Skip to content

Commit

Permalink
Iconselect for door / window contact
Browse files Browse the repository at this point in the history
  • Loading branch information
SiBolio committed May 14, 2020
1 parent 3f1e685 commit eb7922a
Show file tree
Hide file tree
Showing 5 changed files with 128 additions and 46 deletions.
28 changes: 23 additions & 5 deletions lib/Componts/SmarthomeCard.dart
Expand Up @@ -18,6 +18,7 @@ class SmarthomeCard extends StatefulWidget {
final double setPointMax;
final IO.Socket socket;
final bool secured;
final int icon;

SmarthomeCard({
this.id,
Expand All @@ -31,6 +32,7 @@ class SmarthomeCard extends StatefulWidget {
this.setPointMax,
this.socket,
this.secured,
this.icon,
});

SocketService socketSrv;
Expand Down Expand Up @@ -382,18 +384,34 @@ class _SmarthomeCardState extends State<SmarthomeCard> {
}

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(
crossAxisAlignment: CrossAxisAlignment.center,
children: <Widget>[
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(
Expand Down
16 changes: 14 additions & 2 deletions lib/Models/favoriteModel.dart
Expand Up @@ -9,6 +9,7 @@ class FavoriteModel {
double setPointMin;
double setPointMax;
String pageId;
int icon;
bool secured;

FavoriteModel(
Expand All @@ -22,7 +23,8 @@ class FavoriteModel {
this.setPointMin,
this.setPointMax,
this.pageId,
this.secured});
this.secured,
this.icon});

factory FavoriteModel.fromJson(Map<String, dynamic> json) {
return FavoriteModel(
Expand All @@ -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,
);
}

Expand All @@ -53,7 +56,8 @@ class FavoriteModel {
'setPointMin': setPointMin,
'setPointMax': setPointMax,
'pageId': pageId,
'secured': secured
'secured': secured,
'icon': icon,
};

setSecured(bool secured) {
Expand Down Expand Up @@ -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;
}
}
}
113 changes: 80 additions & 33 deletions lib/Pages/allAdapterPage.dart
Expand Up @@ -40,7 +40,8 @@ class _AllAdapterPageState extends State<AllAdapterPage>
];

TabController _tabController;
Icon _selectedIcon;
Icon _selectedPageIcon;
Icon _selectedFavoriteIcon;
List<AdapterModel> _adapters;
IconButtonService _iconButtonSrv = new IconButtonService();
bool _selectingFavorites = false;
Expand Down Expand Up @@ -295,7 +296,6 @@ class _AllAdapterPageState extends State<AllAdapterPage>
Widget _getFavoriteList(List<FavoriteModel> objects, context) {
return ReorderableListView(
onReorder: (int oldIndexCurrentList, int newIndexCurrentList) {

int oldIndexCompleteList = 0;
int newIndexCompleteList = 0;

Expand Down Expand Up @@ -428,6 +428,12 @@ class _AllAdapterPageState extends State<AllAdapterPage>
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(
Expand Down Expand Up @@ -661,6 +667,37 @@ class _AllAdapterPageState extends State<AllAdapterPage>
),
),
),
Visibility(
visible:
_isSelectedDropdownObjectType == 'Tür/Fensterkontakt',
child: Padding(
padding: const EdgeInsets.only(top: 8.0),
child: Row(
mainAxisAlignment: MainAxisAlignment.spaceBetween,
children: <Widget>[
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(),
],
),
),
),
],
),
),
Expand Down Expand Up @@ -690,6 +727,13 @@ class _AllAdapterPageState extends State<AllAdapterPage>
} else if (_isSelected[2]) {
tileSize = 'L';
}

String _icon;
_selectedFavoriteIcon == null
? _icon = ''
: _icon =
_selectedFavoriteIcon.icon.codePoint.toString();

favoriteService.updateFavorite(
object.id,
nameController.text,
Expand All @@ -700,6 +744,7 @@ class _AllAdapterPageState extends State<AllAdapterPage>
setpointMaxController.text,
_isSelectedDropdownPage,
_isSecured,
_icon,
context,
);
},
Expand Down Expand Up @@ -915,7 +960,7 @@ class _AllAdapterPageState extends State<AllAdapterPage>
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!
Expand All @@ -934,10 +979,10 @@ class _AllAdapterPageState extends State<AllAdapterPage>
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(
Expand All @@ -949,7 +994,7 @@ class _AllAdapterPageState extends State<AllAdapterPage>
_context,
iconPackMode: IconPack.material);
setState(() {
_selectedIcon = Icon(icon);
_selectedPageIcon = Icon(icon);
});
},
child: Text('Icon wählen'),
Expand All @@ -962,7 +1007,7 @@ class _AllAdapterPageState extends State<AllAdapterPage>
FlatButton(
child: Text('Abbrechen'),
onPressed: () {
_selectedIcon = null;
_selectedPageIcon = null;
Navigator.of(_context).pop();
},
),
Expand All @@ -971,13 +1016,13 @@ class _AllAdapterPageState extends State<AllAdapterPage>
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();
},
)
Expand Down Expand Up @@ -1020,27 +1065,29 @@ class _AllAdapterPageState extends State<AllAdapterPage>
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: <Widget>[
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(),
],
),
),
],
Expand All @@ -1050,7 +1097,7 @@ class _AllAdapterPageState extends State<AllAdapterPage>
FlatButton(
child: Text('Abbrechen'),
onPressed: () {
_selectedIcon = null;
_selectedPageIcon = null;
Navigator.of(_context).pop();
},
),
Expand All @@ -1060,9 +1107,9 @@ class _AllAdapterPageState extends State<AllAdapterPage>
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()
Expand All @@ -1072,7 +1119,7 @@ class _AllAdapterPageState extends State<AllAdapterPage>
icon: _codePoint);
_pageToAdd = page;
});
_selectedIcon = null;
_selectedPageIcon = null;
Navigator.of(_context).pop();
},
)
Expand Down
1 change: 1 addition & 0 deletions lib/Pages/start.dart
Expand Up @@ -145,6 +145,7 @@ class _StartPageState extends State<StartPage> {
setPointMax: favorites[index].setPointMax,
socket: socket,
secured: favorites[index].secured,
icon: favorites[index].icon,
),
),
staggeredTileBuilder: (int index) {
Expand Down
16 changes: 10 additions & 6 deletions lib/Services/favoriteService.dart
Expand Up @@ -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)));
Expand Down Expand Up @@ -141,6 +142,7 @@ class FavoriteService {
: null,
null,
favorite.secured,
favorite.icon != null ? favorite.icon.toString() : null,
context)
}
}
Expand Down Expand Up @@ -181,6 +183,7 @@ class FavoriteService {
String setPointMax,
String pageId,
bool secured,
String icon,
context,
) async {
if (timeSpan == null) {
Expand All @@ -197,6 +200,7 @@ class FavoriteService {
favorite.setSetPointMax(setPointMax);
favorite.setPageId(pageId);
favorite.setSecured(secured);
favorite.setIcon(icon);
}
}
var prefs = await SharedPreferences.getInstance();
Expand Down

0 comments on commit eb7922a

Please sign in to comment.