From 469fbde6c49b2632355780b08017bcd211430cc6 Mon Sep 17 00:00:00 2001 From: Inex Code Date: Fri, 16 Sep 2022 00:59:37 +0300 Subject: [PATCH] Replace brand_radio_tile.dart with segmented_buttons.dart --- .../brand_button/segmented_buttons.dart | 52 +++++++++++++++++++ .../brand_radio_tile/brand_radio_tile.dart | 37 ------------- lib/ui/pages/server_details/charts/chart.dart | 46 ++++++++-------- .../server_details/server_details_screen.dart | 2 +- .../pages/server_storage/data_migration.dart | 8 ++- 5 files changed, 83 insertions(+), 62 deletions(-) create mode 100644 lib/ui/components/brand_button/segmented_buttons.dart delete mode 100644 lib/ui/components/brand_radio_tile/brand_radio_tile.dart diff --git a/lib/ui/components/brand_button/segmented_buttons.dart b/lib/ui/components/brand_button/segmented_buttons.dart new file mode 100644 index 00000000..444aa906 --- /dev/null +++ b/lib/ui/components/brand_button/segmented_buttons.dart @@ -0,0 +1,52 @@ +import 'package:flutter/material.dart'; + +class SegmentedButtons extends StatelessWidget { + const SegmentedButtons({ + required this.isSelected, + required this.onPressed, + required this.titles, + final super.key, + }); + + final List isSelected; + final Function(int)? onPressed; + final List titles; + + @override + Widget build(final BuildContext context) => LayoutBuilder( + builder: (final context, final constraints) => ToggleButtons( + constraints: BoxConstraints( + minWidth: (constraints.maxWidth - 8) / 3, + minHeight: 40, + ), + borderRadius: BorderRadius.circular(48), + borderColor: Theme.of(context).colorScheme.outline, + selectedBorderColor: Theme.of(context).colorScheme.outline, + fillColor: Theme.of(context).colorScheme.secondaryContainer, + selectedColor: Theme.of(context).colorScheme.onSecondaryContainer, + color: Theme.of(context).colorScheme.onSurface, + isSelected: isSelected, + onPressed: onPressed, + children: titles.asMap().entries.map((final entry) { + final index = entry.key; + final title = entry.value; + return Row( + crossAxisAlignment: CrossAxisAlignment.center, + children: [ + if (isSelected[index]) + Icon( + Icons.check, + size: 18, + color: Theme.of(context).colorScheme.onSecondaryContainer, + ), + if (isSelected[index]) const SizedBox(width: 8), + Text( + title, + style: Theme.of(context).textTheme.labelLarge, + ), + ], + ); + }).toList(), + ), + ); +} diff --git a/lib/ui/components/brand_radio_tile/brand_radio_tile.dart b/lib/ui/components/brand_radio_tile/brand_radio_tile.dart deleted file mode 100644 index 3226c97b..00000000 --- a/lib/ui/components/brand_radio_tile/brand_radio_tile.dart +++ /dev/null @@ -1,37 +0,0 @@ -import 'package:flutter/material.dart'; -import 'package:selfprivacy/ui/components/brand_radio/brand_radio.dart'; -import 'package:selfprivacy/ui/components/brand_text/brand_text.dart'; - -// TODO: Delete this file - -class BrandRadioTile extends StatelessWidget { - const BrandRadioTile({ - required this.isChecked, - required this.text, - required this.onPress, - final super.key, - }); - - final bool isChecked; - - final String text; - final VoidCallback onPress; - - @override - Widget build(final BuildContext context) => GestureDetector( - onTap: onPress, - behavior: HitTestBehavior.translucent, - child: Padding( - padding: const EdgeInsets.all(2), - child: Row( - children: [ - BrandRadio( - isChecked: isChecked, - ), - const SizedBox(width: 9), - BrandText.h5(text) - ], - ), - ), - ); -} diff --git a/lib/ui/pages/server_details/charts/chart.dart b/lib/ui/pages/server_details/charts/chart.dart index 4b23f90f..0ff2dd40 100644 --- a/lib/ui/pages/server_details/charts/chart.dart +++ b/lib/ui/pages/server_details/charts/chart.dart @@ -56,28 +56,30 @@ class _Chart extends StatelessWidget { return Column( children: [ - Padding( - padding: const EdgeInsets.symmetric(horizontal: 20.0, vertical: 10), - child: Row( - mainAxisAlignment: MainAxisAlignment.spaceBetween, - children: [ - BrandRadioTile( - isChecked: period == Period.month, - text: 'providers.server.chart.month'.tr(), - onPress: () => cubit.changePeriod(Period.month), - ), - BrandRadioTile( - isChecked: period == Period.day, - text: 'providers.server.chart.day'.tr(), - onPress: () => cubit.changePeriod(Period.day), - ), - BrandRadioTile( - isChecked: period == Period.hour, - text: 'providers.server.chart.hour'.tr(), - onPress: () => cubit.changePeriod(Period.hour), - ), - ], - ), + SegmentedButtons( + isSelected: [ + period == Period.month, + period == Period.day, + period == Period.hour, + ], + onPressed: (final index) { + switch (index) { + case 0: + cubit.changePeriod(Period.month); + break; + case 1: + cubit.changePeriod(Period.day); + break; + case 2: + cubit.changePeriod(Period.hour); + break; + } + }, + titles: [ + 'providers.server.chart.month'.tr(), + 'providers.server.chart.day'.tr(), + 'providers.server.chart.hour'.tr() + ], ), ...charts, ], diff --git a/lib/ui/pages/server_details/server_details_screen.dart b/lib/ui/pages/server_details/server_details_screen.dart index ac7b13bb..0457c80f 100644 --- a/lib/ui/pages/server_details/server_details_screen.dart +++ b/lib/ui/pages/server_details/server_details_screen.dart @@ -9,12 +9,12 @@ import 'package:selfprivacy/logic/cubit/server_detailed_info/server_detailed_inf import 'package:selfprivacy/logic/cubit/server_installation/server_installation_cubit.dart'; import 'package:selfprivacy/logic/cubit/server_volumes/server_volume_cubit.dart'; import 'package:selfprivacy/logic/models/auto_upgrade_settings.dart'; +import 'package:selfprivacy/ui/components/brand_button/segmented_buttons.dart'; import 'package:selfprivacy/ui/components/brand_cards/filled_card.dart'; import 'package:selfprivacy/ui/components/brand_header/brand_header.dart'; import 'package:selfprivacy/ui/components/brand_hero_screen/brand_hero_screen.dart'; 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_radio_tile/brand_radio_tile.dart'; import 'package:selfprivacy/ui/components/brand_text/brand_text.dart'; import 'package:selfprivacy/ui/components/switch_block/switch_bloc.dart'; import 'package:selfprivacy/ui/pages/server_storage/storage_card.dart'; diff --git a/lib/ui/pages/server_storage/data_migration.dart b/lib/ui/pages/server_storage/data_migration.dart index 6a3756a9..67eca453 100644 --- a/lib/ui/pages/server_storage/data_migration.dart +++ b/lib/ui/pages/server_storage/data_migration.dart @@ -52,7 +52,9 @@ class _DataMigrationPageState extends State { /// subtract the used storage from the old volume and add it to the new volume. /// The old volume is the volume the service is currently on, shown in services list. DiskVolume recalculatedDiskUsages( - final DiskVolume volume, final List services) { + final DiskVolume volume, + final List services, + ) { DiskSize used = volume.sizeUsed; for (final Service service in services) { @@ -105,7 +107,9 @@ class _DataMigrationPageState extends State { children: [ ServerStorageListItem( volume: recalculatedDiskUsages( - volume, widget.services), + volume, + widget.services, + ), dense: true, ), const SizedBox(height: headerVerticalPadding),