flutter_localizations:
sdk: flutter
main.dartapp
import 'package:flutter/material.dart'; import 'package:flutter_demo/pages/Search.dart'; import 'routes/Routes.dart'; import 'package:flutter_localizations/flutter_localizations.dart'; void main() { runApp(MyApp()); } class MyApp extends StatelessWidget { @override Widget build(BuildContext context) { // TODO: implement build return MaterialApp( localizationsDelegates: [ GlobalMaterialLocalizations.delegate, GlobalWidgetsLocalizations.delegate ], supportedLocales: [ const Locale('zh','CH'), const Locale('en','US') ], debugShowCheckedModeBanner: false, //去掉debug圖標: initialRoute: '/', onGenerateRoute: onGenerateRoute); } }
DatePicker.dartless
import 'package:flutter/material.dart'; import 'package:date_format/date_format.dart'; class DatePickerDemo extends StatefulWidget { DatePickerDemo({Key key}) : super(key: key); _DatePickerDemoState createState() => _DatePickerDemoState(); } class _DatePickerDemoState extends State<DatePickerDemo> { var now = DateTime.now(); DateTime _nowDate = DateTime.now(); var _nowTime=TimeOfDay(hour: 12,minute: 20); // String time; _showDatePicker() async { // showDatePicker( // context: context, // initialDate: _nowDate, // firstDate: DateTime(1980), // lastDate: DateTime(2100) // ).then((result){ // print(result); // }); var result = await showDatePicker( context: context, initialDate: _nowDate, firstDate: DateTime(1980), lastDate: DateTime(2100), locale: Locale('zh') ); print(result); setState(() { this._nowDate = result; }); } _showTimePicker() async{ var result=await showTimePicker( context: context, initialTime:_nowTime ); setState(() { this._nowTime=result; }); } @override void initState() { // TODO: implement initState super.initState(); // print(778899); // // // print(now.millisecondsSinceEpoch); //1568786998995 // print(DateTime.fromMillisecondsSinceEpoch(1568786998995)); //2019-09-18 14:09:58.995 // print(formatDate(DateTime.now(),[yyyy,'年',mm,'月',dd])); } @override Widget build(BuildContext context) { return Scaffold( appBar: AppBar(title: Text('DatePicker')), body: Column( mainAxisAlignment: MainAxisAlignment.center, children: <Widget>[ Row( children: <Widget>[ InkWell( child: Row( mainAxisAlignment: MainAxisAlignment.center, children: <Widget>[ Text("${formatDate(_nowDate, [ yyyy, '年', mm, '月', dd, '日' ])}"), Icon(Icons.arrow_drop_down) ], ), onTap: _showDatePicker, ), InkWell( child: Row( mainAxisAlignment: MainAxisAlignment.center, children: <Widget>[ Text("${_nowTime.format(context)}"), Icon(Icons.arrow_drop_down) ], ), onTap: _showTimePicker, ) ], ) ], )); } }