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,19 +29,25 @@ class _AppsPageState extends State<AppsPage> {
'No Apps', 'No Apps',
style: Theme.of(context).textTheme.headline4, style: Theme.of(context).textTheme.headline4,
) )
: ListView( : RefreshIndicator(
onRefresh: appsProvider.getUpdates,
child: ListView(
children: appsProvider.apps.values children: appsProvider.apps.values
.map( .map(
(e) => ListTile( (e) => ListTile(
title: Text(e.name), title: Text('${e.author}/${e.name}'),
subtitle: Text(e.author), subtitle:
trailing:
Text(e.installedVersion ?? 'Not Installed'), Text(e.installedVersion ?? 'Not Installed'),
trailing: e.installedVersion != null &&
e.installedVersion != e.latestVersion
? const Text('Update Available')
: null,
onTap: () { onTap: () {
Navigator.push( Navigator.push(
context, context,
MaterialPageRoute( MaterialPageRoute(
builder: (context) => AppPage(appId: e.id)), builder: (context) =>
AppPage(appId: e.id)),
); );
}, },
), ),
@@ -48,15 +55,44 @@ class _AppsPageState extends State<AppsPage> {
.toList(), .toList(),
), ),
), ),
floatingActionButton: FloatingActionButton( ),
bottomSheet: Column(
mainAxisSize: MainAxisSize.min,
children: [
Padding(
padding:
const EdgeInsets.symmetric(vertical: 8.0, horizontal: 16.0),
child: Row(
mainAxisAlignment: MainAxisAlignment.spaceEvenly,
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: () { onPressed: () {
Navigator.push( Navigator.push(
context, context,
MaterialPageRoute(builder: (context) => const AddAppPage()), MaterialPageRoute(
builder: (context) => const AddAppPage()),
); );
}, },
tooltip: 'Add App', child: const Text('Add App'),
child: const Icon(Icons.add), ),
])),
],
), ),
); );
} }

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,6 +214,9 @@ class AppsProvider with ChangeNotifier {
Future<List<App>> getUpdates() async { Future<List<App>> getUpdates() async {
List<App> updates = []; List<App> updates = [];
if (!gettingUpdates) {
gettingUpdates = true;
List<String> appIds = apps.keys.toList(); List<String> appIds = apps.keys.toList();
for (int i = 0; i < appIds.length; i++) { for (int i = 0; i < appIds.length; i++) {
App? newApp = await getUpdate(appIds[i]); App? newApp = await getUpdate(appIds[i]);
@@ -220,6 +224,8 @@ class AppsProvider with ChangeNotifier {
updates.add(newApp); updates.add(newApp);
} }
} }
gettingUpdates = false;
}
return updates; return updates;
} }