当前位置:   article > 正文

flutter应用安卓商店合规化处理_flutter 隐私政策

flutter 隐私政策

安卓商店在应用上架时会要求用户清楚并授权之后才可收集用户和设备信息,如mac地址 imei等

1、安卓开发者会在application中进行此操作,flutter应用可在main文件中添加授权对话框,

flutter的MyApp()可等同看作是应用的application入口。

  1. import 'package:flutter/material.dart';
  2. void main() => runApp(MyApp());
  3. ///等同于应用的application
  4. class MyApp extends StatelessWidget {
  5. @override
  6. Widget build(BuildContext context) {
  7. return MaterialApp(
  8. home: HomePage());
  9. }
  10. }
  11. ///为了解决路由跳转问题
  12. class HomePage extends StatefulWidget {
  13. @override
  14. _HomePageState createState() => _HomePageState();
  15. }
  16. class _HomePageState extends State<HomePage> {
  17. @override
  18. Widget build(BuildContext context) {
  19. return Scaffold(
  20. appBar: AppBar(
  21. title: Text("route"),
  22. ),
  23. floatingActionButton: FloatingActionButton(onPressed: (){
  24. Navigator.push(contexts,MaterialPageRoute(
  25. builder: (context) {
  26. return AgreementPage(1);
  27. },
  28. ));
  29. }),
  30. );
  31. }
  32. }

在MyApp()中添加对话框,用户点击同意即进行部分三方插件的初始化,如极光、融云等。

可在MyApp()的build的body中添加判断,初次安装先处理授权框,同意后再正常初始化内容

  1. @override
  2. Widget build(BuildContext context) {
  3. appContext = context;
  4. return FutureBuilder<CacheManager>(
  5. future: CacheManager.preInit(context),//进行初始化
  6. builder: (BuildContext context, AsyncSnapshot<CacheManager> snapshot) {
  7. //定义route
  8. var _widget = (snapshot.connectionState == ConnectionState.done &&
  9. snapshot.data != null)
  10. ? Router(routerDelegate: _routeDelegate)
  11. : snapshot.connectionState != ConnectionState.done
  12. ? Scaffold(
  13. body: Center(
  14. child: CircularProgressIndicator(color: ColorTool.red),
  15. ),
  16. )
  17. :_showAgreementWindow(appContext);
  18. return _widget;
  19. },
  20. );
  21. }

2、授权框中会有可点击的用户协议和隐私政策,跳转可能会遇到问题

Navigator operation requested with a context that does not include a Navigator.

这是由于MyApp 是一个可变StatefulWidget这种情况下,如上情况提示路由控制器需要一个context但是当前navigator并不包含,通俗的讲要使用路由(Navigator),根控件不能直接是 MaterialApp.解决方法:将 MaterialApp 内容再使用 StatelessWeight 或 StatefulWeight 包裹一层。如图1所示。

可参考flutter报错Navigator operation requested with a context that does not include a Navigator

声明:本文内容由网友自发贡献,不代表【wpsshop博客】立场,版权归原作者所有,本站不承担相应法律责任。如您发现有侵权的内容,请联系我们。转载请注明出处:https://www.wpsshop.cn/w/菜鸟追梦旅行/article/detail/402106
推荐阅读
相关标签
  

闽ICP备14008679号