【发布时间】:2021-04-20 19:34:47
【问题描述】:
请帮助我编写代码。 代码是用flutter写的。
我正在尝试使用颤振中的table_calendar 方法通过 laravel 中的 APIREST 请求约会。问题是在请求引用约会的日期时,出现如下错误:
我正在使用此方法并将其放入我的 FutureBuilder 中,以将其与我的 getData() 类(这是从我的 API 接收数据以发送以调用数据库的类)中的快照进行比较。
我什么都不想看到,但约会标记在约会的日期
class CitaList extends StatefulWidget {
@override
_CitaListState createState() => _CitaListState();
}
class _CitaListState extends State<CitaList> {
List<dynamic> list;
Future<List> getData() async {
final response = await http.get("http://192.168.0.6:8000/api/auth/cita");
return json.decode(response.body);
}
CalendarController _calendarController;
UsuarioProvider usuarioProvider;
Map<DateTime, List<dynamic>> _groupedEvents;
@override
void initState() {
super.initState();
_calendarController = CalendarController();
// getData().th-en((value) => _fetchEvents());
}
_groupEvents(List<dynamic> events) {
_groupedEvents = {};
events.forEach((event) {
event = event["Fecha"].split("/");
final eventDay = int.parse(event[1]);
DateTime date = DateTime.utc(eventDay);
if (_groupedEvents[date] == null) _groupedEvents[date] = [];
_groupedEvents[date].add(eventDay);
});
}
@override
Widget build(BuildContext context) {
return Scaffold(
appBar: AppBar(
title: Text('Citas'),
),
body: SingleChildScrollView(
child: FutureBuilder<List>(
future: getData(),
builder: (context, snapshot) {
if (snapshot.hasData) {
final events = snapshot.data;
_groupEvents(events);
DateTime selectedDate = _calendarController.selectedDay;
list = _groupedEvents[selectedDate] ?? [snapshot.data];
return SizedBox(
child: Column(
children: [
Card(
clipBehavior: Clip.antiAlias,
margin: EdgeInsets.all(8.0),
child: TableCalendar(
events: _groupedEvents,
weekendDays: [6],
initialCalendarFormat: CalendarFormat.month,
availableCalendarFormats: {
CalendarFormat.month: 'Meses',
CalendarFormat.week: 'Semanas'
},
locale: 'es_ES',
calendarStyle: CalendarStyle(
todayColor: Colors.orange,
selectedColor: Theme.of(context).primaryColor,
todayStyle: TextStyle(
fontWeight: FontWeight.bold,
fontSize: 18.0,
color: Colors.white),
),
headerStyle: HeaderStyle(
decoration: BoxDecoration(
color: Theme.of(context).primaryColor,
),
headerMargin: EdgeInsets.only(bottom: 8.0),
titleTextStyle: TextStyle(
color: Colors.white, fontSize: 18.0),
centerHeaderTitle: true,
formatButtonDecoration: BoxDecoration(
color: Colors.orange,
borderRadius: BorderRadius.circular(20.0),
),
formatButtonTextStyle: TextStyle(
color: Colors.white, fontSize: 15.0),
formatButtonShowsNext: false,
leftChevronIcon:
Icon(Icons.chevron_left, color: Colors.white),
rightChevronIcon: Icon(
Icons.chevron_right,
color: Colors.white,
)),
startingDayOfWeek: StartingDayOfWeek.monday,
onDaySelected: (date, events, holidays) {
setState(() {});
},
builders: CalendarBuilders(
selectedDayBuilder: (context, day, events) =>
Container(
margin: const EdgeInsets.all(4.0),
alignment: Alignment.center,
decoration: BoxDecoration(
color: Theme.of(context).primaryColor,
borderRadius: BorderRadius.circular(10.0)),
child: Text(
day.day.toString(),
style: TextStyle(color: Colors.white),
),
),
todayDayBuilder: (context, day, events) =>
Container(
margin: const EdgeInsets.all(4.0),
alignment: Alignment.center,
decoration: BoxDecoration(
color: Colors.orange,
borderRadius: BorderRadius.circular(10.0)),
child: Text(
day.day.toString(),
style: TextStyle(color: Colors.white),
),
),
),
calendarController: _calendarController,
),
),
Padding(
padding: const EdgeInsets.only(left: 12.0, top: 8.0),
child: Text(
DateFormat('M/dd/yyyy').format(selectedDate),
style: Theme.of(context).textTheme.headline6,
),
),
ListView.builder(
shrinkWrap: true,
physics: NeverScrollableScrollPhysics(),
itemCount: list == null ? 0 : list.length,
itemBuilder: (context, i) {
return Container(
padding: EdgeInsets.all(10.0),
child: GestureDetector(
child: ListTile(
title: Text('Titulo'),
subtitle: Text(list[i]['Fecha']),
trailing: IconButton(
icon: Icon(Icons.edit),
onPressed: () => Navigator.of(context).push(
MaterialPageRoute(
builder: (BuildContext context) =>
DetailCita(
list: list,
index: i,
))),
),
)),
);
},
),
],
),
);
}
return CircularProgressIndicator();
}),
),
floatingActionButton: FloatingActionButton(
child: Icon(Icons.add),
backgroundColor: Theme.of(context).primaryColor,
onPressed: () {
Navigator.push(
context,
MaterialPageRoute(
builder: (context) => AddCita(
selectedDate: _calendarController.selectedDay,
),
),
);
},
),
);
}
}
非常感谢您的帮助,因为我遇到了困难。
【问题讨论】: