GithubHelp home page GithubHelp logo

badge_manager's Introduction

BadgeManager

BadgeManager is a corner marker setting tool. Currently supports iOS and Android (Samsung, Huawei, Xiaomi, etc.). If you need other functions, you can expand on this basis.

Add dependency

dependencies:
  badge_manager: lastest version  

Simple to use

class _MyAppState extends State<MyApp> with WidgetsBindingObserver{

  late TextEditingController controller;

  String brandStr = "";
  String supported = "";

  @override
  void didChangeAppLifecycleState(AppLifecycleState state) {
    super.didChangeAppLifecycleState(state);
    switch (state) {
      case AppLifecycleState.inactive: // 处于这种状态的应用程序应该假设它们可能在任何时候暂停。
        break;
      case AppLifecycleState.resumed: //从后台切换前台,界面可见
        break;
      case AppLifecycleState.paused: // 界面不可见,后台
        setBadge();
        break;
      case AppLifecycleState.detached: // APP结束时调用
        break;
    }
  }

  @override
  void initState() {
    WidgetsBinding.instance?.addObserver(this);
    controller = TextEditingController();
    super.initState();
  }


  /// methodName isSupported
  /// description 是否支持设置角标 
  /// date 2022/4/15 18:42
  /// author waitwalker
  void isSupported() async {
    final bool value = await BadgeManager.isSupportedBadge();
    setState(() {
      supported = value ? "true" : "false";
    });
  }

  /// methodName getBrand
  /// description 获取手机品牌 
  /// date 2022/4/15 18:42
  /// author waitwalker
  void getBrand() async{
    final String brand = await BadgeManager.getBrand();
    setState(() {
      brandStr = brand;
    });
  }

  /// methodName setBadge
  /// description 设置角标
  /// date 2022/4/15 18:42
  /// author waitwalker
  void setBadge() async{
    await BadgeManager.setBadge(count: int.parse(controller.text), title: "通知", content: "this is content");
  }

  /// methodName setBadge
  /// description 移除角标
  /// date 2022/4/15 18:42
  /// author waitwalker
  void removeBadge() async{
    await BadgeManager.removeBadge();
  }

  @override
  Widget build(BuildContext context) {
    return MaterialApp(
      home: Scaffold(
        backgroundColor: Colors.white,
        appBar: AppBar(
          title: const Text('BadgeManager'),
        ),
        resizeToAvoidBottomInset: false,
        body: InkWell(
          child: SafeArea(
            child: SingleChildScrollView(
              child: SizedBox(
                child: Container(
                  alignment: Alignment.center,
                  color: Colors.white,
                  child: Column(
                    crossAxisAlignment: CrossAxisAlignment.center,
                    children: [
                      const Padding(padding: EdgeInsets.only(top: 30)),
                      Text("是否支持:" + supported),
                      const Padding(padding: EdgeInsets.only(top: 30)),
                      InkWell(
                        child: Container(
                          decoration: BoxDecoration(
                            boxShadow:  [
                              BoxShadow(
                                color: Colors.black.withOpacity(0.2),
                                offset: const Offset(0, 1),
                                blurRadius: 1.5,
                                spreadRadius: 2.5,),
                            ],
                            color: Colors.green,
                            borderRadius: BorderRadius.circular(8.0),
                          ),
                          alignment: Alignment.center,
                          height: 50,
                          width: 300,
                          child: const Text("点击查看是否支持",
                            style: TextStyle(
                              color: Colors.white,
                              fontWeight: FontWeight.bold,
                              fontSize: 18,
                            ),
                          ),
                        ),
                        onTap: (){
                          FocusScope.of(context).requestFocus(FocusNode());
                          isSupported();
                        },
                      ),

                      const Padding(padding: EdgeInsets.only(top: 30)),
                      Text("手机品牌:" + brandStr),
                      const Padding(padding: EdgeInsets.only(top: 30)),
                      InkWell(
                        child: Container(
                          decoration: BoxDecoration(
                            boxShadow:  [
                              BoxShadow(
                                color: Colors.black.withOpacity(0.2),
                                offset: const Offset(0, 1),
                                blurRadius: 1.5,
                                spreadRadius: 2.5,),
                            ],
                            color: Colors.orange,
                            borderRadius: BorderRadius.circular(8.0),
                          ),
                          alignment: Alignment.center,
                          height: 50,
                          width: 300,
                          child: const Text("点击获取手机品牌",
                            style: TextStyle(
                              color: Colors.white,
                              fontWeight: FontWeight.bold,
                              fontSize: 18,
                            ),
                          ),
                        ),
                        onTap: (){
                          FocusScope.of(context).requestFocus(FocusNode());
                          getBrand();
                        },
                      ),

                      const Padding(padding: EdgeInsets.only(top: 30)),
                      SizedBox(
                        height: 50,
                        width: 300,
                        child: CupertinoTextField(
                          controller: controller,
                          keyboardType: TextInputType.number,
                          placeholder: "请输入badge的数字",
                        ),
                      ),

                      const Padding(padding: EdgeInsets.only(top: 30)),
                      InkWell(
                        child: Container(
                          decoration: BoxDecoration(
                            boxShadow:  [
                              BoxShadow(
                                color: Colors.black.withOpacity(0.2),
                                offset: const Offset(0, 1),
                                blurRadius: 1.5,
                                spreadRadius: 2.5,),
                            ],
                            color: Colors.lightBlue,
                            borderRadius: BorderRadius.circular(8.0),
                          ),
                          alignment: Alignment.center,
                          height: 50,
                          width: 300,
                          child: const Text("点击设置角标",
                            style: TextStyle(
                              color: Colors.white,
                              fontWeight: FontWeight.bold,
                              fontSize: 18,
                            ),
                          ),
                        ),
                        onTap: (){
                          if (controller.text.isNotEmpty) {
                            FocusScope.of(context).requestFocus(FocusNode());
                            setBadge();
                          } else {
                            Fluttertoast.showToast(msg: "请先输入badge count");
                          }
                        },
                      ),

                      const Padding(padding: EdgeInsets.only(top: 30)),
                      InkWell(
                        child: Container(
                          decoration: BoxDecoration(
                            boxShadow:  [
                              BoxShadow(
                                color: Colors.black.withOpacity(0.2),
                                offset: const Offset(0, 1),
                                blurRadius: 1.5,
                                spreadRadius: 2.5,),
                            ],
                            color: Colors.lime,
                            borderRadius: BorderRadius.circular(8.0),
                          ),
                          alignment: Alignment.center,
                          height: 50,
                          width: 300,
                          child: const Text("点击移除角标",
                            style: TextStyle(
                              color: Colors.white,
                              fontWeight: FontWeight.bold,
                              fontSize: 18,
                            ),
                          ),
                        ),
                        onTap: (){
                          FocusScope.of(context).requestFocus(FocusNode());
                          removeBadge();
                        },
                      ),
                      const Padding(padding: EdgeInsets.only(top: 330)),
                    ],
                  ),
                ),
              ),
            ),
          ),
          onTap: (){
            FocusScope.of(context).requestFocus(FocusNode());
          },
        ),
      ),
    );
  }

  @override
  void dispose() {
    super.dispose();
    WidgetsBinding.instance?.removeObserver(this);
  }
}

Copyright & License

This project is completely open source and the license is MIT. If you like, welcome star.

Features and bugs

Please file feature requests and bugs at the issue tracker.

Flutter Technology and Other Communication Groups

Scan QR code👇:

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.