0

I have this flutter code

import 'package:intl/intl.dart'; import 'package:law_diary/widgets/customAppBar.dart'; import 'package:law_diary/widgets/sideBar.dart'; import 'package:table_calendar/table_calendar.dart'; import 'package:http/http.dart' as http; import 'dart:convert'; void main() { runApp(MaterialApp( debugShowCheckedModeBanner: false, home: CalendarPage(), )); } class CalendarPage extends StatefulWidget { const CalendarPage({super.key}); @override State<CalendarPage> createState() => _CalendarPageState(); } class _CalendarPageState extends State<CalendarPage> { DateTime today = DateTime.now(); int currentMonth = DateTime.now().month; int currentYear = DateTime.now().year; List<Map<String, dynamic>> records = []; Map<DateTime, List<String>> events = {}; bool isLoadingData = true; @override void initState() { super.initState(); fetchData(); } Future<void> fetchData() async { final String apiUrl = 'https://legaldiary.000webhostapp.com/android/diary/dailyCalendar.php'; try { final response = await http.post( Uri.parse(apiUrl), body: { 'year': currentYear.toString(), 'month': currentMonth.toString(), }, ); if (response.statusCode == 200) { setState(() { records = List<Map<String, dynamic>>.from(json.decode(response.body)); events = convertListToMap(records); print(events); isLoadingData = false; }); // print(records); if (records.isNotEmpty) { records.forEach((record) { // print(record); }); } else { print('No records found for the selected case ID.'); } } else { print('API request failed with status code: ${response.statusCode}'); } } catch (error) { print('Error: $error'); } } Map<DateTime, List<String>> convertListToMap( List<Map<String, dynamic>> inputList) { Map<DateTime, List<String>> resultMap = {}; for (Map<String, dynamic> map in inputList) { String dateString = map['caseDate']; DateTime timestamp = DateTime.parse(dateString).toLocal(); String casesCount = map['cases_count'] .toString(); // Ensure cases_count is treated as a string if (resultMap.containsKey(timestamp)) { resultMap[timestamp]!.add(casesCount); } else { resultMap[timestamp] = [casesCount]; } } return resultMap; } void _onDaySelected(DateTime day, DateTime focusedDay) { setState(() { today = DateTime(day.year, day.month, day.day); }); } @override Widget build(BuildContext context) { return Scaffold( appBar: CustomAppBar(), body: isLoadingData ? Center(child: CircularProgressIndicator()) : content(), ); } Widget content() { return SingleChildScrollView( padding: const EdgeInsets.all(8.0), child: ListView( shrinkWrap: true, physics: ClampingScrollPhysics(), children: [ // Expanded( // child: SingleChildScrollView( // child: TableCalendar( locale: "en_IN", rowHeight: 80, headerStyle: HeaderStyle( formatButtonVisible: false, titleCentered: true, titleTextStyle: TextStyle(fontSize: 20, fontWeight: FontWeight.bold), headerPadding: EdgeInsets.all(8.0), leftChevronPadding: EdgeInsets.symmetric(vertical: 20, horizontal: 16), rightChevronPadding: EdgeInsets.symmetric(vertical: 20, horizontal: 16), ), availableGestures: AvailableGestures.all, selectedDayPredicate: (day) => isSameDay(day, today), focusedDay: today, firstDay: DateTime.utc(currentYear, currentMonth, 1), lastDay: DateTime.utc(currentYear + 1, 1, 31), onDaySelected: _onDaySelected, calendarBuilders: CalendarBuilders( defaultBuilder: (context, day, focusedDay) { for (DateTime d in events.keys) { if (isSameDay(day, d)) { List<String> casesCounts = events[d] ?? []; String casesCountText = casesCounts .join(', '); // Join cases_count values if multiple return Container( decoration: BoxDecoration( // Customize day cell appearance borderRadius: BorderRadius.circular(8.0), border: isSameDay(day, today) ? Border.all(color: Colors.blueAccent) : Border.all(color: Colors.white), ), child: Center( child: Column( mainAxisAlignment: MainAxisAlignment.center, crossAxisAlignment: CrossAxisAlignment.center, children: [ Text( '${day.day}', style: TextStyle( fontSize: 16, fontWeight: FontWeight.bold, color: isSameDay(day, today) ? Colors.white : Colors.black, ), ), Container( padding: EdgeInsets.all(8.0), decoration: BoxDecoration( color: Colors.lightGreen.shade400, borderRadius: BorderRadius.circular( 10.0), // Adjust the border radius as needed ), child: Row( crossAxisAlignment: CrossAxisAlignment.center, mainAxisAlignment: MainAxisAlignment.center, children: [ Icon( Icons.calendar_month_sharp, size: 14, color: Colors.white, ), SizedBox(width: 5), Text( casesCountText, style: const TextStyle( color: Colors.white, fontSize: 14, ), ), ], ), ) ], ), ), ); } } return null; }, ), ), // ), // ), SizedBox(height: 15), Text( 'Selected Day: ' + DateFormat('dd-MMM-yyyy').format(today).toString(), style: TextStyle(fontSize: 16)), Text( '${events[today]?.isNotEmpty ?? false ? 'Number of Cases: ${events[today]!.join(', ')}' : 'No cases found'}', style: TextStyle(fontSize: 16), ), ], ), ); } } 

I have tried everything but the page does not scroll.

In the portrait mode it does not need scrolling but when i rotate the screen to landscape mode, it needs scrolling but the page does not scroll.

i have tried using both listview and singlechildscrollview but nothing works

Stackoverflow link

I referred this link as well but nothing works.

5
  • did you get any error? Try to use physics: NeverScrollPhysics() instead `physics: ClampingScrollPhysics()' . Commented Feb 3, 2024 at 13:17
  • earlier i was not getting any error but this statement is giving error Commented Feb 3, 2024 at 13:41
  • okay I used physics: NeverScrollableScrollPhysics(), instead but still not scrolling Commented Feb 3, 2024 at 13:43
  • The calendar widget has scrolling mechanism that absorbs the swipe event, that's why the parent scroll view can't be scrolled Commented Feb 3, 2024 at 13:44
  • So there is no solution for the same ? Commented Feb 3, 2024 at 13:59

1 Answer 1

1

Update -

I changed the following property of TableCalendar and it worked like a charm

availableGestures: AvailableGestures.all,

to

availableGestures: AvailableGestures.none,

Sign up to request clarification or add additional context in comments.

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.