From 139f44d31d85a63146805ab1b02e71a465594802 Mon Sep 17 00:00:00 2001 From: Imran Remtulla Date: Mon, 7 Nov 2022 15:32:42 -0500 Subject: [PATCH] UI improvement in APKPicker --- lib/custom_errors.dart | 16 ++++++++++++ lib/providers/apps_provider.dart | 45 ++++++++++++++++++-------------- 2 files changed, 42 insertions(+), 19 deletions(-) diff --git a/lib/custom_errors.dart b/lib/custom_errors.dart index b47444a..b1d4f3f 100644 --- a/lib/custom_errors.dart +++ b/lib/custom_errors.dart @@ -96,3 +96,19 @@ showError(dynamic e, BuildContext context) { }); } } + +String list2FriendlyString(List list) { + return list.length == 2 + ? '${list[0]} and ${list[1]}' + : list + .asMap() + .entries + .map((e) => + e.value + + (e.key == list.length - 1 + ? '' + : e.key == list.length - 2 + ? ', and ' + : ', ')) + .join(''); +} diff --git a/lib/providers/apps_provider.dart b/lib/providers/apps_provider.dart index 1e4db9f..621b60f 100644 --- a/lib/providers/apps_provider.dart +++ b/lib/providers/apps_provider.dart @@ -217,7 +217,7 @@ class AppsProvider with ChangeNotifier { return APKPicker( app: app, initVal: apkUrl, - arch: archs, + archs: archs, ); }); } @@ -594,11 +594,11 @@ class AppsProvider with ChangeNotifier { } class APKPicker extends StatefulWidget { - const APKPicker({super.key, required this.app, this.initVal, this.arch}); + const APKPicker({super.key, required this.app, this.initVal, this.archs}); final App app; final String? initVal; - final List? arch; + final List? archs; @override State createState() => _APKPickerState(); @@ -615,23 +615,30 @@ class _APKPickerState extends State { title: const Text('Pick an APK'), content: Column(children: [ Text('${widget.app.name} has more than one package:'), - Text( - 'Your device ${widget.arch!.length == 1 ? "support the:" : "supports:"} ${widget.arch!.join(", ")} CPU architecture${widget.arch!.length > 1 ? "s" : ""}', - textAlign: TextAlign.center, - ), const SizedBox(height: 16), - ...widget.app.apkUrls.map((u) => RadioListTile( - title: Text(Uri.parse(u) - .pathSegments - .where((element) => element.isNotEmpty) - .last), - value: u, - groupValue: apkUrl, - onChanged: (String? val) { - setState(() { - apkUrl = val; - }); - })) + ...widget.app.apkUrls.map( + (u) => RadioListTile( + title: Text(Uri.parse(u) + .pathSegments + .where((element) => element.isNotEmpty) + .last), + value: u, + groupValue: apkUrl, + onChanged: (String? val) { + setState(() { + apkUrl = val; + }); + }), + ), + if (widget.archs != null) + const SizedBox( + height: 16, + ), + if (widget.archs != null) + Text( + 'Note:\nYour device supports the ${widget.archs!.length == 1 ? '\'${widget.archs![0]}\' CPU architecture.' : 'following CPU architectures: ${list2FriendlyString(widget.archs!.map((e) => '\'$e\'').toList())}.'}', + style: const TextStyle(fontStyle: FontStyle.italic, fontSize: 12), + ), ]), actions: [ TextButton(