daily pastebin goal
44%
SHARE
TWEET

Untitled

a guest Dec 18th, 2018 57 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. import 'package:flutter/material.dart';
  2. import 'package:flutter_localizations/flutter_localizations.dart';
  3. import 'package:intl/intl.dart';
  4.  
  5. void main() => runApp(MainApp());
  6.  
  7. class MainApp extends StatelessWidget {
  8.   @override
  9.   Widget build(BuildContext context) {
  10.     return MaterialApp(
  11.       localizationsDelegates: [
  12.         GlobalMaterialLocalizations.delegate,
  13.         GlobalWidgetsLocalizations.delegate,
  14.       ],
  15.       supportedLocales: [
  16.         const Locale('th', 'TH'), // English
  17.       ],
  18.       title: 'My App',
  19.       home: MyApp(),
  20.     );
  21.   }
  22. }
  23.  
  24. class MyApp extends StatefulWidget {
  25.   @override
  26.   _MyAppState createState() => _MyAppState();
  27. }
  28.  
  29. class _MyAppState extends State<MyApp> {
  30.   Choice _selectedChoice = choices[0];
  31.   UserTypes _user = userTypes[0];
  32.  
  33.   final numberDecimal = new NumberFormat("#,##0.00", "en_US");
  34.  
  35.   void _select(Choice choice) {
  36.     setState(() {
  37.       _selectedChoice = choice;
  38.       print('${choice.title} ${choice.value}');
  39.     });
  40.   }
  41.  
  42.   DateTime _currentDate;
  43.   int _year = DateTime.now().year;
  44.   int _month = DateTime.now().month;
  45.   int _day = DateTime.now().day;
  46.  
  47.   Future<Null> showPicker() async {
  48.     final DateTime picked = await showDatePicker(
  49.         locale: const Locale('th'),
  50.         context: context,
  51.         initialDate: DateTime(_year, _month, _day),
  52.         firstDate: new DateTime(1920, 1, 1),
  53.         lastDate: new DateTime(_year + 2, _month, _day));
  54.  
  55.     if (picked != null && picked != _currentDate) {
  56.       setState(() {
  57.         var strDate = DateFormat.MMMMd('th_TH')
  58.             .format(new DateTime(picked.year, picked.month, picked.day));
  59.         int thYear = picked.year + 543;
  60.         print('$strDate $thYear');
  61.       });
  62.     }
  63.   }
  64.  
  65.   @override
  66.   void initState() {
  67.     super.initState();
  68.     String num = numberDecimal.format(6000);
  69.     print(num);
  70.   }
  71.  
  72.   @override
  73.   Widget build(BuildContext context) {
  74.     return Scaffold(
  75.       appBar: AppBar(
  76.         title: Text('My App'),
  77.         actions: <Widget>[
  78.           PopupMenuButton<Choice>(
  79.             onSelected: _select,
  80.             itemBuilder: (BuildContext context) {
  81.               return choices.map((Choice choice) {
  82.                 return PopupMenuItem<Choice>(
  83.                   value: choice,
  84.                   child: Text(choice.title),
  85.                 );
  86.               }).toList();
  87.             },
  88.           ),
  89.         ],
  90.       ),
  91.       body: Column(
  92.         children: <Widget>[
  93.           DropdownButton<UserTypes>(
  94.             hint: new Text('Pickup on every'),
  95.             value: _user,
  96.             items: userTypes.map((UserTypes user) {
  97.               return new DropdownMenuItem<UserTypes>(
  98.                 value: user,
  99.                 child: new Text(user.title),
  100.               );
  101.             }).toList(),
  102.             onChanged: (value) {
  103.               print(value.title);
  104.               setState(() {
  105.                 _user = value;
  106.               });
  107.             },
  108.           ),
  109.           RaisedButton(
  110.             onPressed: () => showPicker(),
  111.             child: Text('Show date'),
  112.           )
  113.         ],
  114.       ),
  115.     );
  116.   }
  117. }
  118.  
  119. class Choice {
  120.   const Choice({this.title, this.value});
  121.  
  122.   final String title;
  123.   final int value;
  124. }
  125.  
  126. class UserTypes {
  127.   const UserTypes({this.title, this.id});
  128.   final String title;
  129.   final int id;
  130. }
  131.  
  132. const List<UserTypes> userTypes = const <UserTypes>[
  133.   const UserTypes(title: 'Admin', id: 1),
  134.   const UserTypes(title: 'Guest', id: 2),
  135.   const UserTypes(title: 'Member', id: 3),
  136. ];
  137.  
  138. const List<Choice> choices = const <Choice>[
  139.   const Choice(title: 'Car', value: 0),
  140.   const Choice(title: 'Bicycle', value: 1),
  141.   const Choice(title: 'Boat', value: 2),
  142.   const Choice(title: 'Bus', value: 3),
  143.   const Choice(title: 'Train', value: 4),
  144.   const Choice(title: 'Walk', value: 5),
  145. ];
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand
 
Top