Created
August 15, 2019 23:46
-
-
Save VB10/e22d43d6e86eb4c267972010035f7014 to your computer and use it in GitHub Desktop.
Healtho Settings View
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| int _selectedLangIndex = 0; | |
| int _tempSelectedIndex = 0; | |
| bool _notification = false; | |
| @override | |
| Widget build(BuildContext context) { | |
| return SafeArea( | |
| child: Scaffold( | |
| backgroundColor: Colors.white, | |
| body: ListView( | |
| children: <Widget>[ | |
| UIHelper.verticalSpace, | |
| _settingsProfileCard(), | |
| _settingsLangOptionsCard( | |
| icon: Icons.language, title: Constants.LANGUAGE_OPTIONS), | |
| _settingsNormalCard( | |
| icon: Icons.healing, title: Constants.HEALTH_DATA), | |
| _settingsNotificationsCard( | |
| icon: Icons.notifications, title: Constants.NOTIFICATIONS), | |
| _settingsNormalCard( | |
| icon: Icons.share, title: Constants.REFER_FRIEND), | |
| _settingsNormalCard( | |
| icon: Icons.rate_review, title: Constants.FEEDBACK), | |
| _settingsNormalCard(icon: Icons.star, title: Constants.RATE_US), | |
| _settingsNormalCard( | |
| icon: Icons.exit_to_app, title: Constants.LOG_OUT), | |
| ], | |
| ), | |
| ), | |
| ); | |
| } | |
| Widget get _rigtActionItem => Chip( | |
| label: Icon(Icons.search), | |
| backgroundColor: UIHelper.SETTINGS_APP_BAR_COLOR, | |
| shape: Border(), | |
| ); | |
| Widget get _profileIcon => CircleAvatar( | |
| backgroundImage: NetworkImage(Constants.PROFILE_IMAGE), | |
| ); | |
| Widget _settingsProfileCard() { | |
| return Card( | |
| elevation: UIHelper.Space5, | |
| color: UIHelper.SETTINGS_CARD_BACKGROUND_COLOR, | |
| shape: RoundedRectangleBorder( | |
| borderRadius: BorderRadius.circular(UIHelper.Space10)), | |
| child: ListTile( | |
| title: Text("Profile"), | |
| leading: _profileIcon, | |
| onTap: () => Navigator.of(context).pushNamed("/profile"), | |
| ), | |
| ); | |
| } | |
| Widget _settingsNormalCard({String title, IconData icon}) => | |
| SettingsCardWidget( | |
| title: title, | |
| icon: icon, | |
| ); | |
| Widget _settingsNotificationsCard({String title, IconData icon}) => | |
| SettingsCardWidget( | |
| title: title, | |
| icon: icon, | |
| trailing: FlatButton( | |
| child: Text(_notification ? "On" : "Off"), | |
| onPressed: () { | |
| setState(() { | |
| _notification = !_notification; | |
| }); | |
| }, | |
| ), | |
| ); | |
| Widget _settingsLangOptionsCard({String title, IconData icon}) => | |
| SettingsCardWidget( | |
| title: title, | |
| icon: icon, | |
| trailing: FlatButton( | |
| child: Text(Constants.LANGUAGES[_selectedLangIndex]), | |
| onPressed: () async { | |
| await showCupertinoModalPopup<void>( | |
| context: context, | |
| builder: (BuildContext context) { | |
| return _buildBottomPicker( | |
| CupertinoPicker( | |
| itemExtent: 50, | |
| backgroundColor: CupertinoColors.white, | |
| onSelectedItemChanged: (int index) { | |
| _tempSelectedIndex = index; | |
| }, | |
| children: List<Widget>.generate(Constants.LANGUAGES.length, | |
| (int index) { | |
| return Center( | |
| child: Text(Constants.LANGUAGES[index]), | |
| ); | |
| }), | |
| ), | |
| ); | |
| }, | |
| ); | |
| }, | |
| ), | |
| ); | |
| // | |
| Widget _buildBottomPicker(Widget picker) { | |
| return Container( | |
| height: UIHelper.dynamicHeight(UIHelper.Space500), | |
| color: CupertinoColors.white, | |
| child: SafeArea( | |
| top: false, | |
| child: Column( | |
| children: <Widget>[ | |
| Expanded(child: picker), | |
| FlatButton.icon( | |
| icon: Icon(Icons.check), | |
| label: Text("Save"), | |
| onPressed: () { | |
| /// Check changes [_tempSelectedIndex] & [_selectedLangIndex] | |
| if (_tempSelectedIndex != _selectedLangIndex) { | |
| setState(() { | |
| _selectedLangIndex = _tempSelectedIndex; | |
| }); | |
| } | |
| }, | |
| ), | |
| ], | |
| ), | |
| ), | |
| ); | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment