diff --git a/packages/ubuntu_desktop_installer/lib/pages/confirm/confirm_page.dart b/packages/ubuntu_desktop_installer/lib/pages/confirm/confirm_page.dart index 32f73aea03..e54fcc2d6a 100644 --- a/packages/ubuntu_desktop_installer/lib/pages/confirm/confirm_page.dart +++ b/packages/ubuntu_desktop_installer/lib/pages/confirm/confirm_page.dart @@ -1,4 +1,3 @@ -import 'package:filesize/filesize.dart'; import 'package:flutter/material.dart'; import 'package:flutter_html/flutter_html.dart'; import 'package:flutter_riverpod/flutter_riverpod.dart'; @@ -138,12 +137,13 @@ class _PartitionLabel extends StatelessWidget { final Partition partition; final Partition? original; - String formatPartition(AppLocalizations lang) { + String formatPartition(BuildContext context) { + final lang = AppLocalizations.of(context); if (partition.resize == true) { return lang.writeChangesPartitionResized( partition.sysname, - filesize(original?.size ?? 0), - filesize(partition.size ?? 0), + context.formatByteSize(original?.size ?? 0), + context.formatByteSize(partition.size ?? 0), ); } else if (partition.wipe != null && partition.mount?.isNotEmpty == true) { return lang.writeChangesPartitionFormattedMounted( @@ -169,9 +169,8 @@ class _PartitionLabel extends StatelessWidget { @override Widget build(BuildContext context) { - final lang = AppLocalizations.of(context); return Html( - data: formatPartition(lang), + data: formatPartition(context), style: {'body': Style(margin: Margins.zero)}, ); } diff --git a/packages/ubuntu_desktop_installer/lib/pages/source/not_enough_disk_space/not_enough_disk_space_page.dart b/packages/ubuntu_desktop_installer/lib/pages/source/not_enough_disk_space/not_enough_disk_space_page.dart index 70e7c4626b..782e4f7d03 100644 --- a/packages/ubuntu_desktop_installer/lib/pages/source/not_enough_disk_space/not_enough_disk_space_page.dart +++ b/packages/ubuntu_desktop_installer/lib/pages/source/not_enough_disk_space/not_enough_disk_space_page.dart @@ -1,6 +1,5 @@ import 'dart:math'; -import 'package:filesize/filesize.dart'; import 'package:flutter/material.dart'; import 'package:flutter_riverpod/flutter_riverpod.dart'; import 'package:ubuntu_desktop_installer/installer.dart'; @@ -53,7 +52,7 @@ class NotEnoughDiskSpacePage extends ConsumerWidget { ), const SizedBox(width: 8), Text( - filesize(model.installMinimumSize), + context.formatByteSize(model.installMinimumSize), style: Theme.of(context) .textTheme .bodyLarge! @@ -70,7 +69,7 @@ class NotEnoughDiskSpacePage extends ConsumerWidget { ), const SizedBox(width: 8), Text( - filesize(model.largestDiskSize), + context.formatByteSize(model.largestDiskSize), style: Theme.of(context) .textTheme .bodyLarge! diff --git a/packages/ubuntu_desktop_installer/lib/pages/storage/guided_reformat/guided_reformat_page.dart b/packages/ubuntu_desktop_installer/lib/pages/storage/guided_reformat/guided_reformat_page.dart index 6aecedc897..6ac1567733 100644 --- a/packages/ubuntu_desktop_installer/lib/pages/storage/guided_reformat/guided_reformat_page.dart +++ b/packages/ubuntu_desktop_installer/lib/pages/storage/guided_reformat/guided_reformat_page.dart @@ -1,4 +1,3 @@ -import 'package:filesize/filesize.dart'; import 'package:flutter/material.dart'; import 'package:flutter_riverpod/flutter_riverpod.dart'; import 'package:flutter_svg/flutter_svg.dart'; @@ -24,13 +23,13 @@ class GuidedReformatPage extends ConsumerWidget { } /// Formats a disk in a pretty way e.g. "sda ATA Maxtor (123 GB)" - String prettyFormatDisk(Disk disk) { + String prettyFormatDisk(BuildContext context, Disk disk) { final fullName = [ disk.model, disk.vendor, ].where((p) => p?.isNotEmpty == true).join(' '); - final size = filesize(disk.size); + final size = context.formatByteSize(disk.size); return '${disk.sysname} - $size $fullName'; } @@ -58,7 +57,8 @@ class GuidedReformatPage extends ConsumerWidget { itemBuilder: (context, index, child) { final disk = model.getDisk(index); return disk != null - ? Text(prettyFormatDisk(disk), key: ValueKey(index)) + ? Text(prettyFormatDisk(context, disk), + key: ValueKey(index)) : const SizedBox.shrink(); }, ), @@ -88,7 +88,7 @@ class GuidedReformatPage extends ConsumerWidget { Text(model.selectedDisk?.sysname ?? ''), const SizedBox(height: kWizardSpacing / 2), Text( - filesize(model.selectedDisk?.size ?? 0), + context.formatByteSize(model.selectedDisk?.size ?? 0), style: Theme.of(context).textTheme.headlineSmall, ), ], diff --git a/packages/ubuntu_desktop_installer/lib/pages/storage/guided_resize/guided_resize_widgets.dart b/packages/ubuntu_desktop_installer/lib/pages/storage/guided_resize/guided_resize_widgets.dart index a8dd691bc6..eb63a1073d 100644 --- a/packages/ubuntu_desktop_installer/lib/pages/storage/guided_resize/guided_resize_widgets.dart +++ b/packages/ubuntu_desktop_installer/lib/pages/storage/guided_resize/guided_resize_widgets.dart @@ -1,4 +1,3 @@ -import 'package:filesize/filesize.dart'; import 'package:flutter/material.dart'; import 'package:flutter_html/flutter_html.dart'; import 'package:flutter_riverpod/flutter_riverpod.dart'; @@ -31,7 +30,7 @@ class StorageSelector extends ConsumerWidget { final parts = [ partition?.sysname, if (os != null) os.long, - if (partition?.size != null) filesize(partition!.size), + if (partition?.size != null) context.formatByteSize(partition!.size!), ]; return parts.join(' - '); } diff --git a/packages/ubuntu_desktop_installer/lib/pages/storage/guided_resize/storage_button.dart b/packages/ubuntu_desktop_installer/lib/pages/storage/guided_resize/storage_button.dart index 3c56a585e7..9c01695e11 100644 --- a/packages/ubuntu_desktop_installer/lib/pages/storage/guided_resize/storage_button.dart +++ b/packages/ubuntu_desktop_installer/lib/pages/storage/guided_resize/storage_button.dart @@ -1,5 +1,5 @@ -import 'package:filesize/filesize.dart'; import 'package:flutter/material.dart'; +import 'package:ubuntu_localizations/ubuntu_localizations.dart'; import 'package:ubuntu_wizard/ubuntu_wizard.dart'; import 'storage_icon.dart'; @@ -48,7 +48,7 @@ class StorageButton extends StatelessWidget { ), const SizedBox(height: kWizardSpacing / 2), Text( - filesize(size), + context.formatByteSize(size), style: Theme.of(context).textTheme.headlineSmall, overflow: TextOverflow.clip, softWrap: false, diff --git a/packages/ubuntu_desktop_installer/lib/pages/storage/manual/manual_storage_widgets.dart b/packages/ubuntu_desktop_installer/lib/pages/storage/manual/manual_storage_widgets.dart index fe784cded8..a2783c7032 100644 --- a/packages/ubuntu_desktop_installer/lib/pages/storage/manual/manual_storage_widgets.dart +++ b/packages/ubuntu_desktop_installer/lib/pages/storage/manual/manual_storage_widgets.dart @@ -1,5 +1,4 @@ import 'package:collection/collection.dart'; -import 'package:filesize/filesize.dart'; import 'package:flutter/material.dart'; import 'package:flutter_riverpod/flutter_riverpod.dart'; import 'package:scroll_to_index/scroll_to_index.dart'; @@ -150,7 +149,10 @@ class _PartitionLabel extends StatelessWidget { crossAxisAlignment: CrossAxisAlignment.start, children: [ Text(title, style: Theme.of(context).textTheme.titleSmall), - Text(filesize(size), style: Theme.of(context).textTheme.bodySmall), + Text( + context.formatByteSize(size), + style: Theme.of(context).textTheme.bodySmall, + ), ], ), ], diff --git a/packages/ubuntu_desktop_installer/lib/pages/storage/manual/storage_columns.dart b/packages/ubuntu_desktop_installer/lib/pages/storage/manual/storage_columns.dart index 56e3849a05..159ce4738f 100644 --- a/packages/ubuntu_desktop_installer/lib/pages/storage/manual/storage_columns.dart +++ b/packages/ubuntu_desktop_installer/lib/pages/storage/manual/storage_columns.dart @@ -1,4 +1,3 @@ -import 'package:filesize/filesize.dart'; import 'package:flutter/material.dart'; import 'package:flutter_riverpod/flutter_riverpod.dart'; import 'package:subiquity_client/subiquity_client.dart'; @@ -131,7 +130,7 @@ class StorageSizeColumn extends StorageColumn { return Text(lang.diskHeadersSize); }, diskBuilder: (context, disk) { - return Text(filesize(disk.size)); + return Text(context.formatByteSize(disk.size)); }, gapBuilder: (context, disk, gap) { final lang = AppLocalizations.of(context); @@ -143,13 +142,13 @@ class StorageSizeColumn extends StorageColumn { ? lang.tooManyPrimaryPartitions : '', child: Text( - filesize(gap.size), + context.formatByteSize(gap.size), style: TextStyle(color: color), ), ); }, partitionBuilder: (context, disk, partition) { - return Text(filesize(partition.size ?? 0)); + return Text(context.formatByteSize(partition.size ?? 0)); }, ); } diff --git a/packages/ubuntu_desktop_installer/lib/pages/storage/manual/storage_selector.dart b/packages/ubuntu_desktop_installer/lib/pages/storage/manual/storage_selector.dart index 5b8064e97d..504cbfa91f 100644 --- a/packages/ubuntu_desktop_installer/lib/pages/storage/manual/storage_selector.dart +++ b/packages/ubuntu_desktop_installer/lib/pages/storage/manual/storage_selector.dart @@ -1,6 +1,6 @@ -import 'package:filesize/filesize.dart'; import 'package:flutter/material.dart'; import 'package:subiquity_client/subiquity_client.dart'; +import 'package:ubuntu_localizations/ubuntu_localizations.dart'; import 'package:ubuntu_widgets/ubuntu_widgets.dart'; class StorageSelector extends StatelessWidget { @@ -26,7 +26,7 @@ class StorageSelector extends StatelessWidget { storage.model, storage.vendor, ].where((p) => p?.isNotEmpty == true).join(' '); - return '${storage.sysname} $fullName (${filesize(storage.size)})'; + return '${storage.sysname} $fullName (${context.formatByteSize(storage.size)})'; } return Column( diff --git a/packages/ubuntu_desktop_installer/lib/pages/storage/manual/storage_types.dart b/packages/ubuntu_desktop_installer/lib/pages/storage/manual/storage_types.dart index ccc5aefc8a..68b6b76d67 100644 --- a/packages/ubuntu_desktop_installer/lib/pages/storage/manual/storage_types.dart +++ b/packages/ubuntu_desktop_installer/lib/pages/storage/manual/storage_types.dart @@ -1,4 +1,3 @@ -import 'package:filesize/filesize.dart'; import 'package:subiquity_client/subiquity_client.dart'; export 'package:subiquity_client/subiquity_client.dart' @@ -9,16 +8,11 @@ extension GapExtension on Gap { usable == GapUsable.TOO_MANY_PRIMARY_PARTS; } -extension DiskExtension on Disk { - String get prettySize => filesize(size); -} - extension PartitionExtension on Partition { bool get canWipe => PartitionFormat.fromPartition(this)?.canWipe == true; bool get canEdit => format != 'BitLocker'; bool get isEncrypted => format == 'BitLocker'; bool get isWiped => wipe == 'superblock'; - String get prettySize => filesize(size ?? 0); bool mustWipe(String? format) { // a preserved partition must be wiped if its format changed return preserve == true && format != null && this.format != format; diff --git a/packages/ubuntu_desktop_installer/pubspec.yaml b/packages/ubuntu_desktop_installer/pubspec.yaml index 95073a9098..11e4faeb6e 100644 --- a/packages/ubuntu_desktop_installer/pubspec.yaml +++ b/packages/ubuntu_desktop_installer/pubspec.yaml @@ -15,7 +15,6 @@ dependencies: dbus: ^0.7.3 diacritic: ^0.1.3 file: ^6.1.0 - filesize: ^2.0.0 flutter: sdk: flutter flutter_html: 3.0.0-beta.1 diff --git a/packages/ubuntu_desktop_installer/test/confirm/confirm_page_test.dart b/packages/ubuntu_desktop_installer/test/confirm/confirm_page_test.dart index 1031c694a5..151e88be1a 100644 --- a/packages/ubuntu_desktop_installer/test/confirm/confirm_page_test.dart +++ b/packages/ubuntu_desktop_installer/test/confirm/confirm_page_test.dart @@ -1,4 +1,3 @@ -import 'package:filesize/filesize.dart'; import 'package:flutter/material.dart'; import 'package:flutter_test/flutter_test.dart'; import 'package:mockito/mockito.dart'; @@ -112,8 +111,8 @@ void main() { find.html(tester.lang.writeChangesPartitionMounted('sdb5', '/mnt/5')), findsOneWidget); expect( - find.html(tester.lang - .writeChangesPartitionResized('sdb6', filesize(123), filesize(66))), + find.html( + tester.lang.writeChangesPartitionResized('sdb6', '123 B', '66 B')), findsOneWidget); expect(find.html(tester.lang.writeChangesPartitionCreated('sdb7')), findsOneWidget); diff --git a/packages/ubuntu_desktop_installer/test/source/not_enough_disk_space/not_enough_disk_space_page_test.dart b/packages/ubuntu_desktop_installer/test/source/not_enough_disk_space/not_enough_disk_space_page_test.dart index 857ec70cec..4d0077ec5f 100644 --- a/packages/ubuntu_desktop_installer/test/source/not_enough_disk_space/not_enough_disk_space_page_test.dart +++ b/packages/ubuntu_desktop_installer/test/source/not_enough_disk_space/not_enough_disk_space_page_test.dart @@ -1,7 +1,7 @@ -import 'package:filesize/filesize.dart'; import 'package:flutter/material.dart'; import 'package:flutter_riverpod/flutter_riverpod.dart'; import 'package:flutter_test/flutter_test.dart'; +import 'package:ubuntu_desktop_installer/l10n.dart'; import 'package:ubuntu_desktop_installer/pages/source/not_enough_disk_space/not_enough_disk_space_model.dart'; import 'package:ubuntu_desktop_installer/pages/source/not_enough_disk_space/not_enough_disk_space_page.dart'; import 'package:yaru_test/yaru_test.dart'; @@ -25,10 +25,11 @@ void main() { largestDiskSize: 123456, installMinimumSize: 654321); await tester.pumpWidget(tester.buildApp((_) => buildPage(model))); + final context = tester.element(find.byType(NotEnoughDiskSpacePage)); expect(find.text(tester.lang.notEnoughDiskSpaceUbuntu('Ubuntu')), findsOneWidget); - expect(find.text(filesize(123456)), findsOneWidget); - expect(find.text(filesize(654321)), findsOneWidget); + expect(find.text(context.formatByteSize(123456)), findsOneWidget); + expect(find.text(context.formatByteSize(654321)), findsOneWidget); }); testWidgets('quit', (tester) async { diff --git a/packages/ubuntu_desktop_installer/test/storage/guided_reformat/guided_reformat_page_test.dart b/packages/ubuntu_desktop_installer/test/storage/guided_reformat/guided_reformat_page_test.dart index 9affdc469a..08be556544 100644 --- a/packages/ubuntu_desktop_installer/test/storage/guided_reformat/guided_reformat_page_test.dart +++ b/packages/ubuntu_desktop_installer/test/storage/guided_reformat/guided_reformat_page_test.dart @@ -1,4 +1,3 @@ -import 'package:filesize/filesize.dart'; import 'package:flutter/material.dart'; import 'package:flutter_riverpod/flutter_riverpod.dart'; import 'package:flutter_test/flutter_test.dart'; @@ -7,6 +6,7 @@ import 'package:subiquity_client/subiquity_client.dart'; import 'package:subiquity_test/subiquity_test.dart'; import 'package:ubuntu_desktop_installer/pages/storage/guided_reformat/guided_reformat_model.dart'; import 'package:ubuntu_desktop_installer/pages/storage/guided_reformat/guided_reformat_page.dart'; +import 'package:ubuntu_localizations/ubuntu_localizations.dart'; import 'package:ubuntu_test/ubuntu_test.dart'; import 'package:ubuntu_widgets/ubuntu_widgets.dart'; @@ -80,7 +80,9 @@ void main() { ); await tester.pumpWidget(tester.buildApp((_) => buildPage(model))); expect(find.text(selectedDisk.sysname), findsOneWidget); - expect(find.text(filesize(selectedDisk.size)), findsOneWidget); + final context = tester.element(find.byType(GuidedReformatPage)); + expect( + find.text(context.formatByteSize(selectedDisk.size)), findsOneWidget); }); testWidgets('saves guided storage', (tester) async { diff --git a/packages/ubuntu_desktop_installer/test/storage/manual/manual_storage_page_test.dart b/packages/ubuntu_desktop_installer/test/storage/manual/manual_storage_page_test.dart index df747efd98..2ee6559e82 100644 --- a/packages/ubuntu_desktop_installer/test/storage/manual/manual_storage_page_test.dart +++ b/packages/ubuntu_desktop_installer/test/storage/manual/manual_storage_page_test.dart @@ -1,4 +1,3 @@ -import 'package:filesize/filesize.dart'; import 'package:flutter/material.dart'; import 'package:flutter_riverpod/flutter_riverpod.dart'; import 'package:flutter_test/flutter_test.dart'; @@ -9,6 +8,7 @@ import 'package:ubuntu_desktop_installer/pages/storage/manual/manual_storage_mod import 'package:ubuntu_desktop_installer/pages/storage/manual/manual_storage_page.dart'; import 'package:ubuntu_desktop_installer/pages/storage/manual/storage_selector.dart'; import 'package:ubuntu_desktop_installer/services.dart'; +import 'package:ubuntu_localizations/ubuntu_localizations.dart'; import 'package:ubuntu_test/ubuntu_test.dart'; import 'package:yaru_icons/yaru_icons.dart'; import 'package:yaru_test/yaru_test.dart'; @@ -78,14 +78,16 @@ void main() { final model = buildManualStorageModel(disks: testDisks); await tester.pumpWidget(tester.buildApp((_) => buildPage(model))); + final context = tester.element(find.byType(ManualStoragePage)); for (final disk in testDisks) { expect(find.text(disk.sysname), findsOneWidget); - expect(find.text(filesize(disk.size)), findsOneWidget); + expect(find.text(context.formatByteSize(disk.size)), findsOneWidget); for (final partition in disk.partitions.whereType()) { expect(find.text(partition.format!), findsOneWidget); expect(find.text(partition.mount!), findsOneWidget); - expect(find.text(filesize(partition.size!)), findsOneWidget); + expect( + find.text(context.formatByteSize(partition.size!)), findsOneWidget); } } });