Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import 'package:flutter/material.dart';
- import 'package:flutter_localizations/flutter_localizations.dart';
- import 'package:intl/intl.dart';
- void main() => runApp(MainApp());
- class MainApp extends StatelessWidget {
- @override
- Widget build(BuildContext context) {
- return MaterialApp(
- localizationsDelegates: [
- GlobalMaterialLocalizations.delegate,
- GlobalWidgetsLocalizations.delegate,
- ],
- supportedLocales: [
- const Locale('th', 'TH'), // English
- ],
- title: 'My App',
- home: MyApp(),
- );
- }
- }
- class MyApp extends StatefulWidget {
- @override
- _MyAppState createState() => _MyAppState();
- }
- class _MyAppState extends State<MyApp> {
- Choice _selectedChoice = choices[0];
- UserTypes _user = userTypes[0];
- final numberDecimal = new NumberFormat("#,##0.00", "en_US");
- void _select(Choice choice) {
- setState(() {
- _selectedChoice = choice;
- print('${choice.title} ${choice.value}');
- });
- }
- DateTime _currentDate;
- int _year = DateTime.now().year;
- int _month = DateTime.now().month;
- int _day = DateTime.now().day;
- Future<Null> showPicker() async {
- final DateTime picked = await showDatePicker(
- locale: const Locale('th'),
- context: context,
- initialDate: DateTime(_year, _month, _day),
- firstDate: new DateTime(1920, 1, 1),
- lastDate: new DateTime(_year + 2, _month, _day));
- if (picked != null && picked != _currentDate) {
- setState(() {
- var strDate = DateFormat.MMMMd('th_TH')
- .format(new DateTime(picked.year, picked.month, picked.day));
- int thYear = picked.year + 543;
- print('$strDate $thYear');
- });
- }
- }
- @override
- void initState() {
- super.initState();
- String num = numberDecimal.format(6000);
- print(num);
- }
- @override
- Widget build(BuildContext context) {
- return Scaffold(
- appBar: AppBar(
- title: Text('My App'),
- actions: <Widget>[
- PopupMenuButton<Choice>(
- onSelected: _select,
- itemBuilder: (BuildContext context) {
- return choices.map((Choice choice) {
- return PopupMenuItem<Choice>(
- value: choice,
- child: Text(choice.title),
- );
- }).toList();
- },
- ),
- ],
- ),
- body: Column(
- children: <Widget>[
- DropdownButton<UserTypes>(
- hint: new Text('Pickup on every'),
- value: _user,
- items: userTypes.map((UserTypes user) {
- return new DropdownMenuItem<UserTypes>(
- value: user,
- child: new Text(user.title),
- );
- }).toList(),
- onChanged: (value) {
- print(value.title);
- setState(() {
- _user = value;
- });
- },
- ),
- RaisedButton(
- onPressed: () => showPicker(),
- child: Text('Show date'),
- )
- ],
- ),
- );
- }
- }
- class Choice {
- const Choice({this.title, this.value});
- final String title;
- final int value;
- }
- class UserTypes {
- const UserTypes({this.title, this.id});
- final String title;
- final int id;
- }
- const List<UserTypes> userTypes = const <UserTypes>[
- const UserTypes(title: 'Admin', id: 1),
- const UserTypes(title: 'Guest', id: 2),
- const UserTypes(title: 'Member', id: 3),
- ];
- const List<Choice> choices = const <Choice>[
- const Choice(title: 'Car', value: 0),
- const Choice(title: 'Bicycle', value: 1),
- const Choice(title: 'Boat', value: 2),
- const Choice(title: 'Bus', value: 3),
- const Choice(title: 'Train', value: 4),
- const Choice(title: 'Walk', value: 5),
- ];
Add Comment
Please, Sign In to add comment