2021-10-26 11:04:23 +00:00
|
|
|
/// 时区设置
|
|
|
|
|
2021-10-19 06:28:12 +00:00
|
|
|
import 'package:flutter/material.dart';
|
|
|
|
|
|
|
|
import '../Common.dart';
|
|
|
|
import '../Method.dart';
|
|
|
|
|
|
|
|
const _propertyName = "timeOffsetHour";
|
2021-11-04 05:56:25 +00:00
|
|
|
int _timeOffsetHour = 8;
|
2021-10-19 06:28:12 +00:00
|
|
|
|
|
|
|
Future<void> initTimeZone() async {
|
|
|
|
_timeOffsetHour = int.parse(await method.loadProperty(_propertyName, "8"));
|
|
|
|
}
|
|
|
|
|
2021-11-04 05:56:25 +00:00
|
|
|
int currentTimeOffsetHour() {
|
|
|
|
return _timeOffsetHour;
|
|
|
|
}
|
|
|
|
|
|
|
|
Future<void> _chooseTimeZone(BuildContext context) async {
|
2021-10-19 06:28:12 +00:00
|
|
|
List<String> timeZones = [];
|
|
|
|
for (var i = -12; i <= 12; i++) {
|
|
|
|
var str = i.toString();
|
|
|
|
if (!str.startsWith("-")) {
|
|
|
|
str = "+" + str;
|
|
|
|
}
|
|
|
|
timeZones.add(str);
|
|
|
|
}
|
|
|
|
String? result = await chooseListDialog<String>(context, "时区选择", timeZones);
|
|
|
|
if (result != null) {
|
|
|
|
if (result.startsWith("+")) {
|
|
|
|
result = result.substring(1);
|
|
|
|
}
|
|
|
|
_timeOffsetHour = int.parse(result);
|
2022-03-17 03:31:25 +00:00
|
|
|
await method.saveProperty(_propertyName, result);
|
2021-10-19 06:28:12 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
Widget timeZoneSetting() {
|
|
|
|
return StatefulBuilder(
|
|
|
|
builder: (BuildContext context, void Function(void Function()) setState) {
|
|
|
|
var c = "$_timeOffsetHour";
|
|
|
|
if (!c.startsWith("-")) {
|
|
|
|
c = "+" + c;
|
|
|
|
}
|
|
|
|
return ListTile(
|
2022-03-19 04:12:27 +00:00
|
|
|
title: const Text("时区"),
|
2021-10-19 06:28:12 +00:00
|
|
|
subtitle: Text(c),
|
|
|
|
onTap: () async {
|
2021-11-04 05:56:25 +00:00
|
|
|
await _chooseTimeZone(context);
|
2021-10-19 06:28:12 +00:00
|
|
|
setState(() {});
|
|
|
|
},
|
|
|
|
);
|
|
|
|
},
|
|
|
|
);
|
|
|
|
}
|