Improve OS loading
Rather than waiting for the OS list to load, when the app starts, the loads them in the background, and only waits if we reach the list of available downloads without them loaded yet. In this case, we use a FutureBuilder to display a loading spinner until the list is ready.
This commit is contained in:
parent
208d4f8dc9
commit
3c23106d32
|
@ -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();
|
||||
}
|
||||
|
|
|
@ -8,4 +8,4 @@ class OperatingSystem {
|
|||
List<Version> versions;
|
||||
}
|
||||
|
||||
var gOperatingSystems = <OperatingSystem>[];
|
||||
Future<List<OperatingSystem>>? gOperatingSystems;
|
||||
|
|
|
@ -25,9 +25,6 @@ class _OperatingSystemSelectionState extends State<OperatingSystemSelection> {
|
|||
|
||||
@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<OperatingSystemSelection> {
|
|||
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<List> 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);
|
||||
},
|
||||
),
|
||||
);
|
||||
},
|
||||
}
|
||||
),
|
||||
],
|
||||
]
|
||||
),
|
||||
),
|
||||
);
|
||||
|
|
|
@ -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:
|
||||
|
|
Loading…
Reference in New Issue