Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
56 changes: 9 additions & 47 deletions example/lib/main.dart
Original file line number Diff line number Diff line change
Expand Up @@ -26,15 +26,12 @@ const Set<PointerDeviceKind> _kTouchLikeDeviceTypes = <PointerDeviceKind>{
};

class _MyAppState extends State<MyApp> {
bool dark = false;

@override
Widget build(BuildContext context) {
return MaterialApp(
theme: ThemeData(
primarySwatch: Colors.blue,
fontFamily: _fontFamily,
brightness: dark ? Brightness.dark : Brightness.light,
primaryTextTheme: TextTheme().apply(fontFamily: _fontFamily),
),
scrollBehavior: const MaterialScrollBehavior()
Expand Down Expand Up @@ -76,19 +73,10 @@ class _MyHomePageState extends State<MyHomePage> {
automaticallyImplyLeading: false,
elevation: 0.0,
actions: [
IconButton(
onPressed: () {
final appState = context.findAncestorStateOfType<_MyAppState>();
if (appState == null) return;
appState.setState(() {
appState.dark = !appState.dark;
});
},
icon: Icon(Icons.sunny_snowing)),
IconButton(
onPressed: () => Navigator.push(
context, MaterialPageRoute(builder: (v) => RawPickerTest())),
icon: Icon(Icons.add)),
icon: Icon(Icons.add))
],
),
body: Builder(
Expand Down Expand Up @@ -185,21 +173,14 @@ class _MyHomePageState extends State<MyHomePage> {
showPickerCustomBuilder(context);
},
),
ListTile(
title: Text('16. Select year'),
onTap: () {
showPickerSelectYear(context);
},
),
const SizedBox(height: 60),
],
)),
);
}

showMsg(String msg) {
final state = ScaffoldMessenger.of(context);
state.showSnackBar(SnackBar(content: Text(msg)));
ScaffoldMessenger.of(context).showSnackBar(SnackBar(content: Text(msg)));
}

showPicker(BuildContext context) async {
Expand All @@ -208,11 +189,7 @@ class _MyHomePageState extends State<MyHomePage> {
pickerData: JsonDecoder().convert(PickerData)),
changeToFirst: false,
textAlign: TextAlign.left,
textStyle: TextStyle(
color: Theme.of(context).brightness == Brightness.dark
? Colors.yellow
: Colors.blue,
fontFamily: _fontFamily),
textStyle: TextStyle(color: Colors.blue, fontFamily: _fontFamily),
selectedTextStyle: TextStyle(color: Colors.red),
columnPadding: const EdgeInsets.all(8.0),
onConfirm: (Picker picker, List value) {
Expand Down Expand Up @@ -436,14 +413,15 @@ class _MyHomePageState extends State<MyHomePage> {
),
title: Text("Select DateTime"),
textAlign: TextAlign.right,
// selectedTextStyle: TextStyle(color: Colors.blue),
selectedTextStyle: TextStyle(color: Colors.blue),
delimiter: [
PickerDelimiter(
column: 5,
child: Container(
width: 16.0,
alignment: Alignment.center,
child: Text(':', style: TextStyle(fontWeight: FontWeight.bold)),
color: Colors.white,
))
],
footer: Container(
Expand Down Expand Up @@ -567,6 +545,7 @@ class _MyHomePageState extends State<MyHomePage> {
width: 12.0,
alignment: Alignment.center,
child: Text(':', style: TextStyle(fontWeight: FontWeight.bold)),
color: Colors.white,
)),
],
title: Text("Select DateTime"),
Expand All @@ -579,7 +558,7 @@ class _MyHomePageState extends State<MyHomePage> {
picker.showModal(context, backgroundColor: Colors.transparent,
builder: (context, view) {
return Material(
// color: Colors.white,
color: Colors.white,
borderRadius: BorderRadius.only(
topLeft: Radius.circular(10), topRight: Radius.circular(10)),
child: Container(
Expand Down Expand Up @@ -694,7 +673,7 @@ class _MyHomePageState extends State<MyHomePage> {
fontWeight: FontWeight.bold,
color: Colors.red,
fontSize: 14)),
// color: Colors.white,
color: Colors.white,
)),
],
onSelect: (Picker picker, int index, List<int> selected) {
Expand Down Expand Up @@ -733,7 +712,7 @@ class _MyHomePageState extends State<MyHomePage> {
fontWeight: FontWeight.bold,
color: Colors.red,
fontSize: 14)),
// color: Colors.white,
color: Colors.white,
)),
],
onSelect: (Picker picker, int index, List<int> selected) {
Expand All @@ -748,21 +727,4 @@ class _MyHomePageState extends State<MyHomePage> {
);
});
}

showPickerSelectYear(BuildContext context) {
Picker(
adapter: DateTimePickerAdapter(
type: PickerDateTimeType.kY,
yearSuffix: "年",
yearBegin: 1950,
yearEnd: 2025,
),
title: Text("Select Year"),
onConfirm: (Picker picker, List value) {
print(picker.adapter.text);
},
onSelect: (Picker picker, int index, List<int> selected) {
print(picker.adapter.toString());
}).showBottomSheet(context);
}
}
Loading