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

优化请求,第一次请求容易失败,如果第一次请求失败后,会自动请求一次

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: 500);
                    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
22
downloads

Publisher

unverified uploader

Weekly Downloads

优化请求,第一次请求容易失败,如果第一次请求失败后,会自动请求一次

Homepage

License

unknown (license)

Dependencies

flutter, plugin_platform_interface

More

Packages that depend on mx_system_authority