Flutter自定义对话框插件awesome_custom_dialog的使用
✨ awesome_custom_dialog #
🎖 安装 #
1、安装
dependencies:
awesome_custom_dialog: ^0.0.1
💡 使用示例 #
以下是一个完整的示例,展示如何使用 awesome_custom_dialog
插件创建一个自定义对话框。
首先,确保在 pubspec.yaml
文件中添加了依赖项:
dependencies:
awesome_custom_dialog: ^0.0.1
然后运行 flutter pub get
来获取依赖。
接下来,我们通过以下代码来演示如何使用 awesome_custom_dialog
创建一个自定义对话框。
示例代码
library awesome_custom_dialog_example;
import 'package:awesome_custom_dialog/awesome_custom_dialog.dart';
import 'package:flutter/material.dart';
void main() => runApp(const MyApp());
class MyApp extends StatelessWidget {
const MyApp({super.key});
[@override](/user/override)
Widget build(BuildContext context) {
return const MaterialApp(
home: AppHome(),
);
}
}
class AppHome extends StatelessWidget {
const AppHome({super.key});
[@override](/user/override)
Widget build(BuildContext context) {
// 初始化对话框上下文
ACDDialog.init(context);
return Scaffold(
appBar: AppBar(
title: const Text('Awesome Custom Dialog 示例'),
),
body: Center(
child: Column(
mainAxisAlignment: MainAxisAlignment.center,
children: [
ElevatedButton(
onPressed: () {
// 显示成功对话框
acdNoticeDialog(
title: '成功',
message: '操作已完成!',
type: ACDType.success,
);
},
child: const Text('显示成功对话框'),
),
const SizedBox(height: 20),
ElevatedButton(
onPressed: () {
// 显示警告对话框
acdNoticeDialog(
title: '警告',
message: '请检查输入!',
type: ACDType.warning,
);
},
child: const Text('显示警告对话框'),
),
const SizedBox(height: 20),
ElevatedButton(
onPressed: () {
// 显示错误对话框
acdNoticeDialog(
title: '错误',
message: '发生了一些问题!',
type: ACDType.error,
);
},
child: const Text('显示错误对话框'),
),
],
),
),
);
}
}
更多关于Flutter自定义对话框插件awesome_custom_dialog的使用的实战系列教程也可以访问 https://www.itying.com/category-92-b0.html
1 回复