Flutter底部操作表插件phoenix_actionsheet的使用
Flutter底部操作表插件phoenix_actionsheet的使用
特性
phoenix
将作为企业级基础组件之一,提供 ActionSheet
组件的支持。
开始使用
首先,确保在您的项目中添加了 phoenix_actionsheet
依赖。您可以在 pubspec.yaml
文件中添加以下内容:
dependencies:
phoenix_actionsheet: ^版本号
然后运行 flutter pub get
来获取新的依赖。
使用示例
下面是一个完整的示例代码,演示如何在 Flutter 应用中使用 phoenix_actionsheet
插件。
import 'package:flutter/material.dart';
import 'package:phoenix_actionsheet/phoenix_actionsheet.dart';
import 'package:phoenix_base/phoenix.dart';
void main() {
runApp(const MyApp());
}
class MyApp extends StatelessWidget {
const MyApp({super.key});
[@override](/user/override)
Widget build(BuildContext context) {
return MaterialApp(
title: 'Flutter Demo',
theme: ThemeData(
colorScheme: ColorScheme.fromSeed(seedColor: Colors.deepPurple),
useMaterial3: true,
),
home: ActionSheetEntryPage('ActionSheet'),
);
}
}
class MyHomePage extends StatefulWidget {
const MyHomePage({super.key, required this.title});
final String title;
[@override](/user/override)
State<MyHomePage> createState() => _MyHomePageState();
}
class _MyHomePageState extends State<MyHomePage> {
int _counter = 0;
void _incrementCounter() {
setState(() {
_counter++;
});
/// 1
ShareActionSheet actionSheet = ShareActionSheet(
firstShareChannels: [ShareItem(BaseShareItemConstants.shareQQ)],
mainTitle: '分享',
mainTitleAlignment: Alignment.center,
cancelTitle: '取消',
clickCallBack: (section, index, shareItem) {},
);
// actionSheet.show(context);
/// 2
CommonActionSheet commonActionSheet = CommonActionSheet(
actions: [
CommonActionSheetItem('001', desc: '001_normal', actionStyle: CommonActionSheetItemStyle.normal),
CommonActionSheetItem('002', desc: '002_link', actionStyle: CommonActionSheetItemStyle.link),
CommonActionSheetItem('003', desc: '003_alert', actionStyle: CommonActionSheetItemStyle.alert)
],
);
// showBottomSheet(
// context: context,
// builder: (context) => commonActionSheet,
// );
/// 3
SelectedListActionSheet<CommonActionSheetItem> listActionSheet = SelectedListActionSheet<CommonActionSheetItem>(
context: context,
items: [
CommonActionSheetItem('001', desc: '001_normal', actionStyle: CommonActionSheetItemStyle.normal),
CommonActionSheetItem('002', desc: '002_link', actionStyle: CommonActionSheetItemStyle.link),
CommonActionSheetItem('003', desc: '003_alert', actionStyle: CommonActionSheetItemStyle.alert)
],
itemTitleBuilder: (index, entity) {
return Text(entity.title);
},
onClearConfirmed: () {},
onClear: () {},
);
listActionSheet.show();
}
[@override](/user/override)
Widget build(BuildContext context) {
return Scaffold(
appBar: AppBar(
backgroundColor: Theme.of(context).colorScheme.inversePrimary,
title: Text(widget.title),
),
body: Center(
child: Column(
mainAxisAlignment: MainAxisAlignment.center,
children: [
const Text(
'You have pushed the button this many times:',
),
Text(
'$_counter',
style: Theme.of(context).textTheme.headlineMedium,
),
],
),
),
floatingActionButton: FloatingActionButton(
onPressed: _incrementCounter,
tooltip: 'Increment',
child: const Icon(Icons.add),
),
);
}
}
更多关于Flutter底部操作表插件phoenix_actionsheet的使用的实战教程也可以访问 https://www.itying.com/category-92-b0.html
更多关于Flutter底部操作表插件phoenix_actionsheet的使用的实战系列教程也可以访问 https://www.itying.com/category-92-b0.html
phoenix_actionsheet
是一个用于在 Flutter 应用中显示底部操作表的插件。它提供了丰富的自定义选项,可以帮助你快速实现各种底部操作表的需求。以下是如何使用 phoenix_actionsheet
插件的步骤:
1. 添加依赖
首先,你需要在 pubspec.yaml
文件中添加 phoenix_actionsheet
插件的依赖:
dependencies:
flutter:
sdk: flutter
phoenix_actionsheet: ^1.0.0 # 请使用最新版本
然后运行 flutter pub get
来安装依赖。
2. 导入包
在你的 Dart 文件中导入 phoenix_actionsheet
包:
import 'package:phoenix_actionsheet/phoenix_actionsheet.dart';
3. 使用 PhoenixActionSheet
显示底部操作表
你可以通过调用 PhoenixActionSheet.show
方法来显示底部操作表。以下是一个简单的示例:
import 'package:flutter/material.dart';
import 'package:phoenix_actionsheet/phoenix_actionsheet.dart';
void main() {
runApp(MyApp());
}
class MyApp extends StatelessWidget {
@override
Widget build(BuildContext context) {
return MaterialApp(
home: Scaffold(
appBar: AppBar(
title: Text('PhoenixActionSheet Example'),
),
body: Center(
child: ElevatedButton(
onPressed: () {
_showActionSheet(context);
},
child: Text('Show ActionSheet'),
),
),
),
);
}
void _showActionSheet(BuildContext context) {
PhoenixActionSheet.show(
context,
actions: [
PhoenixActionSheetItem(
title: '选项1',
onPressed: () {
print('选项1被点击');
Navigator.pop(context);
},
),
PhoenixActionSheetItem(
title: '选项2',
onPressed: () {
print('选项2被点击');
Navigator.pop(context);
},
),
],
cancel: PhoenixActionSheetItem(
title: '取消',
onPressed: () {
print('取消被点击');
Navigator.pop(context);
},
),
);
}
}
4. 自定义选项
PhoenixActionSheet
提供了多种自定义选项,你可以根据需要调整样式和行为。以下是一些常用的自定义选项:
title
: 设置操作表的标题。message
: 设置操作表的描述信息。actions
: 设置操作表中的操作项。cancel
: 设置取消按钮。actionSheetTheme
: 自定义操作表的主题样式。
PhoenixActionSheet.show(
context,
title: '标题',
message: '描述信息',
actions: [
PhoenixActionSheetItem(
title: '选项1',
onPressed: () {
print('选项1被点击');
Navigator.pop(context);
},
),
PhoenixActionSheetItem(
title: '选项2',
onPressed: () {
print('选项2被点击');
Navigator.pop(context);
},
),
],
cancel: PhoenixActionSheetItem(
title: '取消',
onPressed: () {
print('取消被点击');
Navigator.pop(context);
},
),
actionSheetTheme: ActionSheetTheme(
backgroundColor: Colors.white,
titleStyle: TextStyle(color: Colors.black, fontSize: 18),
messageStyle: TextStyle(color: Colors.grey, fontSize: 14),
itemStyle: TextStyle(color: Colors.blue, fontSize: 16),
cancelStyle: TextStyle(color: Colors.red, fontSize: 16),
),
);