I'm trying to change a button colour based on firebase text. When a user presses on the container then a callback will check a condition if the button match with the firebase instance then the button colour will be green if not then red.
class TestBtnWidget extends StatefulWidget {
const TestBtnWidget({
Key? key,
this.btnText,
this.customAction,
this.colorChange,
}) : super(key: key);
final String? btnText;
final Future<dynamic> Function()? customAction;
final Color? colorChange;
@override
_TestBtnWidgetState createState() => _TestBtnWidgetState();
}
class _TestBtnWidgetState extends State<TestBtnWidget> {
@override
void initState() {
super.initState();
WidgetsBinding.instance.addPostFrameCallback((_) => setState(() {}));
}
@override
Widget build(BuildContext context) {
return Align(
alignment: AlignmentDirectional(0, 0),
child: InkWell(
onTap: () async {
await widget.customAction?.call();
},
child: Container(
width: 180,
height: 50,
decoration: BoxDecoration(
color: widget.colorChange,
borderRadius: BorderRadius.circular(6),
),
alignment: AlignmentDirectional(0, 0),
child: Text(
widget.btnText!,
style: Theme.of(context).bodyText1,
),
),
),
);
}
}