Hello,
i have this code:
// Automatic FlutterFlow imports
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 'dart:convert';
import 'package:flutter/services.dart';
import 'package:syncfusion_flutter_datepicker/datepicker.dart';
class CalendarApp extends StatelessWidget {
@override
Widget build(BuildContext context) {
return MaterialApp(
title: 'Calendar Demo',
theme: ThemeData(useMaterial3: false),
home: const DateRangePicker(),
//home: const DateRangePicker(jsonDataRaw: 'assets/data.json'),
);
}
}
class DateRangePicker extends StatefulWidget {
const DateRangePicker({
super.key,
this.width,
this.height,
required this.jsonDataRaw,
this.simpleText,
});
final double? width;
final double? height;
final String jsonDataRaw;
final String? simpleText;
@override
State<DateRangePicker> createState() => _DateRangePickerState();
}
class _DateRangePickerState extends State<DateRangePicker> {
List<DateTime> blackoutDates = <DateTime>[
DateTime(2024, 03, 18),
DateTime(2024, 03, 19)
];
Future<String> getJsonFromAssets() async {
return await rootBundle.loadString(widget.jsonDataRaw);
}
Future loadSalesData() async {
final String jsonString = await getJsonFromAssets();
final dynamic jsonResponse = json.decode(jsonString);
blackoutDates.clear();
for (Map<String, dynamic> i in jsonResponse['data']) {
blackoutDates.add(DateTime.fromMillisecondsSinceEpoch(i['timestamp']));
}
}
@override
void initState() {
loadSalesData();
super.initState();
}
@override
Widget build(BuildContext context) {
return Scaffold(
appBar: AppBar(),
body: FutureBuilder<String>(
future: getJsonFromAssets(),
builder: (BuildContext context, AsyncSnapshot<String> snapshot) {
if (snapshot.hasData) {
return SfDateRangePicker(
monthViewSettings: DateRangePickerMonthViewSettings(
firstDayOfWeek: 1,
blackoutDates: blackoutDates,
),
monthCellStyle: const DateRangePickerMonthCellStyle(
blackoutDateTextStyle: TextStyle(
color: Colors.red,
decoration: TextDecoration.lineThrough,
),
),
selectionMode: DateRangePickerSelectionMode.range,
enablePastDates: false,
);
} else {
return const CircularProgressIndicator();
}
},
),
);
}
}
and this error
How can I feed the JSON data to the widget?