[英]How do I set up the showLicensePage function to work with Flutter?
I'm wrapping up an ios app I am creating and realized I need to display the Flutter License somewhere in my settings screen.我正在完成我正在创建的 ios 应用程序,并意识到我需要在设置屏幕的某处显示 Flutter 许可证。
I am trying to implement the showLicensePage
function from Flutter but not sure how to go about this.我正在尝试从 Flutter 实施showLicensePage
function 但不知道如何 go 关于此。 https://api.flutter.dev/flutter/material/showLicensePage.html https://api.flutter.dev/flutter/material/showLicensePage.html
How do I use this function?我该如何使用这个 function?
import 'package:flutter/material.dart';
class FlutterLicense extends StatelessWidget {
void showLicensePage({
@required BuildContext context,
String applicationName,
String applicationVersion,
Widget applicationIcon,
String applicationLegalese,
bool useRootNavigator = false,
}) {
assert(context != null);
assert(useRootNavigator != null);
Navigator.of(context, rootNavigator: useRootNavigator)
.push(MaterialPageRoute<void>(
builder: (BuildContext context) => LicensePage(
applicationName: applicationName,
applicationVersion: applicationVersion,
applicationIcon: applicationIcon,
applicationLegalese: applicationLegalese,
),
));
}
@override
Widget build(BuildContext context) {
return Scaffold(
appBar: AppBar(
backgroundColor: Color(0XFFeb1555),
title: Text(
'LICENSES',
style: TextStyle(),
),
),
body: SafeArea(
child: SingleChildScrollView(
child: Padding(
padding: const EdgeInsets.all(20.0),
child: Column(
children: showLicensePage(context: null),
),
),
),
),
);
}
}
You are passing null
to as the context
parameter which is wrong.您将null
作为错误的context
参数传递给。 Do showLicensePage(context: context)
instead.改为使用showLicensePage(context: context)
。
The showLicensePage
is a function which returns null so you cannot pass it as the children
of the Column
. showLicensePage
是一个 function ,它返回 null 所以你不能将它作为Column
的children
传递。
You do not need a dedicated widget to display your licenses page.您不需要专门的小部件来显示您的许可证页面。 The framework takes care of it for you.该框架会为您处理它。
On your settings page, you may have a widget on which when clicked, shows the license page.在您的设置页面上,您可能有一个小部件,单击该小部件会显示许可证页面。 Just call the function showLicensePage(context: context)
inside the onTap
or onPressed
of that widget.只需在该小部件的onTap
或onPressed
中调用 function showLicensePage showLicensePage(context: context)
即可。
import 'package:flutter/material.dart';
class SettingsPage extends StatelessWidget {
@override
Widget build(BuildContext context) {
return Container(
child: Center(
child: FlatButton(
onPressed: () {
showLicensePage(
context: context,
// applicationIcon: Image.asset(name)
// applicationName: "App Name"
// Other parameters
);
},
child: Text('Show Licenses'),
),
),
);
}
}
This code produces, this when the button is clicked:此代码在单击按钮时产生:
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.