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

1.该插件主要是用于检测系统时间是否正确,通过和ntp时间进行对比来校验时间是否正确 2.主要功能有检测时间,跳转设置弹框 3.直接跳转导致设置界面,注意ios中只能跳转到通用,因为权限问题

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();
  bool checkResult = false;
  bool isSetting = false;

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

  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: () async {
                    CheckTimeModel model =
                        await MxSystemAuthority().checkTime(interval: 1);
                    setState(() {
                      checkResult = model.isMoreThan;
                    });
                  },
                  child: const Text("检测时间")),
              const SizedBox(
                height: 20,
              ),
              Text("结果:$checkResult"),
              const SizedBox(
                height: 20,
              ),
              ElevatedButton(
                  onPressed: () async {
                    bool result = await MxSystemAuthority().showAlertView(
                      title: "请调整日期和时间",
                      message: "前往设置 > 通用 > 日期与时间,启用“自动设置”以确保时间准确",
                      cancelTitle: "取消",
                      okTitle: "去设置",
                    );
                    setState(() {
                      isSetting = result;
                    });
                    // print("是否去设置了:$result");
                  },
                  child: const Text("去设置")),
              const SizedBox(
                height: 20,
              ),
              Text("是否去设置了$isSetting"),
              const SizedBox(
                height: 20,
              ),
              ElevatedButton(
                  onPressed: () {
                    MxSystemAuthority().gotoSetting();
                  },
                  child: const Text("调用去设置的url"))
            ],
          ),
        ),
      ),
    );
  }
}
0
likes
0
points
4
downloads

Publisher

unverified uploader

Weekly Downloads

1.该插件主要是用于检测系统时间是否正确,通过和ntp时间进行对比来校验时间是否正确 2.主要功能有检测时间,跳转设置弹框 3.直接跳转导致设置界面,注意ios中只能跳转到通用,因为权限问题

Homepage

License

unknown (license)

Dependencies

flutter, plugin_platform_interface

More

Packages that depend on mx_system_authority

Packages that implement mx_system_authority