Last active
December 19, 2021 00:13
-
-
Save Roaa94/0776a0f005cd74d2ddbf8b60061c2cf5 to your computer and use it in GitHub Desktop.
Theme Switcher Widget
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
class ThemeSwitcher extends StatelessWidget { | |
@override | |
Widget build(BuildContext context) { | |
return Consumer<ThemeProvider>( | |
builder: (c, themeProvider, _) => SizedBox( | |
height: (_containerWidth - (17 * 2) - (10 * 2)) / 3, | |
child: GridView.count( | |
physics: const NeverScrollableScrollPhysics(), | |
crossAxisSpacing: 10, | |
crossAxisCount: appThemes.length, | |
children: List.generate( | |
appThemes.length, | |
(i) { | |
bool _isSelectedTheme = appThemes[i].mode == themeProvider.selectedThemeMode; | |
return GestureDetector( | |
onTap: _isSelectedTheme ? null : () => themeProvider.setSelectedThemeMode(appThemes[i].mode), | |
child: AnimatedContainer( | |
height: 100, | |
duration: const Duration(milliseconds: 200), | |
decoration: BoxDecoration( | |
color: _isSelectedTheme ? Theme.of(context).primaryColor : Colors.transparent, | |
borderRadius: BorderRadius.circular(10), | |
border: Border.all(width: 2, color: Theme.of(context).primaryColor), | |
), | |
child: Center( | |
child: Container( | |
padding: const EdgeInsets.symmetric(horizontal: 15, vertical: 7), | |
margin: const EdgeInsets.symmetric(horizontal: 15), | |
decoration: BoxDecoration( | |
borderRadius: BorderRadius.circular(8), | |
color: Theme.of(context).cardColor.withOpacity(0.5), | |
), | |
child: Row( | |
mainAxisAlignment: MainAxisAlignment.spaceAround, | |
children: [ | |
Icon(appThemes[i].icon), | |
Text( | |
appThemes[i].title, | |
style: Theme.of(context).textTheme.subtitle2, | |
), | |
], | |
), | |
), | |
), | |
), | |
); | |
}, | |
), | |
), | |
), | |
); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment