From eb7922a9a08376b872794f3f98482e091120aef1 Mon Sep 17 00:00:00 2001 From: Simon Date: Thu, 14 May 2020 09:54:12 +0200 Subject: [PATCH] Iconselect for door / window contact --- lib/Componts/SmarthomeCard.dart | 28 ++++++-- lib/Models/favoriteModel.dart | 16 ++++- lib/Pages/allAdapterPage.dart | 113 +++++++++++++++++++++--------- lib/Pages/start.dart | 1 + lib/Services/favoriteService.dart | 16 +++-- 5 files changed, 128 insertions(+), 46 deletions(-) diff --git a/lib/Componts/SmarthomeCard.dart b/lib/Componts/SmarthomeCard.dart index c327d1a..b3e6fe9 100644 --- a/lib/Componts/SmarthomeCard.dart +++ b/lib/Componts/SmarthomeCard.dart @@ -18,6 +18,7 @@ class SmarthomeCard extends StatefulWidget { final double setPointMax; final IO.Socket socket; final bool secured; + final int icon; SmarthomeCard({ this.id, @@ -31,6 +32,7 @@ class SmarthomeCard extends StatefulWidget { this.setPointMax, this.socket, this.secured, + this.icon, }); SocketService socketSrv; @@ -382,6 +384,12 @@ class _SmarthomeCardState extends State { } Widget _getContactCard(String _switchValue) { + IconData customIconData; + if (widget.icon != null) { + customIconData = IconData(widget.icon, + fontFamily: 'MaterialIcons', matchTextDirection: false); + } + return Card( color: BolioColors.surfaceCard, child: Column( @@ -389,11 +397,21 @@ class _SmarthomeCardState extends State { children: [ Padding( padding: const EdgeInsets.all(8.0), - child: Icon( - _switchValue == 'true' ? Icons.lock_open : Icons.lock, - color: Colors.grey, - size: 44.0, - ), + child: widget.icon == null + ? Icon( + _switchValue == 'true' ? Icons.lock_open : Icons.lock, + color: _switchValue == 'true' + ? Colors.white + : Colors.grey[600], + size: 44.0, + ) + : Icon( + customIconData, + color: _switchValue == 'true' + ? Colors.white + : Colors.grey[600], + size: 44.0, + ), ), Flexible( child: Text( diff --git a/lib/Models/favoriteModel.dart b/lib/Models/favoriteModel.dart index ab5e77c..a7b0387 100644 --- a/lib/Models/favoriteModel.dart +++ b/lib/Models/favoriteModel.dart @@ -9,6 +9,7 @@ class FavoriteModel { double setPointMin; double setPointMax; String pageId; + int icon; bool secured; FavoriteModel( @@ -22,7 +23,8 @@ class FavoriteModel { this.setPointMin, this.setPointMax, this.pageId, - this.secured}); + this.secured, + this.icon}); factory FavoriteModel.fromJson(Map json) { return FavoriteModel( @@ -39,6 +41,7 @@ class FavoriteModel { json['setPointMax'] != null ? json['setPointMax'].toDouble() : null, pageId: json['pageId'] != null ? json['pageId'] : null, secured: json['secured'] != null ? json['secured'] : false, + icon: json['icon'] != null ? json['icon'] : null, ); } @@ -53,7 +56,8 @@ class FavoriteModel { 'setPointMin': setPointMin, 'setPointMax': setPointMax, 'pageId': pageId, - 'secured': secured + 'secured': secured, + 'icon': icon, }; setSecured(bool secured) { @@ -95,4 +99,12 @@ class FavoriteModel { this.setPointMax = null; } } + + setIcon(String icon) { + if (icon != null && icon != '') { + this.icon = int.parse(icon); + } else { + this.icon = null; + } + } } diff --git a/lib/Pages/allAdapterPage.dart b/lib/Pages/allAdapterPage.dart index de711ff..7f843c6 100644 --- a/lib/Pages/allAdapterPage.dart +++ b/lib/Pages/allAdapterPage.dart @@ -40,7 +40,8 @@ class _AllAdapterPageState extends State ]; TabController _tabController; - Icon _selectedIcon; + Icon _selectedPageIcon; + Icon _selectedFavoriteIcon; List _adapters; IconButtonService _iconButtonSrv = new IconButtonService(); bool _selectingFavorites = false; @@ -295,7 +296,6 @@ class _AllAdapterPageState extends State Widget _getFavoriteList(List objects, context) { return ReorderableListView( onReorder: (int oldIndexCurrentList, int newIndexCurrentList) { - int oldIndexCompleteList = 0; int newIndexCompleteList = 0; @@ -428,6 +428,12 @@ class _AllAdapterPageState extends State String _isSelectedDropdownPage = object.pageId; bool _isSecured = object.secured; + if (object.icon != null) { + IconData _iconData = IconData(object.icon, + fontFamily: 'MaterialIcons', matchTextDirection: false); + _selectedFavoriteIcon = Icon(_iconData); + } + return StatefulBuilder( builder: (context, setState) { return AlertDialog( @@ -661,6 +667,37 @@ class _AllAdapterPageState extends State ), ), ), + Visibility( + visible: + _isSelectedDropdownObjectType == 'Tür/Fensterkontakt', + child: Padding( + padding: const EdgeInsets.only(top: 8.0), + child: Row( + mainAxisAlignment: MainAxisAlignment.spaceBetween, + children: [ + RaisedButton( + color: BolioColors.surfaceCard, + onPressed: () async { + IconData icon = + await FlutterIconPicker.showIconPicker( + context, + iconPackMode: IconPack.material); + + if (icon != null) { + setState(() { + _selectedFavoriteIcon = Icon(icon); + }); + } + }, + child: Text('Anderes Icon verwenden'), + ), + _selectedFavoriteIcon != null + ? Icon(_selectedFavoriteIcon.icon, size: 35) + : Container(), + ], + ), + ), + ), ], ), ), @@ -690,6 +727,13 @@ class _AllAdapterPageState extends State } else if (_isSelected[2]) { tileSize = 'L'; } + + String _icon; + _selectedFavoriteIcon == null + ? _icon = '' + : _icon = + _selectedFavoriteIcon.icon.codePoint.toString(); + favoriteService.updateFavorite( object.id, nameController.text, @@ -700,6 +744,7 @@ class _AllAdapterPageState extends State setpointMaxController.text, _isSelectedDropdownPage, _isSecured, + _icon, context, ); }, @@ -915,7 +960,7 @@ class _AllAdapterPageState extends State pageTitleController.text = page.title; var _iconData = IconData(page.icon, fontFamily: 'MaterialIcons', matchTextDirection: false); - _selectedIcon = Icon(_iconData); + _selectedPageIcon = Icon(_iconData); await showDialog( context: context, barrierDismissible: false, // user must tap button! @@ -934,10 +979,10 @@ class _AllAdapterPageState extends State controller: pageTitleController, decoration: InputDecoration(labelText: 'Seitenname'), ), - _selectedIcon != null + _selectedPageIcon != null ? Padding( padding: const EdgeInsets.only(top: 18.0), - child: Icon(_selectedIcon.icon, size: 35), + child: Icon(_selectedPageIcon.icon, size: 35), ) : Container(), Padding( @@ -949,7 +994,7 @@ class _AllAdapterPageState extends State _context, iconPackMode: IconPack.material); setState(() { - _selectedIcon = Icon(icon); + _selectedPageIcon = Icon(icon); }); }, child: Text('Icon wählen'), @@ -962,7 +1007,7 @@ class _AllAdapterPageState extends State FlatButton( child: Text('Abbrechen'), onPressed: () { - _selectedIcon = null; + _selectedPageIcon = null; Navigator.of(_context).pop(); }, ), @@ -971,13 +1016,13 @@ class _AllAdapterPageState extends State color: BolioColors.primary, onPressed: () { int _codePoint; - _selectedIcon == null + _selectedPageIcon == null ? _codePoint = 0 - : _codePoint = _selectedIcon.icon.codePoint; + : _codePoint = _selectedPageIcon.icon.codePoint; page.setTite(pageTitleController.text); page.setIcon(_codePoint); - _selectedIcon = null; + _selectedPageIcon = null; Navigator.of(_context).pop(); }, ) @@ -1020,27 +1065,29 @@ class _AllAdapterPageState extends State controller: pageTitleController, decoration: InputDecoration(labelText: 'Seitenname'), ), - _selectedIcon != null - ? Padding( - padding: const EdgeInsets.only(top: 18.0), - child: Icon(_selectedIcon.icon, size: 35), - ) - : Container(), Padding( - padding: const EdgeInsets.all(8.0), - child: RaisedButton( - color: BolioColors.surfaceCard, - onPressed: () async { - IconData icon = await FlutterIconPicker.showIconPicker( - _context, - iconPackMode: IconPack.material); + padding: const EdgeInsets.only(top: 8.0), + child: Row( + mainAxisAlignment: MainAxisAlignment.spaceBetween, + children: [ + RaisedButton( + color: BolioColors.surfaceCard, + onPressed: () async { + IconData icon = + await FlutterIconPicker.showIconPicker(_context, + iconPackMode: IconPack.material); - if (icon == icon) {} - setState(() { - _selectedIcon = Icon(icon); - }); - }, - child: Text('Icon wählen'), + if (icon == icon) {} + setState(() { + _selectedPageIcon = Icon(icon); + }); + }, + child: Text('Icon wählen'), + ), + _selectedPageIcon != null + ? Icon(_selectedPageIcon.icon, size: 35) + : Container(), + ], ), ), ], @@ -1050,7 +1097,7 @@ class _AllAdapterPageState extends State FlatButton( child: Text('Abbrechen'), onPressed: () { - _selectedIcon = null; + _selectedPageIcon = null; Navigator.of(_context).pop(); }, ), @@ -1060,9 +1107,9 @@ class _AllAdapterPageState extends State onPressed: () { setState(() { int _codePoint; - _selectedIcon == null + _selectedPageIcon == null ? _codePoint = 0 - : _codePoint = _selectedIcon.icon.codePoint; + : _codePoint = _selectedPageIcon.icon.codePoint; PageModel page = new PageModel( id: new DateTime.now() @@ -1072,7 +1119,7 @@ class _AllAdapterPageState extends State icon: _codePoint); _pageToAdd = page; }); - _selectedIcon = null; + _selectedPageIcon = null; Navigator.of(_context).pop(); }, ) diff --git a/lib/Pages/start.dart b/lib/Pages/start.dart index 4e969d4..b149c65 100644 --- a/lib/Pages/start.dart +++ b/lib/Pages/start.dart @@ -145,6 +145,7 @@ class _StartPageState extends State { setPointMax: favorites[index].setPointMax, socket: socket, secured: favorites[index].secured, + icon: favorites[index].icon, ), ), staggeredTileBuilder: (int index) { diff --git a/lib/Services/favoriteService.dart b/lib/Services/favoriteService.dart index a32e2c6..2e938df 100644 --- a/lib/Services/favoriteService.dart +++ b/lib/Services/favoriteService.dart @@ -17,12 +17,13 @@ class FavoriteService { } FavoriteModel favorite = new FavoriteModel( - id: object.id, - title: object.name, - tileSize: 'S', - objectType: objectType, - sliderMin: object.sliderMin, - sliderMax: object.sliderMax); + id: object.id, + title: object.name, + tileSize: 'S', + objectType: objectType, + sliderMin: object.sliderMin, + sliderMax: object.sliderMax, + ); favorites.add(favorite); var prefs = await SharedPreferences.getInstance(); prefs.setString('favorites', jsonEncode(_encodeFavorites(favorites))); @@ -141,6 +142,7 @@ class FavoriteService { : null, null, favorite.secured, + favorite.icon != null ? favorite.icon.toString() : null, context) } } @@ -181,6 +183,7 @@ class FavoriteService { String setPointMax, String pageId, bool secured, + String icon, context, ) async { if (timeSpan == null) { @@ -197,6 +200,7 @@ class FavoriteService { favorite.setSetPointMax(setPointMax); favorite.setPageId(pageId); favorite.setSecured(secured); + favorite.setIcon(icon); } } var prefs = await SharedPreferences.getInstance();