Flutter数学计算插件bahere_hasab的使用
Flutter数学计算插件bahere_hasab的使用
Abushakir (ባሕረ ሃሳብ)
Bahire Hasab源自古埃塞俄比亚语言盖兹语(阿拉伯语:Abu Shakir),是一种由亚历山大第十二位教宗圣德米特里所制定的时间跟踪方法。
什么是Bahire Hasab?
“Bahire Hasab /‘bəhrɛ həsəb’/ " 简单来说就是“带有描述性和时间编号的年龄”。在一些书籍中,它也可以被找到为"Hasabe Bahir”,以海的比喻来赋予时间一个类比。
该插件允许开发者在其应用程序中实现埃塞俄比亚日历和日期系统。
此插件是基于UNIX EPOCH实现的,这意味着它是从1970年1月1日UTC开始以毫秒为单位测量的,不考虑闰秒。
文档
示例
先决条件
在开始之前,请确保满足以下要求:
dependencies:
equatable: ^2.0.3
开始使用
在你的flutter项目的pubspec.yaml
文件中添加以下依赖项:
dependencies:
...
bahere_hasab: ^0.0.2
在你的库中添加以下导入:
import 'package:bahere_hasab/bahere_hasab.dart';
示例代码
/**
* 埃塞俄比亚日期时间模块 [EtDatetime]
*/
EtDatetime now = new EtDatetime.now(); // => 2012-07-28 17:18:31.466
print(now.date); // => {year: 2012, month: 7, day: 28}
print(now.time); // => {h: 17, m: 18, s: 31}
EtDatetime covidFirstConfirmed = new EtDatetime(year: 2012, month: 7, day: 4);
EtDatetime covidFirstConfirmedEpoch =
new EtDatetime.fromMillisecondsSinceEpoch(covidFirstConfirmed.moment);
EtDatetime covidFirstDeath = EtDatetime.parse("2012-07-26 23:00:00");
/// 比较两个EtDatetime实例
Duration daysWithOutDeath = covidFirstConfirmed.difference(covidFirstDeath);
assert(daysWithOutDeath.inDays == -22, true); // 22天
assert(covidFirstDeath.isAfter(covidFirstConfirmed), true);
assert(covidFirstDeath.isBefore(now), true);
assert(covidFirstConfirmed.isAtSameMomentAs(covidFirstConfirmedEpoch), true);
/**
* 埃塞俄比亚日历模块 [ETC]
*/
ETC ethiopianCalendar = new ETC(year: 2012, month: 7, day: 4);
///
print(ethiopianCalendar.monthDays(geezDay: true, weekDayName:true)); // 可迭代对象,表示给定月份
print(ethiopianCalendar.monthDays().toList()[0]); // => [2012, 7, ፩, አርብ]
// [year, month, dateNumber, dateNameIndex], 星期一作为第一个工作日
print(ethiopianCalendar.nextMonth); // => ETC实例,表示下个月,同一年
print(ethiopianCalendar.prevYear); // => ETC实例,表示上一年,同一个月
/**
* Bahire Hasab模块 [BahireHasab]
*/
BahireHasab bh = BahireHasab(year: 2011);
// BahireHasab bh = BahireHasab(); // 获取当前年份
print(bh.getEvangelist(returnName: true)); // => ሉቃስ
print(bh.getSingleBealOrTsom("ትንሳኤ")); // {month: ሚያዝያ, date: 20}
bh.allAtswamat; // => 所有禁食和可移动节日的列表
/**
* 将阿拉伯或英文数字(1,2,3...)转换为埃塞俄比亚或GE'EZ数字(፩, ፪, ፫...)
*/
var input = [1, 10, 15, 20, 25, 78, 105, 333, 450, 600, 1000, 1001, 1010, 1056, 1200, 2013, 9999, 10000];
for (var arabic in input) {
print(ConvertToEthiopic(arabic)); // [፩, ፲, ፲፭, ፳, ፳፭, ፸፰, ፻፭, ፫፻፴፫, ፬፻፶, ፮፻, ፲፻, ፲፻፩, ፲፻፲, ፲፻፶፮, ፲፪፻, ፳፻፲፫, ፺፱፻፺፱, ፻፻]
}
/*
* 将任何日历(在此示例中为格里高利日历)转换为埃塞俄比亚日历。
*/
DateTime gregorian1 = new DateTime.now();
EtDatetime ethiopian1 = new EtDatetime.fromMillisecondsSinceEpoch(gregorian1.millisecondsSinceEpoch);
print("Gregorian := ${gregorian1.toString()} is equivalent to Ethiopian ${ethiopian1.toString()}");
// Gregorian := 2020-09-22 23:36:37.042962 is equivalent to Ethiopian 2013-01-12 20:36:37.042
/*
* 将埃塞俄比亚日历转换为任何日历(在此示例中为格里高利日历)。
*/
EtDatetime ethiopian = new EtDatetime.now();
DateTime gregorian = new DateTime.fromMillisecondsSinceEpoch(ethiopian.moment);
print("Ethiopian ${ethiopian.toString()} is equivalent to Gregorian := ${gregorian.toString()}");
// Ethiopian 2013-01-12 20:36:37.044 is equivalent to Gregorian := 2020-09-22 23:36:37.044
print("Ethiopian EPOCH := ${ethiopian.moment}"); // Ethiopian EPOCH := 1600806997044
print("Gregorian EPOCH := ${gregorian.millisecondsSinceEpoch}"); // Gregorian EPOCH := 1600806997044
更多关于Flutter数学计算插件bahere_hasab的使用的实战教程也可以访问 https://www.itying.com/category-92-b0.html
更多关于Flutter数学计算插件bahere_hasab的使用的实战系列教程也可以访问 https://www.itying.com/category-92-b0.html
当然,以下是如何在Flutter项目中集成和使用bahere_hasab
数学计算插件的示例代码。bahere_hasab
是一个用于执行数学运算的Flutter插件,假设它提供了基本的四则运算功能。请注意,由于bahere_hasab
并非一个真实存在的Flutter插件(在我最后的知识更新时),以下代码是一个假设性的示例,旨在展示如何集成和使用一个类似的数学计算插件。
1. 添加依赖
首先,在你的pubspec.yaml
文件中添加bahere_hasab
依赖(注意:这只是一个假设的包名):
dependencies:
flutter:
sdk: flutter
bahere_hasab: ^1.0.0 # 假设的版本号
然后运行flutter pub get
来安装依赖。
2. 导入插件
在你的Dart文件中导入bahere_hasab
插件:
import 'package:bahere_hasab/bahere_hasab.dart';
3. 使用插件进行数学计算
下面是一个简单的示例,展示如何使用该插件进行加法、减法、乘法和除法运算:
import 'package:flutter/material.dart';
import 'package:bahere_hasab/bahere_hasab.dart'; // 导入插件
void main() {
runApp(MyApp());
}
class MyApp extends StatelessWidget {
@override
Widget build(BuildContext context) {
return MaterialApp(
title: 'Flutter Math Demo',
theme: ThemeData(
primarySwatch: Colors.blue,
),
home: MathCalculatorPage(),
);
}
}
class MathCalculatorPage extends StatefulWidget {
@override
_MathCalculatorPageState createState() => _MathCalculatorPageState();
}
class _MathCalculatorPageState extends State<MathCalculatorPage> {
String result = '';
void performAddition() {
double a = 5.0;
double b = 3.0;
double sum = BahereHasab.add(a, b);
setState(() {
result = '$a + $b = $sum';
});
}
void performSubtraction() {
double a = 5.0;
double b = 3.0;
double difference = BahereHasab.subtract(a, b);
setState(() {
result = '$a - $b = $difference';
});
}
void performMultiplication() {
double a = 5.0;
double b = 3.0;
double product = BahereHasab.multiply(a, b);
setState(() {
result = '$a * $b = $product';
});
}
void performDivision() {
double a = 6.0;
double b = 3.0;
double quotient = BahereHasab.divide(a, b);
setState(() {
result = '$a / $b = $quotient';
});
}
@override
Widget build(BuildContext context) {
return Scaffold(
appBar: AppBar(
title: Text('Math Calculator'),
),
body: Center(
child: Column(
mainAxisAlignment: MainAxisAlignment.center,
children: <Widget>[
Text(
result,
style: TextStyle(fontSize: 24),
),
SizedBox(height: 20),
ElevatedButton(
onPressed: performAddition,
child: Text('Add'),
),
SizedBox(height: 10),
ElevatedButton(
onPressed: performSubtraction,
child: Text('Subtract'),
),
SizedBox(height: 10),
ElevatedButton(
onPressed: performMultiplication,
child: Text('Multiply'),
),
SizedBox(height: 10),
ElevatedButton(
onPressed: performDivision,
child: Text('Divide'),
),
],
),
),
);
}
}
4. 假设的BahereHasab类
由于bahere_hasab
是一个假设的插件,这里提供一个假设的BahereHasab
类实现,以便上述代码能够编译和运行:
class BahereHasab {
static double add(double a, double b) {
return a + b;
}
static double subtract(double a, double b) {
return a - b;
}
static double multiply(double a, double b) {
return a * b;
}
static double divide(double a, double b) {
if (b == 0) throw ArgumentError('Division by zero');
return a / b;
}
}
在实际应用中,你会直接使用插件提供的API,而不是自己实现这些功能。如果bahere_hasab
插件真实存在,它的API文档会告诉你如何正确调用这些方法。
希望这个示例对你有所帮助!如果你有一个具体的插件并且需要更详细的指导,请提供更多信息。