Flutter埃塞俄比亚日期选择器及转换插件ethiopiandatepickerandconvertor的使用
Flutter埃塞俄比亚日期选择器及转换插件ethiopiandatepickerandconvertor的使用
Hilal 埃塞俄比亚日期选择器 Flutter 插件(适用于阿姆哈拉语和奥罗莫语)
设计者:[Firaol Andarge UI/UX设计师](https://www.linkedin.com/in/fraol-andarge-828643261/)Hilal 埃塞俄比亚日期选择器 Flutter 插件基于 renawoned Abushakir 插件。这是一个强大的工具,专门为希望在他们的应用中添加日期选择功能的 Flutter 开发者设计,并支持阿姆哈拉语和奥罗莫语。此插件不仅允许用户选择单个日期,还可以选择跨多个月的日期范围,使其高度灵活且用户友好。
该插件的一个突出特点是它可以显示一个事件日历,为用户提供重要日期和事件的视觉表示。此功能允许开发者无缝集成事件管理系统或展示与应用目的相关的显著日期。
此外,Hilal 埃塞俄比亚日期选择器 Flutter 插件还包括一个随机日期选择器功能。此功能使用户能够在指定范围内生成随机日期,这对于需要生成随机事件、安排预约或进行数据分析的应用程序特别有用。
功能
- 支持阿姆哈拉语和奥罗莫语,提供本地化体验。
- 允许选择单个日期和跨多个月的日期范围。
- 显示事件日历,以可视化重要日期和事件。
- 包括一个随机日期选择器,可在指定范围内生成随机日期。
- 高度可定制,适应应用的设计和品牌。
- 提供直观且用户友好的界面,便于无缝集成到 Flutter 应用程序中。
- 可以显示公历。
- 可以传递参数。
- 支持事件日历。
安装
安装方法是复制 pub.dev
上的 ethiopiandatepickerandconvertor
包:
dependencies:
...
flutter_bloc:latest version
ethiopiandatetimepickerandconverter:latest version
导入相关库:
import 'package:ethiopiandatepickerandconvertor/controller/alert_calender_bloc/alert_calender_controller_bloc.dart';
然后将你的 MaterialApp
包裹在 MultiBlocProvider
中:
return MultiBlocProvider(
providers: [
BlocProvider(
create: (context) => AlertCalenderControllerBloc(),
),
],
child: MaterialApp(
title: 'Flutter Demo',
home: HomePage(),
),
);
对于 GetX 用户:
return MultiBlocProvider(
providers: [
BlocProvider(
create: (context) => AlertCalenderControllerBloc(),
),
],
child: GetMaterialApp(
title: 'Flutter Demo',
home: HomePage(),
),
);
对于 Provider 用户:
runApp(MultiBlocProvider(providers: [
BlocProvider(
create: (context) => AlertCalenderControllerBloc(),
),
],
child:
MultiProvider(
providers: [
Provider<Something>(create: (_) => Something()),
Provider<SomethingElse>(create: (_) => SomethingElse()),
Provider<AnotherThing>(create: (_) => AnotherThing()),
],
child: MyApp(),
)));
使用/埃塞俄比亚日期选择器
范围和日期选择器是一个警报表单,由于库将从今天的日期开始触发,因此它将通过 bloc 触发。当用户点击确定时,库将返回所选值。让我们看看它们:
import 'package:ethiopiandatepickerandconvertor/controller/alert_calender_bloc/alert_calender_controller_bloc.dart';
import 'package:ethiopiandatepickerandconvertor/widgets/calender_wevent_widget.dart';
import 'package:ethiopiandatepickerandconvertor/widgets/date_picker_alret.dart';
import 'package:flutter_bloc/flutter_bloc.dart';
ElevatedButton(
onPressed: () async {
List? val = await showDialog<List>(
context: context,
builder: (_) {
return BlocProvider.value(
value: BlocProvider.of<AlertCalenderControllerBloc>(context),
child: AlertDatePicker(
displayGregorianCalender: false, // 是否显示公历,true 会显示,false 则不会
userLanguage: "ao", // 用户语言,"ao" 表示加载奥罗莫语,"am" 表示显示阿姆哈拉语日历
startYear: 1990, // 日历开始计数的年份
endYear: 2020, // 日历结束计数的年份
todaysDateBackgroundColor: Colors.greenAccent, // 今天日期的背景色
),
);
},
);
print('Dialog one returned value ---> $val');
// 如果用户基于范围选择了 1-3,点击确定后,日历将返回日期
// Dialog one returned value ---> [2016-1-1, 2016-1-2, 2016-1-3]
// 所以获取这些保存为用户任务即可
},
child: const Text('Show Dialog One'),
),
接下来我们将展示日历上的用户任务。首先注意,这不支持添加任务,例如你可以从服务器添加假期日期,这在伊斯兰节日和其他情况下非常有帮助。日历会根据月亮移动,埃塞俄比亚有13个月。
你可以传递无限数量的数据,例如:
List<Map<String, String>> events = [
{'date': '2015-12-28', 'title': 'Event 1', 'description': 'Description 1'},
{'date': '2015-5-1', 'title': 'Event 2', 'description': 'Description 2'},
{'date': '2015-12-24', 'title': 'Event 3', 'description': 'Description 2'},
{'date': '2015-13-3', 'title': 'Event 4', 'description': 'Description 4'},
];
事件应作为 List<Map>
传递。你可以在容器内调用它,这里是如何调用它的方法:
BlocProvider.value(
value: BlocProvider.of<AlertCalenderControllerBloc>(context),
child: CalenderWithEventWidget(
borderColor: Colors.yellow,
todaysDateColor: Colors.purpleAccent,
displayGregorianCalender: true,
userLanguage: "ao",
startYear: 1990,
endYear: 2020,
eventsList: events,
sendUserEventData: (data) {
print("Received data: $data");
// 如果你需要显示Toast或其他操作
},
),
),
更多关于Flutter埃塞俄比亚日期选择器及转换插件ethiopiandatepickerandconvertor的使用的实战系列教程也可以访问 https://www.itying.com/category-92-b0.html
更多关于Flutter埃塞俄比亚日期选择器及转换插件ethiopiandatepickerandconvertor的使用的实战系列教程也可以访问 https://www.itying.com/category-92-b0.html
当然,以下是如何在Flutter项目中使用ethiopiandatepickerandconvertor
插件的详细代码案例。这个插件可以帮助你实现埃塞俄比亚日期的选择以及与其他日期格式的转换。
首先,确保你已经在pubspec.yaml
文件中添加了ethiopiandatepickerandconvertor
依赖:
dependencies:
flutter:
sdk: flutter
ethiopiandatepickerandconvertor: ^最新版本号 # 请替换为实际的最新版本号
然后,运行flutter pub get
来安装依赖。
接下来,是一个完整的示例代码,展示了如何使用这个插件:
import 'package:flutter/material.dart';
import 'package:ethiopiandatepickerandconvertor/ethiopiandatepickerandconvertor.dart';
void main() {
runApp(MyApp());
}
class MyApp extends StatelessWidget {
@override
Widget build(BuildContext context) {
return MaterialApp(
title: 'Ethiopian Date Picker Example',
theme: ThemeData(
primarySwatch: Colors.blue,
),
home: EthiopianDatePickerExample(),
);
}
}
class EthiopianDatePickerExample extends StatefulWidget {
@override
_EthiopianDatePickerExampleState createState() => _EthiopianDatePickerExampleState();
}
class _EthiopianDatePickerExampleState extends State<EthiopianDatePickerExample> {
EthiopianDate? selectedEthiopianDate;
DateTime? selectedGregorianDate;
void _showEthiopianDatePicker() async {
final EthiopianDate? result = await showEthiopianDatePicker(
context: context,
initialDate: EthiopianDate.fromGregorian(DateTime.now()),
firstDate: EthiopianDate.fromGregorian(DateTime(1900)),
lastDate: EthiopianDate.fromGregorian(DateTime(2100)),
);
if (result != null && mounted) {
setState(() {
selectedEthiopianDate = result;
selectedGregorianDate = result.toGregorian();
});
}
}
@override
Widget build(BuildContext context) {
return Scaffold(
appBar: AppBar(
title: Text('Ethiopian Date Picker Example'),
),
body: Padding(
padding: const EdgeInsets.all(16.0),
child: Column(
mainAxisAlignment: MainAxisAlignment.center,
children: <Widget>[
ElevatedButton(
onPressed: _showEthiopianDatePicker,
child: Text('Select Ethiopian Date'),
),
SizedBox(height: 20),
if (selectedEthiopianDate != null)
Text(
'Selected Ethiopian Date: ${selectedEthiopianDate!.toString()}',
style: TextStyle(fontSize: 18),
),
SizedBox(height: 20),
if (selectedGregorianDate != null)
Text(
'Converted Gregorian Date: ${selectedGregorianDate!.toLocal()}',
style: TextStyle(fontSize: 18),
),
],
),
),
);
}
}
代码解释:
-
依赖添加:在
pubspec.yaml
文件中添加ethiopiandatepickerandconvertor
依赖。 -
导入包:在Dart文件中导入
ethiopiandatepickerandconvertor
包。 -
创建主应用:使用
MaterialApp
创建主应用,并设置首页为EthiopianDatePickerExample
。 -
创建状态组件:
EthiopianDatePickerExample
是一个状态组件,包含一个埃塞俄比亚日期选择器和一个显示选定日期的界面。 -
显示日期选择器:
_showEthiopianDatePicker
方法使用showEthiopianDatePicker
函数显示日期选择器,并将选中的日期保存到状态中。 -
UI展示:在UI中,有一个按钮用于触发日期选择器,以及两个文本组件用于显示选中的埃塞俄比亚日期和转换后的公历日期。
这个示例展示了如何使用ethiopiandatepickerandconvertor
插件选择埃塞俄比亚日期并将其转换为公历日期。你可以根据需要进一步自定义和扩展这个示例。