2021-01-22 18:38:04 +00:00
|
|
|
import 'package:date_field/date_field.dart';
|
2021-09-22 18:06:57 +00:00
|
|
|
import 'package:flutter/material.dart';
|
2021-01-22 18:38:04 +00:00
|
|
|
|
|
|
|
void main() {
|
2021-09-22 18:06:57 +00:00
|
|
|
runApp(const MyApp());
|
2021-01-22 18:38:04 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
class MyApp extends StatelessWidget {
|
2021-09-22 18:06:57 +00:00
|
|
|
const MyApp({Key? key}) : super(key: key);
|
|
|
|
|
2021-01-22 18:38:04 +00:00
|
|
|
// This widget is the root of your application.
|
|
|
|
@override
|
|
|
|
Widget build(BuildContext context) {
|
|
|
|
return MaterialApp(
|
|
|
|
title: 'Flutter Demo',
|
|
|
|
theme: ThemeData(
|
2021-09-22 18:06:57 +00:00
|
|
|
inputDecorationTheme: const InputDecorationTheme(
|
|
|
|
border: OutlineInputBorder(),
|
|
|
|
),
|
2021-01-22 18:38:04 +00:00
|
|
|
primarySwatch: Colors.blue,
|
|
|
|
),
|
2021-09-22 18:06:57 +00:00
|
|
|
home: const MyHomePage(),
|
2021-01-22 18:38:04 +00:00
|
|
|
);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
class MyHomePage extends StatefulWidget {
|
2021-09-22 18:06:57 +00:00
|
|
|
const MyHomePage({Key? key}) : super(key: key);
|
|
|
|
|
2021-01-22 18:38:04 +00:00
|
|
|
@override
|
|
|
|
_MyHomePageState createState() => _MyHomePageState();
|
|
|
|
}
|
|
|
|
|
|
|
|
class _MyHomePageState extends State<MyHomePage> {
|
2021-09-22 18:06:57 +00:00
|
|
|
DateTime? selectedDate;
|
2021-01-22 18:38:04 +00:00
|
|
|
|
|
|
|
@override
|
|
|
|
Widget build(BuildContext context) {
|
|
|
|
return Scaffold(
|
|
|
|
body: Padding(
|
2021-01-23 10:57:52 +00:00
|
|
|
padding: const EdgeInsets.all(20.0),
|
|
|
|
child: Column(
|
|
|
|
mainAxisAlignment: MainAxisAlignment.center,
|
2021-09-22 18:06:57 +00:00
|
|
|
children: <Widget>[
|
2021-01-23 10:57:52 +00:00
|
|
|
const FlutterLogo(size: 100),
|
|
|
|
const SizedBox(height: 20),
|
|
|
|
const Text('DateField package showcase'),
|
|
|
|
const Padding(
|
|
|
|
padding: EdgeInsets.symmetric(vertical: 20.0),
|
|
|
|
child: Text('DateTimeField'),
|
|
|
|
),
|
|
|
|
DateTimeField(
|
|
|
|
decoration: const InputDecoration(
|
|
|
|
hintText: 'Please select your birthday date and time'),
|
|
|
|
selectedDate: selectedDate,
|
|
|
|
onDateSelected: (DateTime value) {
|
|
|
|
setState(() {
|
|
|
|
selectedDate = value;
|
|
|
|
});
|
|
|
|
}),
|
|
|
|
const Padding(
|
|
|
|
padding: EdgeInsets.symmetric(vertical: 20.0),
|
|
|
|
child: Text('DateTimeFormField'),
|
|
|
|
),
|
|
|
|
Form(
|
|
|
|
child: Column(
|
2021-09-22 18:06:57 +00:00
|
|
|
children: <Widget>[
|
2021-01-23 10:57:52 +00:00
|
|
|
DateTimeFormField(
|
2021-01-22 18:38:04 +00:00
|
|
|
decoration: const InputDecoration(
|
2021-01-23 10:57:52 +00:00
|
|
|
hintStyle: TextStyle(color: Colors.black45),
|
|
|
|
errorStyle: TextStyle(color: Colors.redAccent),
|
|
|
|
border: OutlineInputBorder(),
|
|
|
|
suffixIcon: Icon(Icons.event_note),
|
|
|
|
labelText: 'My Super Date Time Field',
|
2021-01-22 18:38:04 +00:00
|
|
|
),
|
2021-01-23 10:57:52 +00:00
|
|
|
autovalidateMode: AutovalidateMode.always,
|
2021-09-22 18:06:57 +00:00
|
|
|
validator: (DateTime? e) =>
|
2021-01-23 10:57:52 +00:00
|
|
|
(e?.day ?? 0) == 1 ? 'Please not the first day' : null,
|
2021-01-22 18:38:04 +00:00
|
|
|
onDateSelected: (DateTime value) {
|
2021-01-23 10:57:52 +00:00
|
|
|
print(value);
|
|
|
|
},
|
2021-01-22 18:38:04 +00:00
|
|
|
),
|
2021-01-23 10:57:52 +00:00
|
|
|
const SizedBox(height: 50),
|
|
|
|
DateTimeFormField(
|
|
|
|
decoration: const InputDecoration(
|
|
|
|
hintStyle: TextStyle(color: Colors.black45),
|
|
|
|
errorStyle: TextStyle(color: Colors.redAccent),
|
|
|
|
border: OutlineInputBorder(),
|
|
|
|
suffixIcon: Icon(Icons.event_note),
|
|
|
|
labelText: 'Only time',
|
|
|
|
),
|
|
|
|
mode: DateTimeFieldPickerMode.time,
|
|
|
|
autovalidateMode: AutovalidateMode.always,
|
2021-09-22 18:06:57 +00:00
|
|
|
validator: (DateTime? e) {
|
|
|
|
return (e?.day ?? 0) == 1
|
|
|
|
? 'Please not the first day'
|
|
|
|
: null;
|
|
|
|
},
|
2021-01-23 10:57:52 +00:00
|
|
|
onDateSelected: (DateTime value) {
|
|
|
|
print(value);
|
|
|
|
},
|
|
|
|
),
|
|
|
|
],
|
|
|
|
),
|
2021-01-22 18:38:04 +00:00
|
|
|
),
|
2021-01-23 10:57:52 +00:00
|
|
|
],
|
|
|
|
),
|
|
|
|
));
|
2021-01-22 18:38:04 +00:00
|
|
|
}
|
|
|
|
}
|