mx_system_authority 0.0.5 copy "mx_system_authority: ^0.0.5" to clipboard
mx_system_authority: ^0.0.5 copied to clipboard

1.修改主动检测的返回值,可以直接返回结果 2.增加弹框是单按钮弹框,还是双按钮弹框

example/lib/main.dart

import 'dart:async';

import 'package:flutter/material.dart';
import 'package:flutter/services.dart';
import 'package:mx_system_authority/check_time_model.dart';
import 'package:mx_system_authority/mx_system_authority.dart';

void main() {
  runApp(const MyApp());
}

class MyApp extends StatefulWidget {
  const MyApp({super.key});

  @override
  State<MyApp> createState() => _MyAppState();
}

class _MyAppState extends State<MyApp> {
  String _platformVersion = 'Unknown';
  final _mxSystemAuthorityPlugin = MxSystemAuthority.instance;
  bool checkResult = false;
  bool isSetting = false;
  String observeMsg = "";
  

  @override
  void initState() {
    super.initState();
    initPlatformState();
    addObserver();
  }

  addObserver()async{
    _mxSystemAuthorityPlugin.onMessageRecive(
      callBack: (CheckTimeModel model) {
        //print("isMoreThan:${model.isMoreThan},time:${model.time}");
        setState(() {
           // observeMsg = model.isMoreThan ? "发生改变" : "没有发生改变";
           observeMsg = "status:${model.isMoreThan}, time:${model.time}";
        });
        if (model.isMoreThan) {
          _mxSystemAuthorityPlugin.showAlertView(
              title: "请调整日期和时间",
              message: "前往设置 > 通用 > 日期与时间,启用“自动设置”以确保时间准确",
              cancelTitle: "取消",
              okTitle: "确定",
              isSingleButton: false
              );
        }
      },
    );

   _mxSystemAuthorityPlugin.addObserverListenterChange(interval: 300);
   
  }

  Future<void> initPlatformState() async {
    String platformVersion;

    try {
      platformVersion = await _mxSystemAuthorityPlugin.getPlatformVersion() ??
          'Unknown platform version';
    } on PlatformException {
      platformVersion = 'Failed to get platform version.';
    }

    if (!mounted) return;

    setState(() {
      _platformVersion = platformVersion;
    });
  }

  @override
  Widget build(BuildContext context) {
    return MaterialApp(
      home: Scaffold(
        appBar: AppBar(
          title: const Text('Plugin example app'),
        ),
        body: Container(
          alignment: const Alignment(0, 0),
          child: Column(
            mainAxisAlignment: MainAxisAlignment.center,
            crossAxisAlignment: CrossAxisAlignment.center,
            children: [
              ElevatedButton(
                  onPressed: ()  {
                   
                     _mxSystemAuthorityPlugin.checkTime(interval: 500);
          
                  },
                  child: const Text("检测时间")),
              const SizedBox(
                height: 20,
              ),
              Text("结果:$checkResult"),
              const SizedBox(
                height: 20,
              ),
              ElevatedButton(
                  onPressed: () async {
                    bool result = await _mxSystemAuthorityPlugin.showAlertView(
                      title: "请调整日期和时间",
                      message: "前往设置 > 通用 > 日期与时间,启用“自动设置”以确保时间准确",
                      cancelTitle: "取消",
                      okTitle: "去设置",
                      isSingleButton: false,
                    );
                    setState(() {
                      isSetting = result;
                    });
                  },
                  child: const Text("去设置")),
              const SizedBox(
                height: 20,
              ),
              Text("是否去设置了$isSetting"),
              const SizedBox(
                height: 20,
              ),
              ElevatedButton(
                  onPressed: () {
                    _mxSystemAuthorityPlugin.gotoSetting();
                  },
                  child: const Text("调用去设置的url")),
                   const SizedBox(
                height: 10,
              ),
               Text(observeMsg),
            ],
          ),
        ),
      ),
    );
  }
}
0
likes
0
points
22
downloads

Publisher

unverified uploader

Weekly Downloads

1.修改主动检测的返回值,可以直接返回结果 2.增加弹框是单按钮弹框,还是双按钮弹框

Homepage

License

unknown (license)

Dependencies

flutter, plugin_platform_interface

More

Packages that depend on mx_system_authority