User error messages
This commit is contained in:
parent
fb335e1100
commit
8d1b159f56
@ -118,7 +118,7 @@ part 'ui_widgets/card_widget.dart';
|
|||||||
part 'ui_widgets/card_header_widget.dart';
|
part 'ui_widgets/card_header_widget.dart';
|
||||||
part 'panels/config_panel_widget.dart';
|
part 'panels/config_panel_widget.dart';
|
||||||
part 'panels/widgets/link_to_web_config.dart';
|
part 'panels/widgets/link_to_web_config.dart';
|
||||||
part 'pages/widgets/user_error_screen.widget.dart';
|
part 'pages/widgets/user_error_panel.widget.dart';
|
||||||
|
|
||||||
|
|
||||||
EventBus eventBus = new EventBus();
|
EventBus eventBus = new EventBus();
|
||||||
|
@ -385,7 +385,7 @@ class _MainPageState extends State<MainPage> with WidgetsBindingObserver, Ticker
|
|||||||
Widget build(BuildContext context) {
|
Widget build(BuildContext context) {
|
||||||
Widget bottomBar;
|
Widget bottomBar;
|
||||||
if (_userError != null) {
|
if (_userError != null) {
|
||||||
bottomBar = UserErrorScreen(error: _userError,);
|
bottomBar = UserErrorPanel(error: _userError,);
|
||||||
/*List<Widget> bottomBarChildren = [];
|
/*List<Widget> bottomBarChildren = [];
|
||||||
if (_bottomBarText != null) {
|
if (_bottomBarText != null) {
|
||||||
bottomBarChildren.add(
|
bottomBarChildren.add(
|
||||||
|
@ -1,10 +1,31 @@
|
|||||||
part of '../../main.dart';
|
part of '../../main.dart';
|
||||||
|
|
||||||
class UserErrorScreen extends StatelessWidget {
|
class UserErrorActionButton extends StatelessWidget {
|
||||||
|
|
||||||
|
final onPressed;
|
||||||
|
final String text;
|
||||||
|
|
||||||
|
const UserErrorActionButton({Key key, this.onPressed, this.text}) : super(key: key);
|
||||||
|
|
||||||
|
@override
|
||||||
|
Widget build(BuildContext context) {
|
||||||
|
return RaisedButton(
|
||||||
|
onPressed: () => this.onPressed(),
|
||||||
|
color: Colors.blue,
|
||||||
|
child: Text(
|
||||||
|
"${this.text}",
|
||||||
|
style: TextStyle(color: Colors.white),
|
||||||
|
),
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
class UserErrorPanel extends StatelessWidget {
|
||||||
|
|
||||||
final UserError error;
|
final UserError error;
|
||||||
|
|
||||||
const UserErrorScreen({Key key, this.error}) : super(key: key);
|
const UserErrorPanel({Key key, this.error}) : super(key: key);
|
||||||
|
|
||||||
void _goToAppSettings(BuildContext context) {
|
void _goToAppSettings(BuildContext context) {
|
||||||
Navigator.pushNamed(context, '/connection-settings');
|
Navigator.pushNamed(context, '/connection-settings');
|
||||||
@ -32,27 +53,26 @@ class UserErrorScreen extends StatelessWidget {
|
|||||||
switch (this.error.code) {
|
switch (this.error.code) {
|
||||||
case ErrorCode.AUTH_ERROR: {
|
case ErrorCode.AUTH_ERROR: {
|
||||||
errorText = "There was an error logging in to Home Assistant";
|
errorText = "There was an error logging in to Home Assistant";
|
||||||
buttons.add(RaisedButton(
|
buttons.add(UserErrorActionButton(
|
||||||
onPressed: () => _reload(),
|
onPressed: () => _reload(),
|
||||||
child: Text("Retry"),
|
text: "Retry",
|
||||||
));
|
));
|
||||||
buttons.add(RaisedButton(
|
buttons.add(UserErrorActionButton(
|
||||||
onPressed: () => _reLogin(),
|
onPressed: () => _reLogin(),
|
||||||
child: Text("Login again"),
|
text: "Login again",
|
||||||
));
|
));
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
case ErrorCode.UNABLE_TO_CONNECT: {
|
case ErrorCode.UNABLE_TO_CONNECT: {
|
||||||
errorText = "Unable to connect to Home Assistant";
|
errorText = "Unable to connect to Home Assistant";
|
||||||
buttons.addAll(<Widget>[
|
buttons.addAll(<Widget>[
|
||||||
RaisedButton(
|
UserErrorActionButton(
|
||||||
onPressed: () => _reload(),
|
onPressed: () => _reload(),
|
||||||
child: Text("Retry")
|
text: "Retry"
|
||||||
),
|
),
|
||||||
Container(width: 15.0,),
|
UserErrorActionButton(
|
||||||
RaisedButton(
|
|
||||||
onPressed: () => _goToAppSettings(context),
|
onPressed: () => _goToAppSettings(context),
|
||||||
child: Text("Check application settings"),
|
text: "Check application settings",
|
||||||
)
|
)
|
||||||
]
|
]
|
||||||
);
|
);
|
||||||
@ -61,14 +81,13 @@ class UserErrorScreen extends StatelessWidget {
|
|||||||
case ErrorCode.AUTH_INVALID: {
|
case ErrorCode.AUTH_INVALID: {
|
||||||
errorText = "${error.message ?? "Can't login to Home Assistant"}";
|
errorText = "${error.message ?? "Can't login to Home Assistant"}";
|
||||||
buttons.addAll(<Widget>[
|
buttons.addAll(<Widget>[
|
||||||
RaisedButton(
|
UserErrorActionButton(
|
||||||
onPressed: () => _reload(),
|
onPressed: () => _reload(),
|
||||||
child: Text("Retry")
|
text: "Retry"
|
||||||
),
|
),
|
||||||
Container(width: 15.0,),
|
UserErrorActionButton(
|
||||||
RaisedButton(
|
|
||||||
onPressed: () => _reLogin(),
|
onPressed: () => _reLogin(),
|
||||||
child: Text("Login again"),
|
text: "Login again",
|
||||||
)
|
)
|
||||||
]
|
]
|
||||||
);
|
);
|
||||||
@ -77,14 +96,13 @@ class UserErrorScreen extends StatelessWidget {
|
|||||||
case ErrorCode.GENERAL_AUTH_ERROR: {
|
case ErrorCode.GENERAL_AUTH_ERROR: {
|
||||||
errorText = "There was some error logging in. ${this.error.message ?? ""}";
|
errorText = "There was some error logging in. ${this.error.message ?? ""}";
|
||||||
buttons.addAll(<Widget>[
|
buttons.addAll(<Widget>[
|
||||||
RaisedButton(
|
UserErrorActionButton(
|
||||||
onPressed: () => _reload(),
|
onPressed: () => _reload(),
|
||||||
child: Text("Retry")
|
text: "Retry"
|
||||||
),
|
),
|
||||||
Container(width: 15.0,),
|
UserErrorActionButton(
|
||||||
RaisedButton(
|
|
||||||
onPressed: () => _reLogin(),
|
onPressed: () => _reLogin(),
|
||||||
child: Text("Login again"),
|
text: "Login again",
|
||||||
)
|
)
|
||||||
]
|
]
|
||||||
);
|
);
|
||||||
@ -93,14 +111,13 @@ class UserErrorScreen extends StatelessWidget {
|
|||||||
case ErrorCode.SECURE_STORAGE_READ_ERROR: {
|
case ErrorCode.SECURE_STORAGE_READ_ERROR: {
|
||||||
errorText = "There was an error reading secure storage. You can try again or clear saved auth data and login again.";
|
errorText = "There was an error reading secure storage. You can try again or clear saved auth data and login again.";
|
||||||
buttons.addAll(<Widget>[
|
buttons.addAll(<Widget>[
|
||||||
RaisedButton(
|
UserErrorActionButton(
|
||||||
onPressed: () => _reload(),
|
onPressed: () => _reload(),
|
||||||
child: Text("Retry")
|
text: "Retry"
|
||||||
),
|
),
|
||||||
Container(width: 15.0,),
|
UserErrorActionButton(
|
||||||
RaisedButton(
|
|
||||||
onPressed: () => _reLogin(),
|
onPressed: () => _reLogin(),
|
||||||
child: Text("Clear and login again"),
|
text: "Clear and login again",
|
||||||
)
|
)
|
||||||
]
|
]
|
||||||
);
|
);
|
||||||
@ -109,14 +126,13 @@ class UserErrorScreen extends StatelessWidget {
|
|||||||
case ErrorCode.DISCONNECTED: {
|
case ErrorCode.DISCONNECTED: {
|
||||||
errorText = "Disconnected";
|
errorText = "Disconnected";
|
||||||
buttons.addAll(<Widget>[
|
buttons.addAll(<Widget>[
|
||||||
RaisedButton(
|
UserErrorActionButton(
|
||||||
onPressed: () => _reload(),
|
onPressed: () => _reload(),
|
||||||
child: Text("Reconnect")
|
text: "Reconnect"
|
||||||
),
|
),
|
||||||
Container(width: 15.0,),
|
UserErrorActionButton(
|
||||||
RaisedButton(
|
|
||||||
onPressed: () => _goToAppSettings(context),
|
onPressed: () => _goToAppSettings(context),
|
||||||
child: Text("Check application settings"),
|
text: "Check application settings",
|
||||||
)
|
)
|
||||||
]
|
]
|
||||||
);
|
);
|
||||||
@ -125,14 +141,13 @@ class UserErrorScreen extends StatelessWidget {
|
|||||||
case ErrorCode.CONNECTION_TIMEOUT: {
|
case ErrorCode.CONNECTION_TIMEOUT: {
|
||||||
errorText = "Connection timeout";
|
errorText = "Connection timeout";
|
||||||
buttons.addAll(<Widget>[
|
buttons.addAll(<Widget>[
|
||||||
RaisedButton(
|
UserErrorActionButton(
|
||||||
onPressed: () => _reload(),
|
onPressed: () => _reload(),
|
||||||
child: Text("Reconnect")
|
text: "Reconnect"
|
||||||
),
|
),
|
||||||
Container(width: 15.0,),
|
UserErrorActionButton(
|
||||||
RaisedButton(
|
|
||||||
onPressed: () => _goToAppSettings(context),
|
onPressed: () => _goToAppSettings(context),
|
||||||
child: Text("Check application settings"),
|
text: "Check application settings",
|
||||||
)
|
)
|
||||||
]
|
]
|
||||||
);
|
);
|
||||||
@ -140,9 +155,9 @@ class UserErrorScreen extends StatelessWidget {
|
|||||||
}
|
}
|
||||||
case ErrorCode.NOT_CONFIGURED: {
|
case ErrorCode.NOT_CONFIGURED: {
|
||||||
errorText = "Looks like HA Client is not configured yet.";
|
errorText = "Looks like HA Client is not configured yet.";
|
||||||
buttons.add(RaisedButton(
|
buttons.add(UserErrorActionButton(
|
||||||
onPressed: () => _goToAppSettings(context),
|
onPressed: () => _goToAppSettings(context),
|
||||||
child: Text("Open application settings"),
|
text: "Open application settings",
|
||||||
));
|
));
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
@ -150,90 +165,78 @@ class UserErrorScreen extends StatelessWidget {
|
|||||||
case ErrorCode.ERROR_GETTING_CONFIG:
|
case ErrorCode.ERROR_GETTING_CONFIG:
|
||||||
case ErrorCode.ERROR_GETTING_STATES: {
|
case ErrorCode.ERROR_GETTING_STATES: {
|
||||||
errorText = "Couldn't get data from Home Assistant. ${error.message ?? ""}";
|
errorText = "Couldn't get data from Home Assistant. ${error.message ?? ""}";
|
||||||
buttons.add(RaisedButton(
|
buttons.add(UserErrorActionButton(
|
||||||
onPressed: () => _reload(),
|
onPressed: () => _reload(),
|
||||||
child: Text("Try again"),
|
text: "Try again",
|
||||||
));
|
));
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
case ErrorCode.ERROR_GETTING_LOVELACE_CONFIG: {
|
case ErrorCode.ERROR_GETTING_LOVELACE_CONFIG: {
|
||||||
errorText = "Couldn't get Lovelace UI config. You can try to disable it and use group-based UI istead.";
|
errorText = "Couldn't get Lovelace UI config. You can try to disable it and use group-based UI istead.";
|
||||||
buttons.addAll(<Widget>[
|
buttons.addAll(<Widget>[
|
||||||
RaisedButton(
|
UserErrorActionButton(
|
||||||
onPressed: () => _reload(),
|
onPressed: () => _reload(),
|
||||||
child: Text("Retry"),
|
text: "Retry",
|
||||||
),
|
),
|
||||||
Container(width: 15.0,),
|
UserErrorActionButton(
|
||||||
RaisedButton(
|
|
||||||
onPressed: () => _disableLovelace(),
|
onPressed: () => _disableLovelace(),
|
||||||
child: Text("Disable Lovelace UI"),
|
text: "Disable Lovelace UI",
|
||||||
)
|
)
|
||||||
]);
|
]);
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
case ErrorCode.NOT_LOGGED_IN: {
|
case ErrorCode.NOT_LOGGED_IN: {
|
||||||
errorText = "You are not logged in yet. Please login.";
|
errorText = "You are not logged in yet. Please login.";
|
||||||
buttons.add(RaisedButton(
|
buttons.add(UserErrorActionButton(
|
||||||
onPressed: () => _reload(),
|
onPressed: () => _reload(),
|
||||||
child: Text("Login"),
|
text: "Login",
|
||||||
));
|
));
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
case ErrorCode.NO_MOBILE_APP_COMPONENT: {
|
case ErrorCode.NO_MOBILE_APP_COMPONENT: {
|
||||||
errorText = "Looks like mobile_app component is not enabled on your Home Assistant instance. Please add it to your configuration.yaml";
|
errorText = "Looks like mobile_app component is not enabled on your Home Assistant instance. Please add it to your configuration.yaml";
|
||||||
buttons.add(RaisedButton(
|
buttons.add(UserErrorActionButton(
|
||||||
onPressed: () => Launcher.launchURLInCustomTab(context: context, url: "https://www.home-assistant.io/components/mobile_app/"),
|
onPressed: () => Launcher.launchURLInCustomTab(context: context, url: "https://www.home-assistant.io/components/mobile_app/"),
|
||||||
child: Text("Help"),
|
text: "Help",
|
||||||
));
|
));
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
default: {
|
default: {
|
||||||
errorText = "There was an error. Code ${this.error.code}";
|
errorText = "There was an error. Code ${this.error.code}";
|
||||||
buttons.add(RaisedButton(
|
buttons.add(UserErrorActionButton(
|
||||||
onPressed: () => _reload(),
|
onPressed: () => _reload(),
|
||||||
child: Text("Reload"),
|
text: "Reload",
|
||||||
));
|
));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
return Column(
|
||||||
return Padding(
|
mainAxisSize: MainAxisSize.min,
|
||||||
padding: EdgeInsets.only(left: Sizes.leftWidgetPadding, right: Sizes.rightWidgetPadding),
|
children: <Widget>[
|
||||||
child: Row(
|
Divider(
|
||||||
mainAxisSize: MainAxisSize.min,
|
color: Colors.deepOrange,
|
||||||
crossAxisAlignment: CrossAxisAlignment.center,
|
height: 1.0,
|
||||||
mainAxisAlignment: MainAxisAlignment.center,
|
indent: 8.0,
|
||||||
children: <Widget>[
|
endIndent: 8.0,
|
||||||
Flexible(
|
),
|
||||||
child: Column(
|
Padding(
|
||||||
mainAxisSize: MainAxisSize.max,
|
padding: EdgeInsets.fromLTRB(8.0, 14.0, 8.0, 0.0),
|
||||||
mainAxisAlignment: MainAxisAlignment.start,
|
child: Row(
|
||||||
children: <Widget>[
|
mainAxisSize: MainAxisSize.max,
|
||||||
Padding(
|
children: <Widget>[
|
||||||
padding: EdgeInsets.only(top: 100.0, bottom: 20.0),
|
Text(
|
||||||
child: Icon(
|
errorText,
|
||||||
Icons.error,
|
textAlign: TextAlign.start,
|
||||||
color: Colors.redAccent,
|
style: TextStyle(color: Colors.black87, fontSize: 18.0),
|
||||||
size: 48.0
|
softWrap: true,
|
||||||
)
|
maxLines: 3,
|
||||||
),
|
)
|
||||||
Text(
|
],
|
||||||
errorText,
|
),
|
||||||
textAlign: TextAlign.center,
|
),
|
||||||
style: TextStyle(color: Colors.black45, fontSize: Sizes.largeFontSize),
|
ButtonBar(
|
||||||
softWrap: true,
|
children: buttons,
|
||||||
maxLines: 5,
|
)
|
||||||
),
|
],
|
||||||
Container(height: Sizes.rowPadding,),
|
|
||||||
Row(
|
|
||||||
mainAxisSize: MainAxisSize.max,
|
|
||||||
mainAxisAlignment: MainAxisAlignment.center,
|
|
||||||
children: buttons.isNotEmpty ? buttons : Container(height: 0.0, width: 0.0,),
|
|
||||||
)
|
|
||||||
],
|
|
||||||
),
|
|
||||||
)
|
|
||||||
],
|
|
||||||
),
|
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
}
|
}
|
Reference in New Issue
Block a user