Created
August 31, 2021 18:11
-
-
Save p4yam/ef2322064c7ab005de240d9ed4323e55 to your computer and use it in GitHub Desktop.
This file contains 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
class _MainPagerState extends State<MainPager> | |
with AutomaticKeepAliveClientMixin { | |
int _selectedIndex = 0; | |
Icon _foods = Icon(MdiIcons.foodApple); | |
Icon _favorite = Icon(Icons.favorite_border); | |
Icon _shoppingList = Icon(Icons.playlist_add); | |
bool _darkMode = true; | |
PageController _pagerController = | |
PageController(initialPage: 0, keepPage: false); | |
final _rateMyApp = RateMyApp( | |
preferencesPrefix: 'rateMyApp_', | |
minDays: 0, | |
minLaunches: 5, | |
remindDays: 5, | |
remindLaunches: 5, | |
); | |
@override | |
void initState() { | |
super.initState(); | |
_fetchPrefs(); | |
_showRateDialog(); | |
} | |
_showRateDialog() { | |
_rateMyApp.init().then((_) => { | |
if (_rateMyApp.shouldOpenDialog) | |
_rateMyApp.showRateDialog(context, | |
title: 'امتیاز دهید', | |
message: | |
'در صورتی که از زیتون راضی بودید لطفا به ما امتیاز دهید.', | |
rateButton: 'باشه', | |
laterButton: 'بعدا', | |
noButton: 'نمی خوام', | |
dialogStyle: DialogStyle( | |
titleAlign: TextAlign.right, | |
messageAlign: TextAlign.right, | |
) | |
/* listener: (button){ | |
switch (button){ | |
case RateMyAppDialogButton.rate: | |
UtilLogger.log('Rate!'); | |
break; | |
case RateMyAppDialogButton.later: | |
UtilLogger.log('Later!'); | |
break; | |
case RateMyAppDialogButton.no: | |
UtilLogger.log('No!'); | |
break; | |
} | |
return true; | |
}*/ | |
) | |
}); | |
} | |
@override | |
void dispose() { | |
_pagerController.dispose(); | |
super.dispose(); | |
} | |
void _fetchPrefs() async { | |
/* var prefs = await SharedPreferences.getInstance(); | |
_darkMode=prefs.getBool('isDarkMode')??false;*/ | |
final result = await Hive.openBox(Constraints.brightnessBox); | |
_darkMode = result.get('darkMode', defaultValue: false); | |
result.close(); | |
} | |
void _onItemTapped(int index) { | |
_selectedIndex = index; | |
_favorite = _selectedIndex == 1 | |
? Icon(Icons.favorite) | |
: Icon(Icons.favorite_border); | |
_foods = _selectedIndex == 0 | |
? Icon(MdiIcons.foodApple) | |
: Icon(MdiIcons.foodAppleOutline); | |
_shoppingList = | |
_selectedIndex == 2 ? Icon(Icons.view_list) : Icon(Icons.playlist_add); | |
_pagerController.jumpToPage(index); | |
setState(() {}); | |
} | |
Widget _bottomBar() { | |
return BottomNavyBar( | |
selectedIndex: _selectedIndex, | |
showElevation: true, // use this to remove appBar's elevation | |
onItemSelected: _onItemTapped, | |
items: [ | |
BottomNavyBarItem( | |
icon: _foods, | |
title: Text('غذاها'), | |
activeColor: Theme.of(context).buttonColor, | |
), | |
BottomNavyBarItem( | |
icon: _favorite, | |
title: Text('موردعلاقه'), | |
activeColor: Theme.of(context).primaryColor), | |
BottomNavyBarItem( | |
icon: _shoppingList, | |
title: Text('سبدهای خرید'), | |
activeColor: Color(0xff2980b9)), | |
BottomNavyBarItem( | |
icon: Icon(Icons.notes), | |
title: Text('نکات آشپزی'), | |
activeColor: Theme.of(context).buttonColor), | |
BottomNavyBarItem( | |
icon: Icon(Icons.account_circle), | |
title: Text('صفحهمن'), | |
activeColor: Theme.of(context).cursorColor), | |
], | |
); | |
} | |
@override | |
Widget build(BuildContext context) { | |
super.build(context); | |
return Directionality( | |
textDirection: TextDirection.rtl, | |
child: Scaffold( | |
body: PageView( | |
physics: NeverScrollableScrollPhysics(), | |
controller: _pagerController, | |
children: <Widget>[ | |
const HomePage(), | |
const FavoritePage(), | |
const ShoppingListPage(), | |
const CookingNotePage(), | |
ProfileForm( | |
nightMode: _darkMode, | |
) | |
], | |
), | |
bottomNavigationBar: _bottomBar(), | |
), | |
); | |
} | |
@override | |
// TODO: implement wantKeepAlive | |
bool get wantKeepAlive => true; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment