我正在打包我正在创建的 ios 应用程序,并意识到我需要在设置屏幕的某处显示 Flutter 许可证。
我正在尝试showLicensePage从 Flutter实现该功能,但不确定如何实现。https://api.flutter.dev/flutter/material/showLicensePage.html
如何使用此功能?
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),
),
),
),
),
);
}
}
Run Code Online (Sandbox Code Playgroud)
您将传递null给作为context错误的参数。做showLicensePage(context: context)代替。
该showLicensePage是让你无法把它作为它的返回null功能children的Column。
您不需要专用小部件来显示您的许可证页面。该框架会为您处理它。
在您的设置页面上,您可能有一个小部件,单击该小部件时会显示许可页面。只需调用该小部件showLicensePage(context: context)的onTapor内的函数即可onPressed。
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'),
),
),
);
}
}
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
1993 次 |
| 最近记录: |