Refactor server_settings.dart to use vanilla ListTiles

Inex Code 2022-09-18 17:17:13 +03:00
parent 39358a827f
commit cb660eb2bb
2 changed files with 25 additions and 71 deletions

View File

@ -16,7 +16,6 @@ import 'package:selfprivacy/ui/components/brand_icons/brand_icons.dart';
import 'package:selfprivacy/ui/components/brand_loader/brand_loader.dart'; import 'package:selfprivacy/ui/components/brand_loader/brand_loader.dart';
import 'package:selfprivacy/ui/components/brand_text/brand_text.dart'; import 'package:selfprivacy/ui/components/brand_text/brand_text.dart';
import 'package:selfprivacy/ui/components/list_tiles/list_tile_on_surface_variant.dart'; import 'package:selfprivacy/ui/components/list_tiles/list_tile_on_surface_variant.dart';
import 'package:selfprivacy/ui/components/switch_block/switch_bloc.dart';
import 'package:selfprivacy/ui/pages/server_storage/storage_card.dart'; import 'package:selfprivacy/ui/pages/server_storage/storage_card.dart';
import 'package:selfprivacy/ui/pages/server_details/time_zone/lang.dart'; import 'package:selfprivacy/ui/pages/server_details/time_zone/lang.dart';
import 'package:selfprivacy/utils/extensions/duration.dart'; import 'package:selfprivacy/utils/extensions/duration.dart';
@ -85,6 +84,8 @@ class _ServerDetailsScreenState extends State<ServerDetailsScreen>
StorageCard( StorageCard(
diskStatus: context.watch<ApiServerVolumeCubit>().state.diskStatus, diskStatus: context.watch<ApiServerVolumeCubit>().state.diskStatus,
), ),
const SizedBox(height: 16),
const _ServerSettings(),
const Divider(height: 32), const Divider(height: 32),
Text( Text(
'providers.server.resource_usage'.tr(), 'providers.server.resource_usage'.tr(),
@ -95,9 +96,8 @@ class _ServerDetailsScreenState extends State<ServerDetailsScreen>
create: (final context) => HetznerMetricsCubit()..restart(), create: (final context) => HetznerMetricsCubit()..restart(),
child: _Chart(), child: _Chart(),
), ),
const Divider(height: 32), const SizedBox(height: 8),
_TextDetails(), _TextDetails(),
const _ServerSettings(),
], ],
), ),
); );

View File

@ -26,8 +26,9 @@ class _ServerSettingsState extends State<_ServerSettings> {
return Column( return Column(
children: [ children: [
SwitcherBlock( SwitchListTile(
onChange: (final switched) { value: allowAutoUpgrade ?? false,
onChanged: (final switched) {
context context
.read<ServerDetailsCubit>() .read<ServerDetailsCubit>()
.repository .repository
@ -41,15 +42,15 @@ class _ServerSettingsState extends State<_ServerSettings> {
allowAutoUpgrade = switched; allowAutoUpgrade = switched;
}); });
}, },
isActive: allowAutoUpgrade ?? false, title: Text('providers.server.settings.allow_autoupgrade'.tr()),
child: _TextColumn( subtitle: Text(
title: 'providers.server.settings.allow_autoupgrade'.tr(), 'providers.server.settings.allow_autoupgrade_hint'.tr(),
value: 'providers.server.settings.allow_autoupgrade_hint'.tr(),
), ),
activeColor: Theme.of(context).colorScheme.primary,
), ),
const Divider(height: 0), SwitchListTile(
SwitcherBlock( value: rebootAfterUpgrade ?? false,
onChange: (final switched) { onChanged: (final switched) {
context context
.read<ServerDetailsCubit>() .read<ServerDetailsCubit>()
.repository .repository
@ -59,20 +60,21 @@ class _ServerSettingsState extends State<_ServerSettings> {
allowReboot: switched, allowReboot: switched,
), ),
); );
setState( setState(() {
() { rebootAfterUpgrade = switched;
rebootAfterUpgrade = switched; });
},
);
}, },
isActive: rebootAfterUpgrade ?? false, title: Text('providers.server.settings.reboot_after_upgrade'.tr()),
child: _TextColumn( subtitle: Text(
title: 'providers.server.settings.reboot_after_upgrade'.tr(), 'providers.server.settings.reboot_after_upgrade_hint'.tr(),
value: 'providers.server.settings.reboot_after_upgrade_hint'.tr(),
), ),
activeColor: Theme.of(context).colorScheme.primary,
), ),
const Divider(height: 0), ListTile(
_Button( title: Text('providers.server.settings.server_timezone'.tr()),
subtitle: Text(
serverDetailsState.serverTimezone.toString(),
),
onTap: () { onTap: () {
Navigator.of(context).push( Navigator.of(context).push(
materialRoute( materialRoute(
@ -80,56 +82,8 @@ class _ServerSettingsState extends State<_ServerSettings> {
), ),
); );
}, },
child: _TextColumn(
title: 'providers.server.settings.server_timezone'.tr(),
value: serverDetailsState.serverTimezone.toString(),
),
), ),
], ],
); );
} }
} }
class _Button extends StatelessWidget {
const _Button({
required this.onTap,
required this.child,
});
final Widget child;
final VoidCallback onTap;
@override
Widget build(final BuildContext context) => InkWell(
onTap: onTap,
child: Container(
padding: const EdgeInsets.symmetric(vertical: 16),
child: child,
),
);
}
class _TextColumn extends StatelessWidget {
const _TextColumn({
required this.title,
required this.value,
});
final String title;
final String value;
@override
Widget build(final BuildContext context) => Column(
crossAxisAlignment: CrossAxisAlignment.start,
children: [
BrandText.body1(
title,
style: Theme.of(context).textTheme.bodyLarge,
),
const SizedBox(height: 5),
BrandText.body1(
value,
style: Theme.of(context).textTheme.bodyMedium,
),
],
);
}