-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
821fb61
commit 1c4e7ba
Showing
8 changed files
with
331 additions
and
4 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,68 @@ | ||
import 'package:flutter/material.dart'; | ||
import 'package:flutter_cupertino_date_picker/flutter_cupertino_date_picker.dart'; | ||
import 'package:date_format/date_format.dart'; | ||
|
||
class DatePickPub extends StatefulWidget{ | ||
@override | ||
State<StatefulWidget> createState()=>DatePickPubState(); | ||
} | ||
|
||
class DatePickPubState extends State<DatePickPub>{ | ||
|
||
DateTime _dateTime=DateTime.now(); | ||
|
||
_showDatePicker(){ | ||
DatePicker.showDatePicker( | ||
context, | ||
onMonthChangeStartWithFirstDate: true, | ||
pickerTheme: DateTimePickerTheme( | ||
showTitle: true, | ||
confirm: Text('确定', style: TextStyle(color: Colors.red)), | ||
cancel: Text('取消', style: TextStyle(color: Colors.cyan)), | ||
), | ||
minDateTime: DateTime.parse('1980-05-12'), | ||
maxDateTime: DateTime.parse('2100-11-25'), | ||
initialDateTime: _dateTime, | ||
//dateFormat: 'yyyy-MMMM-dd', | ||
dateFormat: 'yyyy年M月d日 EEE,H时:m分', | ||
pickerMode: DateTimePickerMode.datetime, // show TimePicker | ||
locale: DateTimePickerLocale.zh_cn, | ||
onClose: () => print("----- onClose -----"), | ||
onCancel: () => print('onCancel'), | ||
/*onChange: (dateTime, List<int> index) { | ||
setState(() { | ||
_dateTime = dateTime; | ||
}); | ||
},*/ | ||
onConfirm: (dateTime, List<int> index) { | ||
setState(() { | ||
_dateTime = dateTime; | ||
}); | ||
}, | ||
); | ||
} | ||
|
||
@override | ||
Widget build(BuildContext context) { | ||
return Column( | ||
mainAxisAlignment: MainAxisAlignment.center, | ||
children: <Widget>[ | ||
Row( | ||
mainAxisAlignment: MainAxisAlignment.center, | ||
children: <Widget>[ | ||
InkWell( | ||
child: Row( | ||
children: <Widget>[ | ||
Text(formatDate(_dateTime, [yyyy, '年', mm, '月', dd,'日',HH, ':', nn])), | ||
Icon(Icons.arrow_drop_down) | ||
], | ||
), | ||
onTap: _showDatePicker, | ||
), | ||
], | ||
) | ||
], | ||
); | ||
} | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,85 @@ | ||
import 'package:flutter/material.dart'; | ||
import 'package:date_format/date_format.dart'; | ||
|
||
class DatePicker extends StatefulWidget { | ||
@override | ||
State<StatefulWidget> createState() { | ||
return DatePickerState(); | ||
} | ||
} | ||
|
||
class DatePickerState extends State<DatePicker> { | ||
|
||
var date=DateTime.now(); | ||
TimeOfDay time; | ||
|
||
@override | ||
void initState() { | ||
super.initState(); | ||
time=TimeOfDay(hour: date.hour, minute: date.minute); | ||
//print(now);//2020-05-24 09:32:02.308065 | ||
//print(now.millisecondsSinceEpoch);//1590283882112 | ||
//print(DateTime.fromMillisecondsSinceEpoch(1590283882112));//2020-05-24 09:31:22.112 | ||
//print(formatDate(DateTime.now(), [yyyy, '年', mm, '月', dd,'日'])); | ||
} | ||
|
||
_showDatePicker() async{ | ||
/*showDatePicker( | ||
context: context, | ||
initialDate: now, | ||
firstDate: DateTime(1980), | ||
lastDate: DateTime(2100) | ||
).then((value) => print(value));*/ | ||
var result=await showDatePicker( | ||
context: context, | ||
initialDate: date, | ||
firstDate: DateTime(1980), | ||
lastDate: DateTime(2100) | ||
); | ||
setState(() { | ||
date=result; | ||
}); | ||
} | ||
|
||
_showTimePicker() async{ | ||
var result=await showTimePicker( | ||
context: context, | ||
initialTime: time | ||
); | ||
setState(() { | ||
time=result; | ||
}); | ||
} | ||
|
||
@override | ||
Widget build(BuildContext context) { | ||
return Column( | ||
mainAxisAlignment: MainAxisAlignment.center, | ||
children: <Widget>[ | ||
Row( | ||
mainAxisAlignment: MainAxisAlignment.center, | ||
children: <Widget>[ | ||
InkWell( | ||
child: Row( | ||
children: <Widget>[ | ||
Text(formatDate(date, [yyyy, '-', mm, '-', dd])), | ||
Icon(Icons.arrow_drop_down) | ||
], | ||
), | ||
onTap: _showDatePicker, | ||
), | ||
InkWell( | ||
child: Row( | ||
children: <Widget>[ | ||
Text('${time.format(context)}'), | ||
Icon(Icons.arrow_drop_down) | ||
], | ||
), | ||
onTap: _showTimePicker, | ||
) | ||
], | ||
) | ||
], | ||
); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,95 @@ | ||
import 'package:flutter/cupertino.dart'; | ||
import 'package:flutter/material.dart'; | ||
|
||
class RadioPage extends StatefulWidget{ | ||
@override | ||
State<StatefulWidget> createState() { | ||
return RadioPageState(); | ||
} | ||
|
||
} | ||
class RadioPageState extends State<RadioPage>{ | ||
|
||
int sex=1; | ||
|
||
var flag=true; | ||
|
||
@override | ||
Widget build(BuildContext context) { | ||
return Padding( | ||
padding: EdgeInsets.all(10), | ||
child: Column( | ||
children: <Widget>[ | ||
/*Row( | ||
children: <Widget>[ | ||
Text('男:'), | ||
Radio( | ||
value: 1, | ||
groupValue: sex, | ||
onChanged: (v){ | ||
setState(() { | ||
sex=v; | ||
}); | ||
} | ||
), | ||
SizedBox(width: 20), | ||
Text('女:'), | ||
Radio( | ||
value: 2, | ||
groupValue: sex, | ||
onChanged: (v){ | ||
setState(() { | ||
sex=v; | ||
}); | ||
} | ||
) | ||
], | ||
), | ||
Row( | ||
children: <Widget>[ | ||
Text(sex==1?'男':'女') | ||
], | ||
)*/ | ||
RadioListTile( | ||
selected: sex==1, | ||
activeColor: Colors.red, | ||
secondary: Icon(Icons.home), | ||
title: Text('标题'), | ||
subtitle: Text('副标题'), | ||
value: 1, | ||
groupValue: sex, | ||
onChanged: (v){ | ||
setState(() { | ||
sex=v; | ||
}); | ||
} | ||
), | ||
RadioListTile( | ||
selected: sex==2, | ||
activeColor: Colors.red, | ||
secondary: Image.network('https://ss0.bdstatic.com/70cFvHSh_Q1YnxGkpoWK1HF6hhy/it/u=2832826449,831072255&fm=26&gp=0.jpg'), | ||
title: Text('标题'), | ||
subtitle: Text('副标题'), | ||
value: 2, | ||
groupValue: sex, | ||
onChanged: (v){ | ||
setState(() { | ||
sex=v; | ||
}); | ||
} | ||
), | ||
SizedBox(height: 40), | ||
Switch( | ||
value: flag, | ||
onChanged: (v){ | ||
setState(() { | ||
flag=v; | ||
}); | ||
} | ||
) | ||
], | ||
), | ||
); | ||
} | ||
|
||
} |
Oops, something went wrong.