i want to dynamically change the color of my text depending if it exceeds a certain range of numbers (between 0 and 360). i will share my code that is currently working but not changing colors.
class _DurationContainers extends StatelessWidget {
const _DurationContainers({
Key? key,
required this.controller, required this.hint, required this.digits,
}) : super(key: key);
final String hint;
final TextEditingController controller;
final int digits;
@override
Widget build(BuildContext context) {
return Neumorphic(
style: marketplaceButtonsNeuStyle.copyWith(
boxShape: NeumorphicBoxShape.roundRect(BorderRadius.circular(15))
),
child: Container(
width: ScreenUtils.percentWidth(context, 3.2),
child: TextFormField(
controller: controller,
keyboardType: TextInputType.number,
textInputAction: TextInputAction.next,
onSaved: (precio) {},
textAlign: TextAlign.center,
cursorColor: Color.fromARGB(148, 66, 63, 63) ,
style: Theme.of(context).textTheme.headline1!.copyWith(fontSize: 20),
inputFormatters: [
LengthLimitingTextInputFormatter(digits),
FilteringTextInputFormatter.digitsOnly,
],
decoration: InputDecoration(
border: InputBorder.none,
hintStyle: Theme.of(context).textTheme.headline1!.copyWith(fontSize: 21),
contentPadding: EdgeInsets.symmetric(horizontal: ScreenUtils.percentHeight(context, .5)),
hintText: hint
),
),
),
);
}
}
I have tried parsing the data from my textfield to an int and setting a limit but i think im not doing it correctly since its giving me errors.
This is what im currently trying to do.
2
Answers
Can set a condition for the colour in style.
To avoid an error you can set the value of the variable and update it.
You can use
StatefulWidget
andonChanged
callback fromTextFormField
.