Skip to content

Commit

Permalink
future的delay调用从then改成参数直接调用
Browse files Browse the repository at this point in the history
  • Loading branch information
cdhigh committed Mar 31, 2022
1 parent d98b1ef commit 4e18f6a
Show file tree
Hide file tree
Showing 7 changed files with 20 additions and 18 deletions.
6 changes: 3 additions & 3 deletions lib/delay_period_on_off.dart
Original file line number Diff line number Diff line change
Expand Up @@ -43,9 +43,9 @@ class _DelayPeriodOnOffPageState extends ConsumerState<DelayPeriodOnOffPage> {
_timerForData = Timer.periodic(const Duration(seconds: 1), (timer) {
final load = ref.watch<ConnectionProvider>(Global.connectionProvider).load;
load.queryDelayOn();
Future.delayed(const Duration(milliseconds: 100)).then((_) => load.queryDelayOff());
Future.delayed(const Duration(milliseconds: 200)).then((_) => load.queryPeriodOn());
Future.delayed(const Duration(milliseconds: 300)).then((_) => load.queryPeriodOff());
Future.delayed(const Duration(milliseconds: 100), load.queryDelayOff);
Future.delayed(const Duration(milliseconds: 200), load.queryPeriodOn);
Future.delayed(const Duration(milliseconds: 300), load.queryPeriodOff);
});
}

Expand Down
2 changes: 1 addition & 1 deletion lib/export_data.dart
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ class _ExportPageState extends ConsumerState<ExportPage> {
void initState() {
super.initState();
_nameCtrller.text = "m328v6_" + DateTime.now().format('yyyymmdd_HHMMSS') + ".xlsx";
Future.delayed(const Duration(milliseconds: 500)).then(requestPermission); //延时确认权限并获取路径
Future.delayed(const Duration(milliseconds: 500), requestPermission); //延时确认权限并获取路径
}

@override
Expand Down
12 changes: 6 additions & 6 deletions lib/i18n/load_stats_page.i18n.dart
Original file line number Diff line number Diff line change
Expand Up @@ -49,27 +49,27 @@ extension Localization on String {
} +
{
"en_us": "Initial Ah",
"zh_cn": "初始安时",
"zh_cn": "初始容量",
} +
{
"en_us": "Ah",
"zh_cn": "本次安时",
"zh_cn": "本次容量",
} +
{
"en_us": "Total Ah",
"zh_cn": "总安时",
"zh_cn": "累积容量",
} +
{
"en_us": "Initial Wh",
"zh_cn": "初始瓦时",
"zh_cn": "初始能量",
} +
{
"en_us": "Wh",
"zh_cn": "本次瓦时",
"zh_cn": "本次能量",
} +
{
"en_us": "Total Wh",
"zh_cn": "总瓦时",
"zh_cn": "累积能量",
} +
{
"en_us": "Mode",
Expand Down
2 changes: 1 addition & 1 deletion lib/load_stats_page.dart
Original file line number Diff line number Diff line change
Expand Up @@ -206,7 +206,7 @@ class _ExportLoadStatsPageState extends ConsumerState<ExportLoadStatsPage> {
void initState() {
super.initState();
_nameCtrller.text = "load_stats_" + DateTime.now().format('yyyymmdd_HHMMSS') + ".xlsx";
Future.delayed(const Duration(milliseconds: 500)).then(requestPermission); //延时确认权限并获取路径
Future.delayed(const Duration(milliseconds: 500), requestPermission); //延时确认权限并获取路径
}

@override
Expand Down
2 changes: 1 addition & 1 deletion lib/load_testers/max_i_tester.dart
Original file line number Diff line number Diff line change
Expand Up @@ -470,7 +470,7 @@ class _MaxITesterPageState extends ConsumerState<MaxITesterPage> {
if (_stepTime == 0) {
_stepTime = 1;
}
Future.delayed(Duration(milliseconds: (_stepTime * 1000) - 500)).then((_) {
Future.delayed(Duration(milliseconds: (_stepTime * 1000) - 500), () {
load.setI(65.535);
Future.delayed(const Duration(milliseconds: 100), () => load.setV(65.535));
});
Expand Down
12 changes: 7 additions & 5 deletions lib/main_page.dart
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,7 @@ class _MainPageState extends ConsumerState<MainPage> with AutomaticKeepAliveClie
Global.bus.addListener(EventBus.connectionChanged, connectionChanged);
Global.bus.addListener(EventBus.curvaFilterDotNumChanged, curvaFilterDotNumChanged);
Global.bus.addListener(EventBus.setLoadOnOff, setLoadOnOffReceived);
Future.delayed(const Duration(seconds: 5)).then(checkNewVersion); //延时确定是否需要检查新版本
Future.delayed(const Duration(seconds: 5), checkNewVersion); //延时确定是否需要检查新版本

_timerForExtraData = PausableTimer(const Duration(seconds: 3), qeuryVersionPeriodic);
_timerForExtraData.pause();
Expand All @@ -84,7 +84,7 @@ class _MainPageState extends ConsumerState<MainPage> with AutomaticKeepAliveClie
void qeuryVersionPeriodic() {
final load = ref.read<ConnectionProvider>(Global.connectionProvider).load;
load.requestExtraData();
Future.delayed(const Duration(milliseconds: 100)).then((_) => load.queryVersion());
Future.delayed(const Duration(milliseconds: 100), load.queryVersion);
//_timerForExtraData..reset()..start();
}

Expand Down Expand Up @@ -170,8 +170,8 @@ class _MainPageState extends ConsumerState<MainPage> with AutomaticKeepAliveClie
connProvider.serial.registerListenFunction(newSrlDataReceived);

//连接后马上查询下位机版本号,请求上报额外数据
Future.delayed(const Duration(milliseconds: 250)).then((_) => connProvider.load.queryVersion());
Future.delayed(const Duration(seconds: 500)).then((_) => connProvider.load.requestExtraData());
Future.delayed(const Duration(milliseconds: 250), connProvider.load.queryVersion);
Future.delayed(const Duration(milliseconds: 500), connProvider.load.requestExtraData);
_timerForExtraData..reset()..start();
} else { //断开连接
final rdProvider = ref.read<RunningDataProvider>(Global.runningDataProvider);
Expand Down Expand Up @@ -911,7 +911,9 @@ class _MainPageState extends ConsumerState<MainPage> with AutomaticKeepAliveClie

///使用和下位机一样的计算功率算法,保证和下位机显示一致(因为下位机仅使用整数运算)
///最后的除以100是因为下位机使用10毫瓦为单位
/// 2022-03-22 配置下位机修改,不需要复杂的计算公式了
double calP(int v, int i) {
return (((v ~/ 10) * i).toInt() ~/ 1000) / 100;
//return (((v ~/ 10) * i).toInt() ~/ 1000) / 100;
return ((v * i) ~/ 10000) / 100;
}
}
2 changes: 1 addition & 1 deletion lib/settings/settings.dart
Original file line number Diff line number Diff line change
Expand Up @@ -356,7 +356,7 @@ class _SettingsPageState extends ConsumerState<SettingsPage> {
String? ret = await showInputDialog(context: context,
title: "Enter a value from 0.000 to 1.000 (V)".i18n,
initialText: Global.curvaFilterThreshold.toStringAsFixed(3),
formatters: [DecimalTextInputFormatter(), CustomMaxValueInputFormatter(1.0)],
//formatters: [DecimalTextInputFormatter(), CustomMaxValueInputFormatter(1.0)],
);

if (ret != null) {
Expand Down

0 comments on commit 4e18f6a

Please sign in to comment.