App update

This commit is contained in:
Hillel Coren 2020-03-02 08:19:20 +02:00
parent 8349f2ec4b
commit dbcdb67756
2 changed files with 41 additions and 21 deletions

View File

@ -1,4 +1,5 @@
import 'package:flutter/cupertino.dart'; import 'package:flutter/cupertino.dart';
import 'package:flutter/foundation.dart';
import 'package:flutter/material.dart'; import 'package:flutter/material.dart';
import 'package:flutter_redux/flutter_redux.dart'; import 'package:flutter_redux/flutter_redux.dart';
import 'package:invoiceninja_flutter/constants.dart'; import 'package:invoiceninja_flutter/constants.dart';
@ -15,8 +16,14 @@ class UpdateDialog extends StatefulWidget {
_UpdateDialogState createState() => _UpdateDialogState(); _UpdateDialogState createState() => _UpdateDialogState();
} }
enum UpdateState {
initial,
loading,
done,
}
class _UpdateDialogState extends State<UpdateDialog> { class _UpdateDialogState extends State<UpdateDialog> {
bool _isLoading = false; UpdateState updateState = UpdateState.initial;
@override @override
Widget build(BuildContext context) { Widget build(BuildContext context) {
@ -24,20 +31,22 @@ class _UpdateDialogState extends State<UpdateDialog> {
return AlertDialog( return AlertDialog(
title: Text(localization.updateAvailable), title: Text(localization.updateAvailable),
content: _isLoading content: updateState == UpdateState.done
? LoadingIndicator(height: 50) ? Text(localization.appUpdated)
: Column( : updateState == UpdateState.loading
crossAxisAlignment: CrossAxisAlignment.start, ? LoadingIndicator(height: 50)
mainAxisSize: MainAxisSize.min, : Column(
children: <Widget>[ crossAxisAlignment: CrossAxisAlignment.start,
Text(localization.aNewVersionIsAvailable), mainAxisSize: MainAxisSize.min,
SizedBox(height: 20), children: <Widget>[
Text('${localization.currentVersion}: v$kAppVersion'), Text(localization.aNewVersionIsAvailable),
//Text('${localization.latestVersion}: v???'), SizedBox(height: 20),
], Text('${localization.currentVersion}: v$kAppVersion'),
), //Text('${localization.latestVersion}: v???'),
],
),
actions: <Widget>[ actions: <Widget>[
if (!_isLoading) ...[ if (updateState == UpdateState.initial) ...[
FlatButton( FlatButton(
child: Text(localization.cancel.toUpperCase()), child: Text(localization.cancel.toUpperCase()),
onPressed: () { onPressed: () {
@ -50,7 +59,13 @@ class _UpdateDialogState extends State<UpdateDialog> {
updateApp(context); 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( passwordCallback(
context: context, context: context,
callback: (password) { callback: (password) {
setState(() => _isLoading = true); setState(() => updateState = UpdateState.loading);
final credentials = state.credentials; final credentials = state.credentials;
final webClient = WebClient(); final webClient = WebClient();
const url = '/self-update'; const url = '/self-update';
webClient webClient
.post(url, credentials.token, password: password) .post(url, credentials.token, password: password)
.then((dynamic response) { .then((dynamic response) {
setState(() => _isLoading = false);
print('## response: $response'); print('## response: $response');
if (response == 'done') { if (response == '{message: true}') {
webReload(); setState(() => updateState = UpdateState.done);
if (kIsWeb) {
webReload();
}
} }
}).catchError((dynamic error) { }).catchError((dynamic error) {
showErrorDialog(context: context, message: '$error'); showErrorDialog(context: context, message: '$error');
setState(() => _isLoading = false); setState(() => updateState = UpdateState.initial);
}); });
}); });
} }

View File

@ -17,8 +17,9 @@ mixin LocalizationsProvider on LocaleCodeAware {
'current_version': 'Current Version', 'current_version': 'Current Version',
'latest_version': 'Latest Version', 'latest_version': 'Latest Version',
'update_now': 'Update Now', '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', 'update_available': 'Update Available',
'app_updated': 'Update successfully completed',
'learn_more': 'Learn More', 'learn_more': 'Learn More',
'integrations': 'Integrations', 'integrations': 'Integrations',
'tracking_id': 'Tracking Id', 'tracking_id': 'Tracking Id',
@ -32747,6 +32748,8 @@ mixin LocalizationsProvider on LocaleCodeAware {
String get latestVersion => _localizedValues[localeCode]['latest_version']; String get latestVersion => _localizedValues[localeCode]['latest_version'];
String get appUpdated => _localizedValues[localeCode]['app_updated'];
String lookup(String key) { String lookup(String key) {
final lookupKey = toSnakeCase(key); final lookupKey = toSnakeCase(key);
return _localizedValues[localeCode][lookupKey] ?? return _localizedValues[localeCode][lookupKey] ??