简体   繁体   English

如何设置 showLicensePage function 以使用 Flutter?

[英]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),
            ),
          ),
        ),
      ),
    );
  }
}
  1. You are passing null to as the context parameter which is wrong.您将null作为错误的context参数传递给。 Do showLicensePage(context: context) instead.改为使用showLicensePage(context: context)

  2. The showLicensePage is a function which returns null so you cannot pass it as the children of the Column . showLicensePage是一个 function ,它返回 null 所以你不能将它作为Columnchildren传递。

  3. You do not need a dedicated widget to display your licenses page.您不需要专门的小部件来显示您的许可证页面。 The framework takes care of it for you.该框架会为您处理它。

Solution解决方案

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.只需在该小部件的onTaponPressed中调用 function showLicensePage showLicensePage(context: context)即可。

Example例子

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.

相关问题 如何在 Flutter 中向 showLicensePage 添加许可证 - How to add a license to showLicensePage in Flutter 如何在 flutter 应用程序中设置前台通知? - How do i set up foreground notifications in flutter app? 如何设置与 Flutter 同步? - How do you set up sync with Flutter? 如何正确设置我的颤振项目以调用 Cloud Functions? - How do I properly set up my flutter project to make calls to Cloud Functions? 如何使用 Angular 和 Flutter(均为 Dart)为工作区设置 VS Code 调试? - How do I set up VS Code debugging for a workspace using Angular and Flutter (both Dart)? 如何使用 flutter 中的 JSONserializable 在 Cloud Firestore 数据库中设置嵌套字段 - How do I set up a nested field in a Cloud Firestore database using JSONserializable in flutter Flutter 导航 - 如何在索引中设置文件页面? - Flutter Navigation - How do you set up file pages in index? 如何在 Flutter 中为 Android 设置初始路由? - How do I set the initialRoute for Android in Flutter? Flutter如何设置背景图? - How do I Set Background image in Flutter? 当我单击 flutter 到检查器的小部件时,如何将 function 设置为自动 go 到该代码? - How do I set the function to automatically go to that code when I click the widget from flutter to the inspector?
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM