Related
how can i change color of these iconbuttons by pressing it, please help me and show me whole code for it,
Thanks
In setState you have to add boolean variable, for example changeColor = false;
Then in button :
color: changeColor ? Colors.grey : Colors.blue,
onPressed: () => setState(() => changeColor = !changeColor),
Flutter - How do I toggle the color of a RaisedButton upon click?
This is new method to change color,
there is youtube video for this Here and a article for this Article
ElevatedButton(
child: Text('Elevated Button'),
onPressed: () {
print('Pressed');
},
style: ButtonStyle(
backgroundColor: MaterialStateProperty.resolveWith<Color>(
(Set<MaterialState> states) {
if (states.contains(MaterialState.pressed)) return Colors.green;
return Colors.greenAccent;
},
),
),
)
You can change the background color of the ElevatedButton using MaterialStateProperty class. You can change the color of the button based on the states too. See the code snippet given below.
IconButton in flutter has a color variable you can set as here:
IconButton(
color: Colors.green,
icon: Icon(Icons.camera),
onPressed: () {},
)
This is the code that I would use:
import 'package:flutter/material.dart';
import 'package:flutter_svg/flutter_svg.dart';
void main() {
runApp(MyApp());
}
class MyApp extends StatelessWidget {
#override
Widget build(BuildContext context) {
return MaterialApp(
theme: ThemeData.dark().copyWith(
scaffoldBackgroundColor: darkBlue,
),
debugShowCheckedModeBanner: false,
home: MyWidget(),
);
}
}
class MyWidget extends StatelessWidget {
#override
Widget build(BuildContext context) {
return Scaffold(
backgroundColor: Colors.white,
body: Center(
child: SingleChildScrollView(
child: Column(children: [
const Text(
'Choose Category',
style: TextStyle(
color: Colors.white,
fontSize: 12,
fontWeight: FontWeight.w600,
),
),
Row(children: [
CategoryButton(
svg: 'assets/candy.svg',
label: 'Tech',
selected: false,
),
CategoryButton(
svg: 'assets/candy.svg',
label: 'Finance',
selected: false,
),
CategoryButton(
svg: 'assets/candy.svg',
label: 'Design',
selected: false,
),
CategoryButton(
svg: 'assets/candy.svg',
label: 'File',
selected: false,
),
CategoryButton(
svg: 'assets/candy.svg',
label: 'Music',
selected: false,
),
])
]),
),
),
);
}
}
class CategoryButton extends StatefulWidget {
CategoryButton({
Key? key,
required this.svg,
required this.label,
required this.selected,
}) : super(key: key);
String svg;
String label;
bool selected;
#override
State<CategoryButton> createState() => _CategoryButtonState();
}
class _CategoryButtonState extends State<CategoryButton> {
#override
Widget build(BuildContext context) {
return GestureDetector(
onTap: () {
setState(() {
widget.selected = !widget.selected;
});
print(widget.selected);
},
child: Container(
height: 40,
width: 40,
decoration: BoxDecoration(
color: widget.selected ? Colors.blue : Colors.black,
borderRadius: BorderRadius.circular(90),
),
child: Column(
children: [
SvgPicture.asset(widget.svg,
color: widget.selected ? Colors.white : Colors.blue),
Text(
widget.label,
style: TextStyle(
color: Colors.white,
fontSize: 9,
fontWeight: FontWeight.w500,
),
),
],
)),
);
}
}
here you need to make sure to add flutter_svg to your pubspec.yaml file and have a folder for your assets and add that to your pubspec.yaml file as well
if you have any further questions just ask :)
It shows this error although I have added late and required in the Question class constructor. It's repeatedly shows
Exception caught by widgets library
The following LateError was thrown building _BodyBuilder:
LateInitializationError: Field 'ques' has not been initialized
Main class:
import 'package:flutter/cupertino.dart';
import 'package:flutter/material.dart';
import 'QuestionsAnswers.dart';
void main() {
runApp(const Quizzler());
}
class Quizzler extends StatelessWidget {
const Quizzler({Key? key}) : super(key: key);
#override
Widget build(BuildContext context) {
return MaterialApp(
debugShowCheckedModeBanner: false,
home: SafeArea(
child: Scaffold(
backgroundColor: Colors.black,
appBar: AppBar(
backgroundColor: Colors.grey[900],
leading: Icon(Icons.games),
title: Text(
'Quizzler',
style: TextStyle(
fontSize: 20.0,
fontWeight: FontWeight.bold,
fontStyle: FontStyle.italic,
color: Colors.white,
),
),
),
body: QuizPlay(),
),
),
);
}
}
class QuizPlay extends StatefulWidget {
const QuizPlay({Key? key}) : super(key: key);
#override
State<QuizPlay> createState() => _QuizplayState();
}
class _QuizplayState extends State<QuizPlay> {
List<Icon> score=[];// array of score icon
List<Questions>questionsAndAnswers=[
Questions(a:'Pakistan is an under developed country',b:true),
Questions(a:'Imran Khan is the Prime Minister of Pakistan',b:true),
Questions(a:'Y comes after U',b:false)
];
int questiontracker=0;// variable to increment of questions
#override
Widget build(BuildContext context) {
return Column(
crossAxisAlignment: CrossAxisAlignment.stretch,
mainAxisAlignment: MainAxisAlignment.spaceBetween,
children: [
Expanded(
flex: 4,
child: Padding(
padding: EdgeInsets.all(10.0),
child: Center(
child: Text(
questionsAndAnswers[questiontracker].ques,
style: TextStyle(
fontSize: 25.0,
color: Colors.white70,
),
),
),
),
),
Expanded(
child: Padding(
padding: EdgeInsets.all(10.0),
child: ElevatedButton(
style: ButtonStyle(
backgroundColor: MaterialStateProperty.all(Colors.green),
),
onPressed: () {
//Yes button
bool answer=questionsAndAnswers[questiontracker].ans;
if (answer==true)
{
print('correct answer');
}
else
{
print('wrong answer ');
}
setState(() {
questiontracker++;
score.add(Icon(Icons.check,color: Colors.green,)) ;
});
},
child: Text(
'Yes',
style: TextStyle(
fontSize: 20.0,
),
),
),
),
),
Expanded(
child: Padding(
padding: EdgeInsets.all(10.0),
child: ElevatedButton(
style: ButtonStyle(
backgroundColor: MaterialStateProperty.all(Colors.red),
),
onPressed: () {
// No button
bool answer=questionsAndAnswers[questiontracker].ans;
if (answer==false)
{
print('correct answer');
}
else
{
print('wrong answer ');
}
setState(() {
questiontracker++;
score.add(Icon(Icons.close,color: Colors.red,)) ;
});
},
child: Text(
'No',
style: TextStyle(
fontSize: 20.0,
),
),
),
),
),
Row(
children: score,
),
],
);
}
}
###Question CLASS###
class Questions{
late String ques;
late bool ans;
Questions({required String a,required bool b})
{
a=ques;
b=ans;
}
}
make it
ques = a;
ans = b;
This stores the value on the right in the value on the left.
Your class constructor Questions is wrong, change it to:
class Questions{
late String ques;
late bool ans;
Questions({required String a,required bool b}) {
ques = a;
and = b;
}
}
What is the purpose of having your questions as a plain class? I'd suggest turning it into a module class which in turn should be
class Question
{
String? ques;
bool? ans;
Question({
this.ques, this.ans});
}
and when you want to initialize a question I'd suggest creating a list
List<Question> questions = [];
question.add(Question("question",true));
// add more as you wish
This will allow you to turn it into JSON which will enable you to maybe provide questions from an online database to the app without needing to update the app every time you want to add a question.
I have a simple website menu on clicking it's just changing int value and on the basis of int value it's changing the font color.
I don't want to use setState instead of it I need to use getX I am doing it like this
class SideMenu extends StatefulWidget {
const SideMenu({Key? key}) : super(key: key);
#override
_SideMenuState createState() => _SideMenuState();
}
class _SideMenuState extends State<SideMenu> {
TileColorX tcx = Get.put(TileColorX());
#override
Widget build(BuildContext context) {
return Drawer(
child: ListView(
children: [
DrawerHeader(
child: Center(
child: Row(
mainAxisAlignment: MainAxisAlignment.center,
children: [
Text('Dashboard ',
style: Theme.of(context).textTheme.caption!.copyWith(
color: Colors.white,
fontSize: 21,
fontWeight: FontWeight.w700)),
Text('Dashboard',
style: Theme.of(context).textTheme.caption!.copyWith(
color: primaryColor,
fontSize: 21,
fontWeight: FontWeight.w700)),
],
)),
),
DrawerListTile(
title: "Dashboard",
svgSrc: "assets/icons/menu_dashbord.svg",
control: 0,
press: () {
tcx.toggle(0);
},
),
DrawerListTile(
title: "POS and Invoices",
svgSrc: "assets/icons/menu_tran.svg",
control: 1,
press: () {
tcx.toggle(1);
},
),
],
),
);
}
}
class DrawerListTile extends StatelessWidget {
DrawerListTile({
Key? key,
// For selecting those three line once press "Command+D"
required this.title,
required this.svgSrc,
required this.press,
required this.control,
}) : super(key: key);
final String title, svgSrc;
final VoidCallback press;
final int control;
TileColorX tcx = Get.put(TileColorX());
#override
Widget build(BuildContext context) {
return ListTile(
onTap: press,
horizontalTitleGap: 0.0,
leading: SvgPicture.asset(
svgSrc,
color: control == tcx.selectedIndex.value
? Colors.white
: Colors.white54,
height: 16,
),
title: Text(
title,
style: TextStyle(
color: control == tcx.selectedIndex.value
? Colors.white
: Colors.white54),
),
);
}
}
I have a class for toggle
class TileColorX extends GetxController {
RxInt selectedIndex = 0.obs;
void toggle(int index) => selectedIndex.value = index;
}
But it's not changing the state (mean not changing my font color)
You need to use Obx on that widget you want to see change. This will work
return Obx(() => ListTile(
onTap: press,
horizontalTitleGap: 0.0,
leading: SvgPicture.asset(
svgSrc,
color: control == tcx.selectedIndex.value
? Colors.white
: Colors.white54,
height: 16,
),
title: Text(
title,
style: TextStyle(
color: control == tcx.selectedIndex.value
? Colors.white
: Colors.white54),
),
));
I don't know more detailed answer to what Obx exactly did but it will work for you :D
"When you select a color from the drop-down menu, the drop-down button widget’s title shows the selected color. Then, when you tap one of the four buttons, only that particular button’s background color will change to the selected background color." This is what I want to do it.
This picture shows the screen. There are 4 color options in the DropdownButton. In the beginning, I made maps for the get "Colors.black" etc. Then I wrote a function called "change" and this function for the color palettes.
But I confused about where to call this function. onPressed part of the RaisedButtons is empty right now. In the first RaisedButton,
_favIconColor = ;
That part will be equals to the new color. But I couldn't call the function anywhere.
This is my whole code:
import 'package:flutter/material.dart';
void main () => runApp(MyApp());
class MyApp extends StatefulWidget {
#override
_MyAppState createState() => _MyAppState();
}
class _MyAppState extends State<MyApp> {
String renk;
String decoration;
String x;
List<DropdownMenuItem> frommenuitems = [
DropdownMenuItem(child: Text('Black'),value: 'Black'),
DropdownMenuItem(child: Text('Green'),value: 'Green'),
DropdownMenuItem(child: Text('Orange'),value: 'Orange'),
DropdownMenuItem(child: Text('Blue'),value: 'Blue')];
final Map<String, int> renkmap = {
'Black': 0,
'Green': 1,
'Orange': 2,
'Blue': 3};
final Map<String, List> formulas = {
'0': [Colors.black],
'1': [Colors.green],
'2': [Colors.orange],
'3': [Colors.blue]};
void change(renk) {
int newcolor = renkmap[renk];
var result = formulas[newcolor];
}
Color _favIconColor = Colors.black; //for the set the RaisedButton color to the black in the beginning
#override
Widget build(BuildContext context) {
final TextStyle header = TextStyle (fontSize: 30, color: Colors.red[500], fontWeight: FontWeight.bold);
final TextStyle buttontext = TextStyle (fontSize: 25, color: Colors.white, fontWeight: FontWeight.bold);
return MaterialApp(
title: 'Color Changing',
home: Scaffold(
body: Container(
child: Column(
children: <Widget> [
Spacer(), //flex property
Text('Select a color', style: header),
DropdownButton(items: frommenuitems, hint: Text('Black', style: TextStyle(color: Colors.black)),
value: renk,
onChanged: (value) {
setState(() {
renk = value;
change(renk);
});
}
),
Spacer(),
ButtonTheme(
minWidth: 2000.0,
height: 100.0,
child: RaisedButton(child: Text('Change Color', style: buttontext), color: _favIconColor,
onPressed: () {
setState(() {
//_favIconColor = ;
});
})),
ButtonTheme(
minWidth: 2000.0,
height: 100.0,
child: RaisedButton(child: Text('Change Color', style: buttontext), color: Colors.black,
onPressed: () {
})),
ButtonTheme(
minWidth: 2000.0,
height: 100.0,
child: RaisedButton(child: Text('Change Color', style: buttontext), color: Colors.black,
onPressed: () {})),
ButtonTheme(
minWidth: 2000.0,
height: 100.0,
child: RaisedButton(child: Text('Change Color', style: buttontext), color: Colors.black,
onPressed: () {}))
],
),
),
),
);}}
you should do this
_favIconColor = Colors.black;
ButtonTheme(
minWidth: 2000.0,
height: 100.0,
child: RaisedButton(child: Text('Change Color', style: buttontext), color: _favIconColor,
onPressed: () {
setState(() {
_favIconColor =newColor ;// the one selected from the drop down menu
});
})),
the issue here is that every time you change the color all the Buttons will have the same color ( because of the setState ) if that ok for you ,
in case you want that every button has its own color you should consider using an array to know which button should change the color
Ps : i don't know what is your change function is used for !! it has no effect here unless it returns the color value or code depends on how you want to use it
I'm sure there are lots of better solutions with more clean codes. But for a temporary workaround, you can try this:
import 'package:flutter/material.dart';
void main() => runApp(MyApp());
class MyApp extends StatefulWidget {
#override
_MyAppState createState() => _MyAppState();
}
class _MyAppState extends State<MyApp> {
String renk;
String decoration;
String x;
List<DropdownMenuItem> frommenuitems = [
DropdownMenuItem(child: Text('Black'), value: 'Black'),
DropdownMenuItem(child: Text('Green'), value: 'Green'),
DropdownMenuItem(child: Text('Orange'), value: 'Orange'),
DropdownMenuItem(child: Text('Blue'), value: 'Blue')
];
final Map<String, int> renkmap = {
'Black': 0,
'Green': 1,
'Orange': 2,
'Blue': 3
};
final Map<String, List> formulas = {
'0': [Colors.black],
'1': [Colors.green],
'2': [Colors.orange],
'3': [Colors.blue]
};
Color _favIconColor = Colors.black;
List<Color> _favIconColorList = [
Colors.black,
Colors.black,
Colors.black,
Colors.black
];
int selectedIndex = -1;
//for the set the RaisedButton color to the black in the beginning
#override
Widget build(BuildContext context) {
void change(renk) {
int newcolor = renkmap[renk];
var result = formulas[newcolor.toString()][0];
/**
* In here, you need to convert int to string, and take the first of the Color list
*/
// In here, if an item selected, then only it should be change.
if (selectedIndex == -1) {
_favIconColorList[0] = result;
_favIconColorList[1] = result;
_favIconColorList[2] = result;
_favIconColorList[3] = result;
} else {
_favIconColorList[selectedIndex] = result;
}
}
final TextStyle header = TextStyle(
fontSize: 30, color: Colors.red[500], fontWeight: FontWeight.bold);
final TextStyle buttontext = TextStyle(
fontSize: 25, color: Colors.white, fontWeight: FontWeight.bold);
return MaterialApp(
title: 'Color Changing',
home: Scaffold(
body: Container(
child: Column(
children: <Widget>[
Spacer(), //flex property
Text('Select a color', style: header),
DropdownButton(
items: frommenuitems,
hint: Text("Color", style: TextStyle(color: _favIconColor)),
value: renk,
onChanged: (value) {
setState(() {
renk = value;
change(renk);
});
}),
Spacer(),
ButtonTheme(
minWidth: 2000.0,
height: 100.0,
child: RaisedButton(
child: Text('Change Color', style: buttontext),
color: _favIconColorList[0],
onPressed: () {
setState(() {
selectedIndex = 0;
//_favIconColor = ;
});
})),
ButtonTheme(
minWidth: 2000.0,
height: 100.0,
child: RaisedButton(
child: Text('Change Color', style: buttontext),
color: _favIconColorList[1],
onPressed: () {
setState(() {
selectedIndex = 1;
});
})),
ButtonTheme(
minWidth: 2000.0,
height: 100.0,
child: RaisedButton(
child: Text('Change Color', style: buttontext),
color: _favIconColorList[2],
onPressed: () {
setState(() {
selectedIndex = 2;
});
})),
ButtonTheme(
minWidth: 2000.0,
height: 100.0,
child: RaisedButton(
child: Text('Change Color', style: buttontext),
color: _favIconColorList[3],
onPressed: () {
setState(() {
selectedIndex = 3;
});
}))
],
),
),
),
);
}
}
You can define a _favIconColorList to store for each ButtonTheme item's color and a selectedIndex with a default value, -1. If it set to an index of ButtonTheme list by tapping one of them, then the color will set only the selected ButtonTheme. Otherwise, all of the ButtonTheme list will be change.
I've created an app that "almost done", but there is some issue regarding to switching theme. I'm using getx and get_storage for it's state management.
I also using a lot of static type for themes because I think it should never get rebuilt all over the time. It works fine for the other components but not for texts. It acts like this which is kinda weird..
I have no idea what causing this, should I avoid using static classes for themes?
Please have a look at my script and feel free to tell me if I did something wrong.
main.dart
void main() async {
WidgetsFlutterBinding.ensureInitialized();
await GetStorage.init();
...
...
runApp(MyApp());
}
class MyApp extends StatelessWidget {
final box = GetStorage();
#override
Widget build(BuildContext context) {
return SimpleBuilder(
builder: (_) {
bool isDark = box.read('darkMode');
return GetMaterialApp(
...
theme: CustomTheme.light,
darkTheme: CustomTheme.dark,
themeMode: isDark == null
? ThemeMode.system
: isDark ? ThemeMode.dark : ThemeMode.light,
...
);
},
);
}
}
custom_theme.dart
class CustomTheme {
static ThemeData get light {
return ThemeData.light().copyWith(
...
cardTheme: CustomCardTheme.shared,
textTheme: CustomTextTheme.light,
...
);
}
static ThemeData get dark {
return ThemeData.dark().copyWith(
...
cardTheme: CustomCardTheme.shared,
textTheme: CustomTextTheme.dark,
...
);
}
}
card_theme.dart
class CustomCardTheme {
static CardTheme get shared {
return CardTheme(
elevation: 8.0,
margin: const EdgeInsets.only(bottom: 8.0),
shadowColor: Colors.black26,
shape: RoundedRectangleBorder(
borderRadius: BorderRadius.circular(10.0),
),
);
}
}
text_theme.dart
const String _fontFamily = 'Nunito Sans';
const TextStyle _lightStyle = TextStyle(
color: Colors.black,
fontFamily: _fontFamily,
);
const TextStyle _darkStyle = TextStyle(
color: Colors.white,
fontFamily: _fontFamily,
);
class CustomTextTheme {
static TextTheme get light {
return ThemeData.light().textTheme.copyWith(
headline1: _lightStyle,
headline2: _lightStyle,
headline3: _lightStyle,
headline4: _lightStyle,
headline5: _lightStyle,
headline6: _lightStyle,
subtitle1: _lightStyle,
subtitle2: _lightStyle,
bodyText1: _lightStyle,
bodyText2: _lightStyle,
// caption: _secondaryStyle,
);
}
static TextTheme get dark {
return ThemeData.dark().textTheme.copyWith(
headline1: _darkStyle,
headline2: _darkStyle,
headline3: _darkStyle,
headline4: _darkStyle,
headline5: _darkStyle,
headline6: _darkStyle,
subtitle1: _darkStyle,
subtitle2: _darkStyle,
bodyText1: _darkStyle,
bodyText2: _darkStyle,
// caption: _secondaryStyle,
);
}
}
profile_menu_card.dart
class ProfileMenuCard extends GetView<ProfileController> {
const ProfileMenuCard({
Key key,
this.iconBackgroundColor,
this.iconHeight = 18.0,
this.iconWidth = 18.0,
this.trailing,
#required this.label,
#required this.icon,
#required this.onTap,
}) : super(key: key);
final Color iconBackgroundColor;
final String label;
final String icon;
final double iconHeight;
final double iconWidth;
final VoidCallback onTap;
final Widget trailing;
#override
Widget build(BuildContext context) {
return Card(
child: Padding(
padding: const EdgeInsets.symmetric(horizontal: 16.0),
child: ListTile(
onTap: onTap,
contentPadding: EdgeInsets.zero,
leading: Container(
height: 32,
width: 32,
decoration: BoxDecoration(
color: iconBackgroundColor ?? Get.theme.primaryColor,
borderRadius: BorderRadius.circular(10.0),
),
child: Center(
child: SvgPicture.asset(
icon,
height: iconHeight,
width: iconWidth,
),
),
),
title: Text(
StringUtils.capitalize(label, allWords: true),
style: Get.textTheme.bodyText1.copyWith(
fontWeight: FontWeight.w600,
),
),
trailing: trailing ?? Icon(Icons.chevron_right),
),
),
);
}
}
dark_mode_switch.dart
class DarkModeSwitch extends StatelessWidget {
final box = GetStorage();
#override
Widget build(BuildContext context) {
bool isDark = box.read('darkMode');
return Transform.scale(
scale: 0.8,
child: CupertinoSwitch(
value: isDark,
onChanged: (bool val) => box.write('darkMode', val),
),
);
}
}
profile_page.dart
const EdgeInsets _titlePadding = EdgeInsets.only(bottom: 10.0, left: 8.0);
class ProfilePage extends GetView<ProfileController> {
#override
Widget build(BuildContext context) {
return Scaffold(
appBar: AppBar(),
body: SingleChildScrollView(
padding: const EdgeInsets.symmetric(horizontal: 20.0),
child: Column(
crossAxisAlignment: CrossAxisAlignment.stretch,
children: [
ListViewGroup(
title: Padding(
padding: _titlePadding,
child: Text('account.info'.tr, style: Get.textTheme.caption),
),
items: [
ProfileMenuCard(
icon: 'assets/icons/icon-user-circle.svg',
label: 'Personal',
onTap: () => Get.toNamed(Routes.ACCOUNT_INFO_PERSONAL),
),
ProfileMenuCard(
iconBackgroundColor: Color(0xFFF3548D),
icon: 'assets/icons/icon-id-badge.svg',
label: 'Employment',
onTap: () {
// Get.toNamed(Routes.EMPLOYMENT_INFO);
},
),
ProfileMenuCard(
iconBackgroundColor: Color(0xFF9A5BFF),
icon: 'assets/icons/icon-contacts.svg',
label: 'Contacts',
onTap: () => Get.toNamed(Routes.CONTACT_INFO),
),
ProfileMenuCard(
iconBackgroundColor: Color(0xFF00D166),
icon: 'assets/icons/icon-book-reader.svg',
label: 'Educations',
onTap: () => Get.toNamed(Routes.EDUCATION_INFO),
),
ProfileMenuCard(
iconBackgroundColor: Color(0xFF57109F),
icon: 'assets/icons/icon-briefcase.svg',
iconHeight: 15.75,
label: 'Working Experiences',
onTap: () => Get.toNamed(Routes.EXPERIENCE_INFO),
),
ProfileMenuCard(
iconBackgroundColor: Color(0xFF28CEE8),
icon: 'assets/icons/icon-credit-card.svg',
iconWidth: 18,
iconHeight: 14,
label: 'Payroll',
onTap: () {},
),
],
),
ListViewGroup(
title: Padding(
padding: _titlePadding,
child: Text('settings'.tr, style: Get.textTheme.caption),
),
items: [
ProfileMenuCard(
iconBackgroundColor: Color(0xFF2DB9B0),
icon: 'assets/icons/icon-bell.svg',
label: 'Notifications',
onTap: () {},
),
ProfileMenuCard(
iconBackgroundColor: Color(0xFF555D5C),
icon: 'assets/icons/icon-moon.svg',
label: 'Dark Mode',
trailing: DarkModeSwitch(),
onTap: null,
),
ProfileMenuCard(
iconBackgroundColor: Color(0xFFFF894B),
icon: 'assets/icons/icon-paint.svg',
label: 'Color Scheme',
onTap: () {},
),
],
),
ListViewGroup(
title: Padding(
padding: _titlePadding,
child: Text('settings.others'.tr, style: Get.textTheme.caption),
),
items: [
ProfileMenuCard(
icon: 'assets/icons/icon-book.svg',
label: 'Official Documentation',
onTap: () {},
),
ProfileMenuCard(
iconBackgroundColor: Color(0xFF9D99B9),
icon: 'assets/icons/icon-info.svg',
label: 'About this app',
onTap: () {},
),
],
),
],
),
),
);
}
}
Themes in Flutter are managed by InheritedWidget ( Theme.of(context) ) to rebuild the Widget that's consuming it's values, much like MediaQuery or Localization... same situation applies, u need to "invalidate" the current context.
You can use static values for fonts, colors, images, whatever... I would use them, as it's more clear to me to build the styles by hand that trying to make sense of all the properties in ThemeData. Although, when u do it that way, you lose the transitions capabilities that Themes has by default to interpolate the values.
Anyway, if you are using GetX, just add at the beginning of each Widget you wanna rebuild on Theme change.
build(context){
context.theme; /// this
return ...
}
Here's a gist and the demo I made a while ago.