2019-03-13 16:39:23 +02:00
part of ' ../main.dart ' ;
2019-02-16 22:04:49 +02:00
2019-03-13 16:39:23 +02:00
class ConfigPanelWidget extends StatefulWidget {
ConfigPanelWidget ( { Key key } ) : super ( key: key ) ;
2019-02-16 22:04:49 +02:00
@ override
2019-03-13 16:39:23 +02:00
_ConfigPanelWidgetState createState ( ) = > new _ConfigPanelWidgetState ( ) ;
2019-02-16 22:04:49 +02:00
}
class ConfigurationItem {
ConfigurationItem ( { this . isExpanded: false , this . header , this . body } ) ;
bool isExpanded ;
final String header ;
final Widget body ;
}
2019-03-13 16:39:23 +02:00
class _ConfigPanelWidgetState extends State < ConfigPanelWidget > {
2019-02-16 22:04:49 +02:00
List < ConfigurationItem > _items ;
@ override
void initState ( ) {
super . initState ( ) ;
_items = < ConfigurationItem > [
ConfigurationItem (
header: ' General ' ,
body: Padding (
padding: EdgeInsets . fromLTRB ( Sizes . leftWidgetPadding , 0.0 , Sizes . rightWidgetPadding , Sizes . rowPadding ) ,
child: Column (
crossAxisAlignment: CrossAxisAlignment . start ,
mainAxisSize: MainAxisSize . min ,
children: < Widget > [
Text ( " Server management " , style: TextStyle ( fontSize: Sizes . largeFontSize ) ) ,
Container ( height: Sizes . rowPadding , ) ,
Text ( " Control your Home Assistant server from HA Client. " ) ,
Divider ( ) ,
Row (
mainAxisSize: MainAxisSize . min ,
children: < Widget > [
FlatServiceButton (
text: " Restart " ,
serviceName: " restart " ,
serviceDomain: " homeassistant " ,
entityId: null ,
) ,
FlatServiceButton (
text: " Stop " ,
serviceName: " stop " ,
serviceDomain: " homeassistant " ,
entityId: null ,
) ,
] ,
)
] ,
) ,
)
2019-06-15 18:07:11 +03:00
) ,
ConfigurationItem (
header: ' Mobile app ' ,
body: Padding (
padding: EdgeInsets . fromLTRB ( Sizes . leftWidgetPadding , 0.0 , Sizes . rightWidgetPadding , Sizes . rowPadding ) ,
child: Column (
crossAxisAlignment: CrossAxisAlignment . start ,
mainAxisSize: MainAxisSize . min ,
children: < Widget > [
Text ( " Registration " , style: TextStyle ( fontSize: Sizes . largeFontSize ) ) ,
Container ( height: Sizes . rowPadding , ) ,
Text ( " ${ HomeAssistant ( ) . userName } 's ${ Device ( ) . model } , ${ Device ( ) . osName } ${ Device ( ) . osVersion } " ) ,
Container ( height: 6.0 , ) ,
Text ( " Reseting mobile app registration will not remove integration from Home Assistant but creates a new one with different device. If you want to reset mobile app registration completally you need to remove MobileApp from Configuretion -> Integrations of your Home Assistant. " ) ,
Divider ( ) ,
Row (
mainAxisSize: MainAxisSize . min ,
children: < Widget > [
FlatButton (
onPressed: ( ) = > resetRegistration ( ) ,
child: Text ( " Reset registration " )
) ,
FlatButton (
onPressed: ( ) = > updateRegistration ( ) ,
child: Text ( " Update registration " )
)
] ,
)
] ,
) ,
)
2019-02-16 22:04:49 +02:00
)
] ;
}
2019-06-15 18:07:11 +03:00
resetRegistration ( ) {
HomeAssistant ( ) . checkAppRegistration ( forceRegister: true ) . then ( ( _ ) = > Navigator . of ( context ) . pop ( ) ) ;
}
updateRegistration ( ) {
HomeAssistant ( ) . checkAppRegistration ( forceUpdate: true ) . then ( ( _ ) = > Navigator . of ( context ) . pop ( ) ) ;
}
2019-02-16 22:04:49 +02:00
@ override
Widget build ( BuildContext context ) {
2019-03-13 16:39:23 +02:00
return ListView (
children: [
new ExpansionPanelList (
expansionCallback: ( int index , bool isExpanded ) {
setState ( ( ) {
_items [ index ] . isExpanded = ! _items [ index ] . isExpanded ;
} ) ;
} ,
children: _items . map ( ( ConfigurationItem item ) {
return new ExpansionPanel (
headerBuilder: ( BuildContext context , bool isExpanded ) {
return CardHeaderWidget (
name: item . header ,
) ;
} ,
isExpanded: item . isExpanded ,
body: new Container (
child: item . body ,
) ,
) ;
} ) . toList ( ) ,
) ,
] ,
2019-02-16 22:04:49 +02:00
) ;
}
@ override
void dispose ( ) {
super . dispose ( ) ;
}
}