gtgalone / currency_text_input_formatter

Currency Text Input Formatter for Flutter.
https://pub.dev/packages/currency_text_input_formatter
MIT License
50 stars 28 forks source link

fix value update #56

Closed tainanfochesatto closed 4 months ago

tainanfochesatto commented 4 months ago

The new value is currently being updated before the minimum and maximum check, causing issues when obtaining the current value through the methods getDouble(), getUnformattedValue() and getFormattedValue() after exceeding the maximum value.

https://github.com/gtgalone/currency_text_input_formatter/assets/35779173/0eb2999a-b2a3-42c4-ac31-2d2586787f0d

Sample code


class MyHomePage extends StatefulWidget {
  const MyHomePage({super.key});

  @override
  State<MyHomePage> createState() => _MyHomePageState();
}

class _MyHomePageState extends State<MyHomePage> {
  final formatter = CurrencyTextInputFormatter.simpleCurrency(maxValue: 100);

  @override
  Widget build(BuildContext context) {
    return Scaffold(
      body: Padding(
        padding: const EdgeInsets.all(32.0),
        child: Column(
          mainAxisAlignment: MainAxisAlignment.center,
          children: <Widget>[
            const Text('Updated Value:'),
            Text(
              '${formatter.getDouble()}',
              style: Theme.of(context).textTheme.headlineMedium,
            ),
            TextField(
              inputFormatters: [formatter],
              keyboardType: TextInputType.number,
            ),
            ElevatedButton(
              onPressed: () => setState(() {}),
              child: const Text('Update value'),
            ),
          ],
        ),
      ),
    );
  }
}```
gtgalone commented 4 months ago

Thank you so much! @tainanfochesatto

Your fix has been released!