【发布时间】:2021-06-07 23:51:52
【问题描述】:
我希望如果我们在日历表上按某一天,那么文本将自动设置被点击的日期。
这是使用TableCalendar实现的代码:
@override
Widget build(BuildContext context) {
return Scaffold(
body: SingleChildScrollView(
child: Column(
crossAxisAlignment: CrossAxisAlignment.start,
children: <Widget>[
Padding(
padding: const EdgeInsets.only(top:10.0,bottom: 5.0,left: 10.0,right: 10.0),
child: Text(tgl,style: TextStyle(color: Colors.green, fontSize: 16.0,fontWeight: FontWeight.w500),),
),//for the text I use datetimeNow
Padding(
padding: const EdgeInsets.only(bottom:10.0,left: 10.0,right: 10.0),
child: TableCalendar(
initialCalendarFormat: CalendarFormat.month,
calendarStyle: CalendarStyle(
todayColor: Colors.green,
selectedColor: Theme.of(context).primaryColor,
todayStyle: TextStyle(
fontWeight: FontWeight.bold,
fontSize: 22.0,
color: Colors.white)
),
headerStyle: HeaderStyle(
centerHeaderTitle: true,
formatButtonDecoration: BoxDecoration(
color: Colors.brown,
borderRadius: BorderRadius.circular(22.0),
),
formatButtonTextStyle: TextStyle(color: Colors.white),
formatButtonShowsNext: false,
),
startingDayOfWeek: StartingDayOfWeek.monday,
onDaySelected: (date, events,e) {
print(date.toUtc());
},
builders: CalendarBuilders(
selectedDayBuilder: (context, date, events) => Container(
margin: const EdgeInsets.all(5.0),
alignment: Alignment.center,
decoration: BoxDecoration(
color: Theme.of(context).primaryColor,
borderRadius: BorderRadius.circular(8.0)),
child: Text(
date.day.toString(),
style: TextStyle(color: Colors.white),
)),
todayDayBuilder: (context, date, events) => Container(
margin: const EdgeInsets.all(5.0),
alignment: Alignment.center,
decoration: BoxDecoration(
color: Colors.black26,
borderRadius: BorderRadius.circular(8.0)),
child: Text(
date.day.toString(),
style: TextStyle(color: Colors.white),
)),
),
calendarController: _controller,
),
),
Padding(
padding: const EdgeInsets.only(left:15.0,top: 10.0,right: 15.0),
child:
Column(
crossAxisAlignment: CrossAxisAlignment.start,
children: [
Text("Report __ ", style: TextStyle(
color: Colors.green, fontSize: 16.0,fontWeight: FontWeight.w500)
),.................
【问题讨论】:
标签: flutter date dart mobile calendar