App update
This commit is contained in:
parent
8349f2ec4b
commit
dbcdb67756
|
|
@ -1,4 +1,5 @@
|
|||
import 'package:flutter/cupertino.dart';
|
||||
import 'package:flutter/foundation.dart';
|
||||
import 'package:flutter/material.dart';
|
||||
import 'package:flutter_redux/flutter_redux.dart';
|
||||
import 'package:invoiceninja_flutter/constants.dart';
|
||||
|
|
@ -15,8 +16,14 @@ class UpdateDialog extends StatefulWidget {
|
|||
_UpdateDialogState createState() => _UpdateDialogState();
|
||||
}
|
||||
|
||||
enum UpdateState {
|
||||
initial,
|
||||
loading,
|
||||
done,
|
||||
}
|
||||
|
||||
class _UpdateDialogState extends State<UpdateDialog> {
|
||||
bool _isLoading = false;
|
||||
UpdateState updateState = UpdateState.initial;
|
||||
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
|
|
@ -24,7 +31,9 @@ class _UpdateDialogState extends State<UpdateDialog> {
|
|||
|
||||
return AlertDialog(
|
||||
title: Text(localization.updateAvailable),
|
||||
content: _isLoading
|
||||
content: updateState == UpdateState.done
|
||||
? Text(localization.appUpdated)
|
||||
: updateState == UpdateState.loading
|
||||
? LoadingIndicator(height: 50)
|
||||
: Column(
|
||||
crossAxisAlignment: CrossAxisAlignment.start,
|
||||
|
|
@ -37,7 +46,7 @@ class _UpdateDialogState extends State<UpdateDialog> {
|
|||
],
|
||||
),
|
||||
actions: <Widget>[
|
||||
if (!_isLoading) ...[
|
||||
if (updateState == UpdateState.initial) ...[
|
||||
FlatButton(
|
||||
child: Text(localization.cancel.toUpperCase()),
|
||||
onPressed: () {
|
||||
|
|
@ -50,7 +59,13 @@ class _UpdateDialogState extends State<UpdateDialog> {
|
|||
updateApp(context);
|
||||
},
|
||||
),
|
||||
]
|
||||
] else if (updateState == UpdateState.done)
|
||||
FlatButton(
|
||||
child: Text(localization.close.toUpperCase()),
|
||||
onPressed: () {
|
||||
Navigator.of(context).pop();
|
||||
},
|
||||
),
|
||||
],
|
||||
);
|
||||
}
|
||||
|
|
@ -60,21 +75,23 @@ class _UpdateDialogState extends State<UpdateDialog> {
|
|||
passwordCallback(
|
||||
context: context,
|
||||
callback: (password) {
|
||||
setState(() => _isLoading = true);
|
||||
setState(() => updateState = UpdateState.loading);
|
||||
final credentials = state.credentials;
|
||||
final webClient = WebClient();
|
||||
const url = '/self-update';
|
||||
webClient
|
||||
.post(url, credentials.token, password: password)
|
||||
.then((dynamic response) {
|
||||
setState(() => _isLoading = false);
|
||||
print('## response: $response');
|
||||
if (response == 'done') {
|
||||
if (response == '{message: true}') {
|
||||
setState(() => updateState = UpdateState.done);
|
||||
if (kIsWeb) {
|
||||
webReload();
|
||||
}
|
||||
}
|
||||
}).catchError((dynamic error) {
|
||||
showErrorDialog(context: context, message: '$error');
|
||||
setState(() => _isLoading = false);
|
||||
setState(() => updateState = UpdateState.initial);
|
||||
});
|
||||
});
|
||||
}
|
||||
|
|
|
|||
|
|
@ -17,8 +17,9 @@ mixin LocalizationsProvider on LocaleCodeAware {
|
|||
'current_version': 'Current Version',
|
||||
'latest_version': 'Latest Version',
|
||||
'update_now': 'Update Now',
|
||||
'a_new_version_is_available': 'A new version of the app is available',
|
||||
'a_new_version_is_available': 'A new version of the web app is available',
|
||||
'update_available': 'Update Available',
|
||||
'app_updated': 'Update successfully completed',
|
||||
'learn_more': 'Learn More',
|
||||
'integrations': 'Integrations',
|
||||
'tracking_id': 'Tracking Id',
|
||||
|
|
@ -32747,6 +32748,8 @@ mixin LocalizationsProvider on LocaleCodeAware {
|
|||
|
||||
String get latestVersion => _localizedValues[localeCode]['latest_version'];
|
||||
|
||||
String get appUpdated => _localizedValues[localeCode]['app_updated'];
|
||||
|
||||
String lookup(String key) {
|
||||
final lookupKey = toSnakeCase(key);
|
||||
return _localizedValues[localeCode][lookupKey] ??
|
||||
|
|
|
|||
Loading…
Reference in New Issue