I get this error when running the app on a real device. Testing the web version does not give the error. The data that is submitted is in JSON format and is valid as a format.
error:
type '_Map<Object?, Object?>' is not a subtype of type
'Map<String, dynamic>' in type cast See also: https://flutter.dev/ docs/testing/errors
// Automatic FlutterFlow imports
import '/backend/backend.dart';
import '/backend/schema/structs/index.dart';
import '/flutter_flow/flutter_flow_theme.dart';
import '/flutter_flow/flutter_flow_util.dart';
import '/custom_code/widgets/index.dart'; // Imports other custom widgets
import '/flutter_flow/custom_functions.dart'; // Imports custom functions
import 'package:flutter/material.dart';
// Begin custom widget code
// DO NOT REMOVE OR MODIFY THE CODE ABOVE!
import 'package:calendar_date_picker2/calendar_date_picker2.dart';
import 'dart:convert'; // Import for json decode
final today = DateUtils.dateOnly(DateTime.now());
class DatePickerWidget extends StatefulWidget {
const DatePickerWidget({
super.key,
this.width,
this.height,
required this.rebuildpage,
required this.backAction,
required this.jsonn,
this.colorblockDates,
this.colorownerDate,
this.coloradminDate,
this.colorwaitingDate,
});
final double? width;
final double? height;
final Future Function() rebuildpage;
final Future Function() backAction;
final dynamic jsonn;
final Color? colorblockDates;
final Color? colorownerDate;
final Color? coloradminDate;
final Color? colorwaitingDate;
@override
_DatePickerWidgetState createState() => _DatePickerWidgetState();
}
class _DatePickerWidgetState extends State<DatePickerWidget> {
// List<DateTime?> _selectedDates = [DateTime.now()];
List<DateTime?> _selectedDates = [];
List<DateTime> blockDates = [];
List<DateTime> ownerDates = [];
List<DateTime> adminDates = [];
List<DateTime> waitingDate = [];
@override
void initState() {
super.initState();
_parseDatesFromJson();
}
void _parseDatesFromJson() {
final jsonMap = widget.jsonn as Map<String, dynamic>;
final List<dynamic> data = jsonMap['data'];
for (var item in data) {
final date = DateTime.parse(item['iso_date']);
final status = item['status'];
switch (status) {
case 'block':
blockDates.add(date);
break;
case 'owner':
ownerDates.add(date);
break;
case 'reception':
adminDates.add(date);
break;
case 'waiting':
waitingDate.add(date);
}
}
}
Map<Object?, Object?> objMap = { 'key1': 'value1', 'key2': 5 };
Map<String, dynamic> strDynamicMap = Map<String, dynamic>.from(objMap as Map);
TextStyle? _dayTextStyle(DateTime date) {
if (blockDates.any((blockDate) => date.isAtSameMomentAs(blockDate))) {
return TextStyle(
color: widget.colorblockDates ?? Color.fromARGB(255, 50, 49, 49),
fontWeight: FontWeight.bold);
} else if (ownerDates
.any((ownerDate) => date.isAtSameMomentAs(ownerDate))) {
return TextStyle(
color: widget.colorownerDate ?? Color.fromARGB(255, 4, 101, 246),
fontWeight: FontWeight.bold);
} else if (adminDates
.any((adminDate) => date.isAtSameMomentAs(adminDate))) {
return TextStyle(
color: widget.coloradminDate ?? Color.fromARGB(255, 10, 123, 34),
fontWeight: FontWeight.bold);
} else if (waitingDate
.any((waitingDate) => date.isAtSameMomentAs(waitingDate))) {
return TextStyle(
color: widget.colorwaitingDate ?? Color.fromARGB(255, 10, 123, 34),
fontWeight: FontWeight.bold);
}
return null;
}
@override
Widget build(BuildContext context) {
return Scaffold(
body: Center(
child: CalendarDatePicker2WithActionButtons(
config: CalendarDatePicker2WithActionButtonsConfig(
calendarType: CalendarDatePicker2Type.range,
disableModePicker: true,
dayTextStylePredicate: ({required DateTime date}) {
return _dayTextStyle(date);
},
),
value: _selectedDates,
onValueChanged: (dates) async {
if (dates.length == 2 && dates[0] != null && dates[1] != null) {
final start = dates[0]!;
final end = dates[1]!;
// final end = dates[1]!.add(Duration(
// days: 1)); // Add one day to include the end date in the range
FFAppState().value1 = start;
FFAppState().value2 = end;
// Check if the selected range includes any block dates
bool includesBlockedDates = blockDates
.any((date) => date.isAfter(start) && date.isBefore(end));
if (includesBlockedDates) {
// Show dialog if the range includes block dates
showDialog(
context: context,
builder: (BuildContext context) {
return AlertDialog(
title: Text("Грешка при избор на период"),
content: Text(
"Избраният от вас интервал включва вече резервирани дни. Моля изберете друг интервал или направете две отделни резервации."),
actions: <Widget>[
TextButton(
child: Text("Добре"),
onPressed: () {
Navigator.of(context).pop();
},
),
],
);
},
);
} else {
setState(() {
_selectedDates = dates;
});
await widget.rebuildpage();
}
}
},
onOkTapped: () async {
await widget.backAction();
},
onCancelTapped: () async {
await widget.backAction();
},
),
),
);
}
}
The widget should display a calendar with blocked and colored dates.
Testing the flutterflow virtual simulator also had no problems.The error only appears on Android and iOS devices