-
-
Notifications
You must be signed in to change notification settings - Fork 166
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* add requirements dialog * make storage op dialog futurebuilder
- Loading branch information
1 parent
823ff52
commit b5a06fc
Showing
8 changed files
with
172 additions
and
42 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,34 +1,77 @@ | ||
|
||
import 'package:flutter/material.dart'; | ||
import 'package:maid/providers/session.dart'; | ||
import 'package:provider/provider.dart'; | ||
|
||
Future<void> storageOperationDialog(BuildContext context, Future<String> Function(BuildContext context) storageFunction) async { | ||
String ret = await storageFunction(context); | ||
// Ensure that the context is still valid before attempting to show the dialog. | ||
if (context.mounted) { | ||
showDialog( | ||
context: context, | ||
builder: (BuildContext context) { | ||
return AlertDialog( | ||
title: Text(ret), | ||
alignment: Alignment.center, | ||
actionsAlignment: MainAxisAlignment.center, | ||
backgroundColor: Theme.of(context).colorScheme.background, | ||
shape: const RoundedRectangleBorder( | ||
borderRadius: BorderRadius.all(Radius.circular(20.0)), | ||
), | ||
actions: [ | ||
FilledButton( | ||
onPressed: () { | ||
Navigator.of(context).pop(); | ||
}, | ||
child: Text( | ||
"Close", | ||
style: Theme.of(context).textTheme.labelLarge, | ||
void storageOperationDialog(BuildContext context, Future<String> Function(BuildContext context) storageFunction) { | ||
showDialog( | ||
context: context, | ||
builder: (BuildContext context) { | ||
return FutureBuilder<String>( | ||
future: storageFunction(context), | ||
builder: (BuildContext context, AsyncSnapshot<String> snapshot) { | ||
if (snapshot.connectionState == ConnectionState.done) { | ||
return AlertDialog( | ||
title: Text( | ||
snapshot.data!, | ||
textAlign: TextAlign.center | ||
), | ||
actionsAlignment: MainAxisAlignment.center, | ||
actions: [ | ||
FilledButton( | ||
onPressed: () { | ||
Navigator.of(context).pop(); | ||
}, | ||
child: Text( | ||
"Close", | ||
style: Theme.of(context).textTheme.labelLarge, | ||
), | ||
), | ||
], | ||
); | ||
} else { | ||
return const AlertDialog( | ||
title: Text( | ||
"Storage Operation Pending", | ||
textAlign: TextAlign.center | ||
), | ||
content: Center( | ||
heightFactor: 1.0, | ||
child: CircularProgressIndicator(), | ||
) | ||
); | ||
} | ||
}, | ||
); | ||
}, | ||
); | ||
} | ||
|
||
void showMissingRequirementsDialog(BuildContext context) { | ||
showDialog( | ||
context: context, | ||
builder: (context) { | ||
final requirement = context.read<Session>().model.missingRequirements; | ||
|
||
return AlertDialog( | ||
title: const Text( | ||
"Missing Requirements", | ||
textAlign: TextAlign.center | ||
), | ||
actionsAlignment: MainAxisAlignment.center, | ||
content: Text( | ||
requirement.join() | ||
), | ||
actions: [ | ||
FilledButton( | ||
onPressed: () => Navigator.of(context).pop(), | ||
child: Text( | ||
"OK", | ||
style: Theme.of(context).textTheme.labelLarge | ||
), | ||
], | ||
); | ||
}, | ||
); | ||
} | ||
), | ||
], | ||
); | ||
}, | ||
); | ||
} |