Resolves #201 New progress indicator in the bottom of the app

This commit is contained in:
Yegor Vialov 2018-11-23 16:30:42 +02:00
parent 12088d9516
commit cdf55ce68b

View File

@ -13,6 +13,7 @@ import 'package:date_format/date_format.dart';
import 'package:http/http.dart' as http; import 'package:http/http.dart' as http;
import 'package:flutter_colorpicker/material_picker.dart'; import 'package:flutter_colorpicker/material_picker.dart';
import 'package:charts_flutter/flutter.dart' as charts; import 'package:charts_flutter/flutter.dart' as charts;
import 'package:progress_indicators/progress_indicators.dart';
part 'entity_class/const.dart'; part 'entity_class/const.dart';
part 'entity_class/entity.class.dart'; part 'entity_class/entity.class.dart';
@ -242,7 +243,7 @@ class _MainPageState extends State<MainPage> with WidgetsBindingObserver {
_refreshData() async { _refreshData() async {
_homeAssistant.updateSettings(_webSocketApiEndpoint, _password, _authType, _useLovelaceUI); _homeAssistant.updateSettings(_webSocketApiEndpoint, _password, _authType, _useLovelaceUI);
_hideBottomBar(); _hideBottomBar();
_showInfoBottomBar(message: "Refreshing..."); _showInfoBottomBar(progress: true,);
await _homeAssistant.fetch().then((result) { await _homeAssistant.fetch().then((result) {
_hideBottomBar(); _hideBottomBar();
}).catchError((e) { }).catchError((e) {
@ -383,13 +384,15 @@ class _MainPageState extends State<MainPage> with WidgetsBindingObserver {
Widget _bottomBarAction; Widget _bottomBarAction;
bool _showBottomBar = false; bool _showBottomBar = false;
String _bottomBarText; String _bottomBarText;
bool _bottomBarProgress;
Color _bottomBarColor; Color _bottomBarColor;
void _showInfoBottomBar({@required String message}) { void _showInfoBottomBar({String message, bool progress: false}) {
_bottomBarAction = Container(height: 0.0, width: 0.0,); _bottomBarAction = Container(height: 0.0, width: 0.0,);
_bottomBarColor = Colors.grey.shade50; _bottomBarColor = Colors.grey.shade50;
setState(() { setState(() {
_bottomBarText = "$message"; _bottomBarText = message;
_bottomBarProgress = progress;
_showBottomBar = true; _showBottomBar = true;
}); });
} }
@ -472,6 +475,7 @@ class _MainPageState extends State<MainPage> with WidgetsBindingObserver {
} }
} }
setState(() { setState(() {
_bottomBarProgress = false;
_bottomBarText = "$message (code: $errorCode)"; _bottomBarText = "$message (code: $errorCode)";
_showBottomBar = true; _showBottomBar = true;
}); });
@ -535,18 +539,44 @@ class _MainPageState extends State<MainPage> with WidgetsBindingObserver {
Widget build(BuildContext context) { Widget build(BuildContext context) {
Widget bottomBar; Widget bottomBar;
if (_showBottomBar) { if (_showBottomBar) {
List<Widget> bottomBarChildren = [];
if (_bottomBarText != null) {
bottomBarChildren.add(
Padding(
padding: EdgeInsets.fromLTRB(
Sizes.leftWidgetPadding, Sizes.rowPadding, 0.0,
Sizes.rowPadding),
child: Text(
"$_bottomBarText",
textAlign: TextAlign.left,
softWrap: true,
),
)
);
}
if (_bottomBarProgress) {
bottomBarChildren.add(
CollectionScaleTransition(
children: <Widget>[
Icon(Icons.stop, size: 10.0, color: EntityColor.stateColor(EntityState.on),),
Icon(Icons.stop, size: 10.0, color: EntityColor.stateColor(EntityState.unavailable),),
Icon(Icons.stop, size: 10.0, color: EntityColor.stateColor(EntityState.off),),
],
),
);
}
if (bottomBarChildren.isNotEmpty) {
bottomBar = Container( bottomBar = Container(
color: _bottomBarColor, color: _bottomBarColor,
child: Row( child: Row(
mainAxisSize: MainAxisSize.max, mainAxisSize: MainAxisSize.max,
children: <Widget>[ children: <Widget>[
Expanded( Expanded(
child: Padding( child: Column(
padding: EdgeInsets.fromLTRB(Sizes.leftWidgetPadding, Sizes.rowPadding, 0.0, Sizes.rowPadding), crossAxisAlignment: _bottomBarProgress ? CrossAxisAlignment.center : CrossAxisAlignment.start,
child: Text( mainAxisSize: MainAxisSize.min,
"$_bottomBarText", children: bottomBarChildren,
softWrap: true,
),
), ),
), ),
_bottomBarAction _bottomBarAction
@ -554,6 +584,7 @@ class _MainPageState extends State<MainPage> with WidgetsBindingObserver {
), ),
); );
} }
}
// This method is rerun every time setState is called. // This method is rerun every time setState is called.
if (_homeAssistant.ui == null || _homeAssistant.ui.views == null) { if (_homeAssistant.ui == null || _homeAssistant.ui.views == null) {
return Scaffold( return Scaffold(