全屏浏览
缩小浏览
回到页首

flutter---->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.


posted @   huhx  阅读(759)  评论(0编辑  收藏  举报
编辑推荐:
· [.NET]调用本地 Deepseek 模型
· 一个费力不讨好的项目,让我损失了近一半的绩效!
· .NET Core 托管堆内存泄露/CPU异常的常见思路
· PostgreSQL 和 SQL Server 在统计信息维护中的关键差异
· C++代码改造为UTF-8编码问题的总结
阅读排行:
· 一个费力不讨好的项目,让我损失了近一半的绩效!
· 实操Deepseek接入个人知识库
· CSnakes vs Python.NET:高效嵌入与灵活互通的跨语言方案对比
· 【.NET】调用本地 Deepseek 模型
· Plotly.NET 一个为 .NET 打造的强大开源交互式图表库
点击右上角即可分享
微信分享提示