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.
作者:
huhx
出处: www.cnblogs.com/huhx
格言:你尽力了,才有资格说自己的运气不好。
版权:本文版权归作者huhx和博客园共有,欢迎转载。未经作者同意必须保留此段声明,且在文章页面明显位置给出原文链接,否则保留追究法律责任的权利。
出处: www.cnblogs.com/huhx
格言:你尽力了,才有资格说自己的运气不好。
版权:本文版权归作者huhx和博客园共有,欢迎转载。未经作者同意必须保留此段声明,且在文章页面明显位置给出原文链接,否则保留追究法律责任的权利。