I'm having a problem when I try to add "1.1" to a string that I've already changed to double before. I can't work out what's causing the bug.
If you look at the gif you can see that 2.2 +1.1 = 3.30000000003 and then there are other bugs like this
My code :
class _TestPageState extends State<TestPage> {
String value = "";
@override
Widget build(BuildContext context) {
return Scaffold(
appBar: AppBar(title: Text("Test")),
body: Center(
child: Row(
mainAxisAlignment: MainAxisAlignment.center,
children: [
InkWell(
onTap: () {
setState(() {
value = (double.parse(value.isNotEmpty ? value : "0") - 1.1)
.toString();
});
},
child: Container(
alignment: Alignment.center,
decoration: BoxDecoration(
borderRadius: BorderRadius.circular(10),
color: Colors.white,
boxShadow: [
BoxShadow(
color: Colors.black.withOpacity(0.3),
offset: const Offset(0, 2),
blurRadius: 2,
spreadRadius: 1,
),
],
),
height: 60,
width: 60,
child: Center(
child: Text(
"-",
),
),
),
),
Padding(
padding: const EdgeInsets.all(20.0),
child: Text(
value.isNotEmpty ? value : "-",
),
),
InkWell(
onTap: () {
setState(() {
double newValue =
double.parse(value.isNotEmpty ? value : "0") + 1.1;
print(newValue);
value = newValue.toString();
});
},
child: Container(
alignment: Alignment.center,
decoration: BoxDecoration(
borderRadius: BorderRadius.circular(10),
color: Colors.white,
boxShadow: [
BoxShadow(
color: Colors.black.withOpacity(0.3),
offset: const Offset(0, 2),
blurRadius: 2,
spreadRadius: 1,
),
],
),
height: 60,
width: 60,
child: Center(
child: Text(
"+",
),
),
),
),
],
),
),
);
}
}
It looks like your post is mostly code; please add some more details. It looks like your post is mostly code; please add some more details.