zoukankan      html  css  js  c++  java
  • flutter feature---->quick action

    reference: https://www.filledstacks.com/snippet/managing-quick-actions-in-flutter/

    code

    import 'dart:io';
    
    import 'package:flutter/material.dart';
    import 'package:quick_actions/quick_actions.dart';
    
    void main() => runApp(MyApp());
    
    class MyApp extends StatelessWidget {
      @override
      Widget build(BuildContext context) {
        return MaterialApp(home: QuickActionScreen());
      }
    }
    
    class QuickActionScreen extends StatefulWidget {
      @override
      _QuickActionScreenState createState() => _QuickActionScreenState();
    }
    
    class _QuickActionScreenState extends State<QuickActionScreen> {
      final QuickActions quickActions = QuickActions();
    
      @override
      void initState() {
        super.initState();
        _initQuickActions();
      }
    
      @override
      Widget build(BuildContext context) {
        return Scaffold(
          body: Center(
            child: Text("quick action"),
          ),
        );
      }
    
      void _initQuickActions() {
        quickActions.setShortcutItems(<ShortcutItem>[
          ShortcutItem(localizedTitle: 'add', type: 'add', icon: Platform.isAndroid ? 'add' : 'Add'),
          ShortcutItem(localizedTitle: 'help', type: 'help', icon: Platform.isAndroid ? 'help' : 'Love'),
        ]);
        quickActions.initialize((type) {
          if (type == 'add') {
            Navigator.push(context, MaterialPageRoute(builder: (context) => AddScreen()));
          } else {
            Navigator.push(context, MaterialPageRoute(builder: (context) => HelpScreen()));
          }
        });
      }
    }
    
    class AddScreen extends StatelessWidget {
      @override
      Widget build(BuildContext context) {
        return Scaffold(
          body: Center(
            child: Text("Add"),
          ),
        );
      }
    }
    
    class HelpScreen extends StatelessWidget {
      @override
      Widget build(BuildContext context) {
        return Scaffold(
          body: Center(
            child: Text("help"),
          ),
        );
      }
    }
    

    Android asset

    Android recommends a 24x24 image that you can customise. Export that to all the size buckets and add them in the res/drawable-[dpi] folders. Here are the assets that I used. Copy then into the drawable-mdpi, drawable-hdpi, drawable-xhdpi, etc folders to use them.

    iOS

    iOS recommends using the icons under home screen quick actions. I did not create custom icons for iOS for the tutorials.


  • 相关阅读:
    面向对象的三个基本特征 和 五种设计原则
    break和continue的区别
    为什么数组是从0开始的
    在线编程挑战网站列表
    十分钟搞清字符集和字符编码
    MMM和MHA的对比和应用(PPT分享)
    MySQL工具汇总
    关于全局唯一ID生成方法
    关于4K Block Size的Device和 Aligned IO
    加快MySQL逻辑恢复速度的方法和参数总结
  • 原文地址:https://www.cnblogs.com/huhx/p/13406634.html
Copyright © 2011-2022 走看看