2022-05-18 10:39:11 +00:00
|
|
|
part of '../server_details_screen.dart';
|
2022-01-25 17:00:47 +00:00
|
|
|
|
|
|
|
final List<Location> locations = timeZoneDatabase.locations.values.toList()
|
|
|
|
..sort((l1, l2) =>
|
|
|
|
l1.currentTimeZone.offset.compareTo(l2.currentTimeZone.offset));
|
|
|
|
|
|
|
|
class SelectTimezone extends StatefulWidget {
|
|
|
|
SelectTimezone({Key? key}) : super(key: key);
|
|
|
|
|
|
|
|
@override
|
|
|
|
_SelectTimezoneState createState() => _SelectTimezoneState();
|
|
|
|
}
|
|
|
|
|
|
|
|
class _SelectTimezoneState extends State<SelectTimezone> {
|
|
|
|
final ScrollController controller = ScrollController();
|
|
|
|
|
|
|
|
@override
|
|
|
|
void initState() {
|
2022-05-16 20:30:14 +00:00
|
|
|
WidgetsBinding.instance.addPostFrameCallback(_afterLayout);
|
2022-01-25 17:00:47 +00:00
|
|
|
super.initState();
|
|
|
|
}
|
|
|
|
|
|
|
|
void _afterLayout(_) {
|
|
|
|
var t = DateTime.now().timeZoneOffset;
|
|
|
|
var index = locations.indexWhere((element) =>
|
|
|
|
Duration(milliseconds: element.currentTimeZone.offset) == t);
|
2022-02-08 21:01:08 +00:00
|
|
|
print(t);
|
|
|
|
|
2022-01-25 17:00:47 +00:00
|
|
|
if (index >= 0) {
|
2022-02-08 21:01:08 +00:00
|
|
|
controller.animateTo(60.0 * index,
|
2022-01-25 17:00:47 +00:00
|
|
|
duration: Duration(milliseconds: 300), curve: Curves.easeIn);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
@override
|
|
|
|
void dispose() {
|
|
|
|
controller.dispose();
|
|
|
|
super.dispose();
|
|
|
|
}
|
|
|
|
|
|
|
|
@override
|
|
|
|
Widget build(BuildContext context) {
|
|
|
|
return Scaffold(
|
|
|
|
appBar: PreferredSize(
|
|
|
|
child: BrandHeader(
|
|
|
|
title: 'select timezone',
|
|
|
|
hasBackButton: true,
|
|
|
|
),
|
|
|
|
preferredSize: Size.fromHeight(52),
|
|
|
|
),
|
|
|
|
body: ListView(
|
|
|
|
controller: controller,
|
|
|
|
children: locations
|
|
|
|
.asMap()
|
|
|
|
.map((key, value) {
|
|
|
|
var duration =
|
|
|
|
Duration(milliseconds: value.currentTimeZone.offset);
|
|
|
|
var area = value.currentTimeZone.abbreviation
|
|
|
|
.replaceAll(RegExp(r'[\d+()-]'), '');
|
2022-02-07 07:53:13 +00:00
|
|
|
|
|
|
|
String timezoneName = value.name;
|
|
|
|
if (context.locale.toString() == 'ru') {
|
|
|
|
timezoneName = russian[value.name] ??
|
|
|
|
() {
|
|
|
|
var arr = value.name.split('/')..removeAt(0);
|
|
|
|
return arr.join('/');
|
|
|
|
}();
|
|
|
|
}
|
|
|
|
|
2022-01-25 17:00:47 +00:00
|
|
|
return MapEntry(
|
|
|
|
key,
|
|
|
|
Container(
|
2022-02-08 21:01:08 +00:00
|
|
|
height: 60,
|
|
|
|
padding: EdgeInsets.symmetric(horizontal: 20),
|
2022-02-07 07:53:13 +00:00
|
|
|
child: Column(
|
|
|
|
crossAxisAlignment: CrossAxisAlignment.start,
|
2022-02-08 21:01:08 +00:00
|
|
|
mainAxisAlignment: MainAxisAlignment.center,
|
2022-01-25 17:00:47 +00:00
|
|
|
children: [
|
2022-02-07 07:53:13 +00:00
|
|
|
BrandText.body1(
|
|
|
|
timezoneName,
|
|
|
|
style: TextStyle(
|
|
|
|
fontSize: 16,
|
|
|
|
fontWeight: FontWeight.bold,
|
|
|
|
),
|
2022-01-25 17:00:47 +00:00
|
|
|
),
|
2022-02-07 07:53:13 +00:00
|
|
|
BrandText.small(
|
|
|
|
'GMT ${duration.toDayHourMinuteFormat()} ${area.isNotEmpty ? '($area)' : ''}',
|
|
|
|
style: TextStyle(
|
|
|
|
fontSize: 13,
|
|
|
|
)),
|
2022-01-25 17:00:47 +00:00
|
|
|
],
|
|
|
|
),
|
|
|
|
decoration: BoxDecoration(
|
|
|
|
border: Border(
|
|
|
|
bottom: BorderSide(
|
|
|
|
color: BrandColors.dividerColor,
|
|
|
|
)),
|
|
|
|
),
|
|
|
|
),
|
|
|
|
);
|
|
|
|
})
|
|
|
|
.values
|
|
|
|
.toList(),
|
|
|
|
),
|
|
|
|
);
|
|
|
|
}
|
|
|
|
}
|