gpt4 book ai didi

flutter - 当您长按 flutter 应用程序的主图标时,有没有办法显示要执行的 2 或 3 个项目的菜单

转载 作者:行者123 更新时间:2023-12-04 02:44:19 25 4
gpt4 key购买 nike

我正在使用 Flutter 开发 iOS 和 Android 应用程序。当用户在应用程序图标上长按以执行 2 种或 3 种最常用的方法时,我需要显示一个小菜单。我不确定从哪里开始。

最佳答案

编辑
请使用包 quick_actions https://pub.dev/packages/quick_actions
请引用https://medium.com/flutter-community/quick-actions-in-flutter-c455caa4f2ba
github 引用文档 https://github.com/SubirZ/quick_action

文档引用演示

enter image description here

官方示例演示

enter image description here

官方示例代码

// Copyright 2017 The Chromium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.

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(
title: 'Flutter Quick Actions Demo',
theme: ThemeData(
primarySwatch: Colors.blue,
),
home: MyHomePage(),
);
}
}

class MyHomePage extends StatefulWidget {
MyHomePage({Key key}) : super(key: key);

@override
_MyHomePageState createState() => _MyHomePageState();
}

class _MyHomePageState extends State<MyHomePage> {
String shortcut = "no action set";

@override
void initState() {
super.initState();

final QuickActions quickActions = QuickActions();
quickActions.initialize((String shortcutType) {
setState(() {
if (shortcutType != null) shortcut = shortcutType;
});
});

quickActions.setShortcutItems(<ShortcutItem>[
// NOTE: This first action icon will only work on iOS.
// In a real world project keep the same file name for both platforms.
const ShortcutItem(
type: 'action_one',
localizedTitle: 'Action one',
icon: 'AppIcon',
),
// NOTE: This second action icon will only work on Android.
// In a real world project keep the same file name for both platforms.
const ShortcutItem(
type: 'action_two',
localizedTitle: 'Action two',
icon: 'ic_launcher'),
]);
}

@override
Widget build(BuildContext context) {
return Scaffold(
appBar: AppBar(
title: Text('$shortcut'),
),
body: const Center(
child: Text('On home screen, long press the app icon to '
'get Action one or Action two options. Tapping on that action should '
'set the toolbar title.'),
),
);
}
}

关于flutter - 当您长按 flutter 应用程序的主图标时,有没有办法显示要执行的 2 或 3 个项目的菜单,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/57863414/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com