/// 时区设置 import 'package:flutter/material.dart'; import '../Common.dart'; import '../Method.dart'; int _timeOffsetHour = 8; int currentTimeOffsetHour() { return _timeOffsetHour; } const _propertyName = "timeOffsetHour"; Future initTimeZone() async { _timeOffsetHour = int.parse(await method.loadProperty(_propertyName, "8")); } Future chooseTimeZone(BuildContext context) async { List timeZones = []; for (var i = -12; i <= 12; i++) { var str = i.toString(); if (!str.startsWith("-")) { str = "+" + str; } timeZones.add(str); } String? result = await chooseListDialog(context, "时区选择", timeZones); if (result != null) { if (result.startsWith("+")) { result = result.substring(1); } _timeOffsetHour = int.parse(result); await method.saveProperty(_propertyName, "$result"); } } Widget timeZoneSetting() { return StatefulBuilder( builder: (BuildContext context, void Function(void Function()) setState) { var c = "$_timeOffsetHour"; if (!c.startsWith("-")) { c = "+" + c; } return ListTile( title: Text("时区"), subtitle: Text(c), onTap: () async { await chooseTimeZone(context); setState(() {}); }, ); }, ); }