diff --git a/lib/main.dart b/lib/main.dart index 251d685..6a08e8e 100644 --- a/lib/main.dart +++ b/lib/main.dart @@ -80,7 +80,7 @@ void main() async { setWindowMaxSize(const Size(692, 580)); final foundQuickGet = await Process.run('which', ['quickget']); if (foundQuickGet.exitCode == 0) { - gOperatingSystems = await loadOperatingSystems(false); + gOperatingSystems = loadOperatingSystems(false); getIcons(); AppVersion.packageInfo = await PackageInfo.fromPlatform(); } diff --git a/lib/src/model/operating_system.dart b/lib/src/model/operating_system.dart index a3c913d..f870138 100644 --- a/lib/src/model/operating_system.dart +++ b/lib/src/model/operating_system.dart @@ -8,4 +8,4 @@ class OperatingSystem { List versions; } -var gOperatingSystems = []; +Future>? gOperatingSystems; diff --git a/lib/src/pages/operating_system_selection.dart b/lib/src/pages/operating_system_selection.dart index 622fc2c..2645a87 100644 --- a/lib/src/pages/operating_system_selection.dart +++ b/lib/src/pages/operating_system_selection.dart @@ -25,9 +25,6 @@ class _OperatingSystemSelectionState extends State { @override Widget build(BuildContext context) { - var list = gOperatingSystems - .where((os) => os.name.toLowerCase().contains(term.toLowerCase())) - .toList(); return Scaffold( appBar: AppBar( title: Text(context.t('Select operating system')), @@ -69,36 +66,61 @@ class _OperatingSystemSelectionState extends State { body: SingleChildScrollView( child: Column( children: [ - ListView.builder( - padding: const EdgeInsets.only(top: 4), - shrinkWrap: true, - itemCount: list.length, - itemBuilder: (context, index) { - var item = list[index]; - Widget icon; + FutureBuilder( + future: gOperatingSystems, + builder: (BuildContext context, AsyncSnapshot snapshot) { + if (snapshot.hasData) { + List list = snapshot.data! + .where((os) => os.name.toLowerCase().contains(term.toLowerCase())) + .toList(); + return ListView.builder( + padding: const EdgeInsets.only(top: 4), + shrinkWrap: true, + itemCount: list.length, + itemBuilder: (context, index) { + var item = list[index]; + Widget icon; - if (osIcons.containsKey(item.code)) { - icon = SvgPicture.asset( - osIcons[item.code]!, - width: 32, - height: 32, + if (osIcons.containsKey(item.code)) { + icon = SvgPicture.asset( + osIcons[item.code]!, + width: 32, + height: 32, + ); + } else { + // Replace with generic icon + icon = const Icon(Icons.computer, size: 32); + } + return Card( + child: ListTile( + title: Text(item.name), + leading: icon, + onTap: () { + Navigator.of(context).pop(item); + }, + ), + ); + }, ); } else { - // Replace with generic icon - icon = const Icon(Icons.computer, size: 32); + return Row( + mainAxisAlignment: MainAxisAlignment.center, + children: [ + Column( + children: [ + const Padding( + padding: EdgeInsets.all(16.0), + child: CircularProgressIndicator() + ), + Text(context.t('Loading available downloads')), + ], + ) + ], + ); } - return Card( - child: ListTile( - title: Text(item.name), - leading: icon, - onTap: () { - Navigator.of(context).pop(item); - }, - ), - ); - }, + } ), - ], + ] ), ), ); diff --git a/pubspec.yaml b/pubspec.yaml index 96277fd..bacbd40 100644 --- a/pubspec.yaml +++ b/pubspec.yaml @@ -4,7 +4,7 @@ publish_to: 'none' # Remove this line if you wish to publish to pub.dev version: 1.2.8-1 environment: - sdk: ">=2.14.4 <3.0.0" + sdk: ">=2.15.0 <3.0.0" dependencies: flutter: