Farmers in yards world, beautiful application experience, from the programmer for the processing of detail, and self requirements state, agriculture in the yard a member of the young people is busy, every day, every week, can leave some footprints, is the creation of content, there is a persistent, is I don’t know why, if you lost, might as well to Chou Chou code track of farmers.
If you are interested, you can follow the public account Biglead to get the latest learning materials.
- The Series of articles on Flutter from Entry to Mastery is here
1 Chinese Environment
Add language internationalization support to your Flutter project configuration file
dependencies:
flutter:
sdk: flutter
flutter_localizations:
sdk: flutter
Copy the code
Then configure the Chinese environment in the entry file of your Flutter project as follows:
main() {
runApp(MaterialApp(
// Do not display the debug tag
debugShowCheckedModeBanner: false.// The current operating environment is configured
locale: Locale("zh"."CH"),
// The locale configuration supported by the program
supportedLocales: [Locale("zh"."CH")].//Material style proxy configuration
localizationsDelegates: [
GlobalMaterialLocalizations.delegate,
GlobalWidgetsLocalizations.delegate,
],
// Display the home page
home: DemoDateRangPage(),
));
}
Copy the code
- The Locale class is used to identify the user’s Locale
- GlobalMaterialLocalizations. Delegate for Material Components library provides a localized string
2 Displays the date range selector
This Demo is to click a button to display a date range selector, the page DemoDateRangPage code is as follows
class _DemoDateRangPageState extends State<DemoDateRangPage> {
String _dateSelectText;
@override
Widget build(BuildContext context) {
return Scaffold(
appBar: AppBar(
title: Text("Date range selection"),
),
body: Center(
child: Text("Currently select $_dateSelectText"),
),
floatingActionButton: FloatingActionButton(
onPressed: () {
showDateSelect();
},
child: Icon(Icons.select_all),
),
);
}
Copy the code
void showDateSelect(a) async {
// Get the current time
DateTime start = DateTime.now();
// Add 4 more days to the current time
DateTime end = DateTime(start.year,start.month,start.day+4);
// Display time selector
DateTimeRange selectTimeRange = await showDateRangePicker// locale: locale ("zh"."CH"),
context: context,
// Start time
firstDate: DateTime(2020.1).// End time
lastDate: DateTime(2022.1)CancelText: "cancel ", confirmText:" confirm ",// Initial time range selection
initialDateRange: DateTimeRange(start: start, end: end)
);
/ / the result
_dateSelectText = selectTimeRange.toString();
// Select the start time in the result
DateTime selectStart = selectTimeRange.start;
// Select the end time in the result
DateTime selectEnd = selectTimeRange.end;
setState(() {
});
}
Copy the code
The completion of
Not limited to thinking, not limited to language restrictions, is the highest realm of programming.
With xiaobian character, must be to record a set of video, and then upload
If you are interested, you can follow the public account Biglead to get the latest learning materials