More UI tweaks

This commit is contained in:
Imran Remtulla
2022-08-18 22:40:57 -04:00
parent 821fd6934a
commit 15d5ac1eef
2 changed files with 74 additions and 32 deletions

View File

@@ -15,6 +15,7 @@ class _AppsPageState extends State<AppsPage> {
@override @override
Widget build(BuildContext context) { Widget build(BuildContext context) {
var appsProvider = context.watch<AppsProvider>(); var appsProvider = context.watch<AppsProvider>();
appsProvider.getUpdates();
return Scaffold( return Scaffold(
appBar: AppBar( appBar: AppBar(
@@ -28,35 +29,70 @@ class _AppsPageState extends State<AppsPage> {
'No Apps', 'No Apps',
style: Theme.of(context).textTheme.headline4, style: Theme.of(context).textTheme.headline4,
) )
: ListView( : RefreshIndicator(
children: appsProvider.apps.values onRefresh: appsProvider.getUpdates,
.map( child: ListView(
(e) => ListTile( children: appsProvider.apps.values
title: Text(e.name), .map(
subtitle: Text(e.author), (e) => ListTile(
trailing: title: Text('${e.author}/${e.name}'),
Text(e.installedVersion ?? 'Not Installed'), subtitle:
onTap: () { Text(e.installedVersion ?? 'Not Installed'),
Navigator.push( trailing: e.installedVersion != null &&
context, e.installedVersion != e.latestVersion
MaterialPageRoute( ? const Text('Update Available')
builder: (context) => AppPage(appId: e.id)), : null,
); onTap: () {
}, Navigator.push(
), context,
) MaterialPageRoute(
.toList(), builder: (context) =>
AppPage(appId: e.id)),
);
},
),
)
.toList(),
),
), ),
), ),
floatingActionButton: FloatingActionButton( bottomSheet: Column(
onPressed: () { mainAxisSize: MainAxisSize.min,
Navigator.push( children: [
context, Padding(
MaterialPageRoute(builder: (context) => const AddAppPage()), padding:
); const EdgeInsets.symmetric(vertical: 8.0, horizontal: 16.0),
}, child: Row(
tooltip: 'Add App', mainAxisAlignment: MainAxisAlignment.spaceEvenly,
child: const Icon(Icons.add), children: [
Expanded(
child: appsProvider.apps.values.toList().where((e) {
return (e.installedVersion != null &&
e.installedVersion != e.latestVersion);
}).isNotEmpty
? OutlinedButton(
onPressed: () {
appsProvider.installUpdates().catchError((e) {
ScaffoldMessenger.of(context).showSnackBar(
SnackBar(content: Text(e.toString())),
);
});
},
child: const Text('Update All'))
: Container()),
const SizedBox(width: 16.0),
OutlinedButton(
onPressed: () {
Navigator.push(
context,
MaterialPageRoute(
builder: (context) => const AddAppPage()),
);
},
child: const Text('Add App'),
),
])),
],
), ),
); );
} }

View File

@@ -17,6 +17,7 @@ class AppsProvider with ChangeNotifier {
// In memory App state (should always be kept in sync with local storage versions) // In memory App state (should always be kept in sync with local storage versions)
Map<String, App> apps = {}; Map<String, App> apps = {};
bool loadingApps = false; bool loadingApps = false;
bool gettingUpdates = false;
AppsProvider() { AppsProvider() {
initializeDownloader(); initializeDownloader();
@@ -213,12 +214,17 @@ class AppsProvider with ChangeNotifier {
Future<List<App>> getUpdates() async { Future<List<App>> getUpdates() async {
List<App> updates = []; List<App> updates = [];
List<String> appIds = apps.keys.toList(); if (!gettingUpdates) {
for (int i = 0; i < appIds.length; i++) { gettingUpdates = true;
App? newApp = await getUpdate(appIds[i]);
if (newApp != null) { List<String> appIds = apps.keys.toList();
updates.add(newApp); for (int i = 0; i < appIds.length; i++) {
App? newApp = await getUpdate(appIds[i]);
if (newApp != null) {
updates.add(newApp);
}
} }
gettingUpdates = false;
} }
return updates; return updates;
} }