Adjust loading indicator

This commit is contained in:
Hillel Coren 2021-10-11 15:25:22 +03:00
parent 4ee3b041e9
commit 5dd1981b8d
4 changed files with 40 additions and 88 deletions

View File

@ -1,55 +0,0 @@
import 'package:flutter/material.dart';
import 'package:flutter_redux/flutter_redux.dart';
import 'package:invoiceninja_flutter/redux/app/app_state.dart';
import 'package:invoiceninja_flutter/ui/app/buttons/app_text_button.dart';
class ActionTextButton extends StatelessWidget {
const ActionTextButton({
this.onPressed,
this.tooltip,
this.isSaving = false,
this.isVisible = true,
this.isHeader = false,
});
final bool isSaving;
final bool isVisible;
final Function onPressed;
final String tooltip;
final bool isHeader;
@override
Widget build(BuildContext context) {
final store = StoreProvider.of<AppState>(context);
final state = store.state;
if (!isVisible) {
return Container();
}
if (isSaving) {
return SizedBox(
width: 80,
child: IconButton(
onPressed: null,
icon: SizedBox(
width: 28,
height: 28,
child: CircularProgressIndicator(
valueColor: AlwaysStoppedAnimation<Color>(
state.hasAccentColor || state.prefState.enableDarkMode
? Colors.white
: state.accentColor),
),
),
),
);
}
return AppTextButton(
label: tooltip,
isInHeader: isHeader,
onPressed: onPressed,
);
}
}

View File

@ -130,30 +130,43 @@ class EditScaffold extends StatelessWidget {
], ],
), ),
actions: <Widget>[ actions: <Widget>[
SaveCancelButtons( if (state.isSaving)
isEnabled: isEnabled && onSavePressed != null, Padding(
isHeader: true, padding: const EdgeInsets.only(right: 20),
isCancelEnabled: isCancelEnabled, child: Center(
saveLabel: saveLabel, child: SizedBox(
isSaving: state.isSaving, width: 28,
onSavePressed: (context) { height: 28,
// Clear focus now to prevent un-focus after save from child: CircularProgressIndicator(
// marking the form as changed and to hide the keyboard color:
FocusScope.of(context).unfocus( state.prefState.enableDarkMode ? Colors.white : null,
disposition: UnfocusDisposition.previouslyFocusedChild); ),
)),
)
else
SaveCancelButtons(
isEnabled: isEnabled && onSavePressed != null,
isHeader: true,
isCancelEnabled: isCancelEnabled,
saveLabel: saveLabel,
onSavePressed: (context) {
// Clear focus now to prevent un-focus after save from
// marking the form as changed and to hide the keyboard
FocusScope.of(context).unfocus(
disposition: UnfocusDisposition.previouslyFocusedChild);
onSavePressed(context); onSavePressed(context);
}, },
onCancelPressed: isMobile(context) onCancelPressed: isMobile(context)
? null ? null
: (context) { : (context) {
if (onCancelPressed != null) { if (onCancelPressed != null) {
onCancelPressed(context); onCancelPressed(context);
} else { } else {
store.dispatch(ResetSettings()); store.dispatch(ResetSettings());
} }
}, },
), ),
if (actions != null && !state.isSaving) if (actions != null && !state.isSaving)
PopupMenuButton<EntityAction>( PopupMenuButton<EntityAction>(
icon: Icon( icon: Icon(

View File

@ -1,5 +1,4 @@
import 'package:flutter/material.dart'; import 'package:flutter/material.dart';
import 'package:invoiceninja_flutter/ui/app/buttons/action_flat_button.dart';
import 'package:invoiceninja_flutter/ui/app/buttons/app_text_button.dart'; import 'package:invoiceninja_flutter/ui/app/buttons/app_text_button.dart';
import 'package:invoiceninja_flutter/utils/localization.dart'; import 'package:invoiceninja_flutter/utils/localization.dart';
@ -10,14 +9,12 @@ class SaveCancelButtons extends StatelessWidget {
this.saveLabel, this.saveLabel,
this.cancelLabel, this.cancelLabel,
this.isHeader = true, this.isHeader = true,
this.isSaving = false,
this.isEnabled = true, this.isEnabled = true,
this.isCancelEnabled = false, this.isCancelEnabled = false,
}); });
final bool isEnabled; final bool isEnabled;
final bool isCancelEnabled; final bool isCancelEnabled;
final bool isSaving;
final String saveLabel; final String saveLabel;
final String cancelLabel; final String cancelLabel;
final bool isHeader; final bool isHeader;
@ -32,7 +29,7 @@ class SaveCancelButtons extends StatelessWidget {
crossAxisAlignment: crossAxisAlignment:
isHeader ? CrossAxisAlignment.stretch : CrossAxisAlignment.center, isHeader ? CrossAxisAlignment.stretch : CrossAxisAlignment.center,
children: <Widget>[ children: <Widget>[
if (onCancelPressed != null && !isSaving) if (onCancelPressed != null)
Builder(builder: (BuildContext context) { Builder(builder: (BuildContext context) {
return AppTextButton( return AppTextButton(
label: cancelLabel ?? localization.cancel, label: cancelLabel ?? localization.cancel,
@ -43,11 +40,9 @@ class SaveCancelButtons extends StatelessWidget {
); );
}), }),
Builder(builder: (BuildContext context) { Builder(builder: (BuildContext context) {
return ActionTextButton( return AppTextButton(
tooltip: saveLabel ?? localization.save, label: saveLabel ?? localization.save,
isVisible: true, isInHeader: isHeader,
isSaving: isSaving,
isHeader: isHeader,
onPressed: isEnabled ? () => onSavePressed(context) : null, onPressed: isEnabled ? () => onSavePressed(context) : null,
); );
}), }),

View File

@ -88,7 +88,6 @@ class CompanyGatewayScreen extends StatelessWidget {
isEnabled: settingsUIState.isChanged, isEnabled: settingsUIState.isChanged,
isCancelEnabled: true, isCancelEnabled: true,
isHeader: true, isHeader: true,
isSaving: state.isSaving,
onSavePressed: viewModel.onSavePressed, onSavePressed: viewModel.onSavePressed,
onCancelPressed: isMobile(context) || !settingsUIState.isChanged onCancelPressed: isMobile(context) || !settingsUIState.isChanged
? null ? null