Skip to content

Instantly share code, notes, and snippets.

@mhadaniya
Created August 13, 2020 14:35
Show Gist options
  • Save mhadaniya/3d58b546c0a492e5f50ecfda8ce4ad7c to your computer and use it in GitHub Desktop.
Save mhadaniya/3d58b546c0a492e5f50ecfda8ce4ad7c to your computer and use it in GitHub Desktop.
Example of using intl to format input value.
import 'package:flutter/material.dart';
import 'package:intl/intl.dart';
void main() {
runApp(MyApp());
}
class MyApp extends StatelessWidget {
// This widget is the root of your application.
@override
Widget build(BuildContext context) {
return MaterialApp(
title: 'Flutter Demo',
theme: ThemeData(
primarySwatch: Colors.blue,
visualDensity: VisualDensity.adaptivePlatformDensity,
),
home: MyHomePage(title: 'Flutter Demo Home Page'),
);
}
}
class MyHomePage extends StatefulWidget {
MyHomePage({Key key, this.title}) : super(key: key);
final String title;
@override
_MyHomePageState createState() => _MyHomePageState();
}
class _MyHomePageState extends State<MyHomePage> {
int _inputValue = 0;
var f = NumberFormat('###.00', 'pt_BR');
@override
Widget build(BuildContext context) {
return Scaffold(
appBar: AppBar(
title: Text(widget.title),
),
body: Center(
child: Padding(
padding: const EdgeInsets.symmetric(horizontal: 10.0),
child: Column(
mainAxisAlignment: MainAxisAlignment.center,
children: <Widget>[
TextField(
decoration: InputDecoration(
border: OutlineInputBorder(),
labelText: 'Value',
),
onChanged: (value) {
setState(() {
_inputValue = int.parse(value);
});
},
),
Text(
'Value:',
),
Text(
'${f.format(_inputValue)}',
style: Theme.of(context).textTheme.headline4,
),
],
),
),
),
);
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment