|
| 1 | +import 'package:flutter/material.dart'; |
| 2 | +import 'package:provider/provider.dart'; |
| 3 | + |
| 4 | +import '../customwidgets/reservation_item_body_view.dart'; |
| 5 | +import '../customwidgets/reservation_item_header_view.dart'; |
| 6 | +import '../customwidgets/search_box.dart'; |
| 7 | +import '../models/reservation_expansion_item.dart'; |
| 8 | +import '../providers/app_data_provider.dart'; |
| 9 | +import '../utils/helper_functions.dart'; |
| 10 | + |
| 11 | +class MyReservationPage extends StatefulWidget { |
| 12 | + const MyReservationPage({super.key}); |
| 13 | + |
| 14 | + @override |
| 15 | + State<MyReservationPage> createState() => _MyReservationPageState(); |
| 16 | +} |
| 17 | + |
| 18 | +class _MyReservationPageState extends State<MyReservationPage> { |
| 19 | + bool isFirst = true; |
| 20 | + List<ReservationExpansionItem> items = []; |
| 21 | + @override |
| 22 | + void didChangeDependencies() { |
| 23 | + if(isFirst) { |
| 24 | + _getData(); |
| 25 | + } |
| 26 | + super.didChangeDependencies(); |
| 27 | + } |
| 28 | + |
| 29 | + _getData() async { |
| 30 | + String userName = await getLoggedInUserName(); |
| 31 | + final reservations = await Provider.of<AppDataProvider>(context, listen: false).getMyReservations(userName); |
| 32 | + items = Provider.of<AppDataProvider>(context, listen: false).getExpansionItems(reservations); |
| 33 | + setState(() { |
| 34 | + |
| 35 | + }); |
| 36 | + } |
| 37 | + @override |
| 38 | + Widget build(BuildContext context) { |
| 39 | + return Scaffold( |
| 40 | + appBar: AppBar( |
| 41 | + title: const Text('Reservation List'), |
| 42 | + ), |
| 43 | + body: SingleChildScrollView( |
| 44 | + child: Column( |
| 45 | + children: [ |
| 46 | + // SearchBox(onSubmit: (value) { |
| 47 | + // _search(value); |
| 48 | + // }), |
| 49 | + ExpansionPanelList( |
| 50 | + expansionCallback: (index, isExpanded) { |
| 51 | + setState(() { |
| 52 | + items[index].isExpanded = !items[index].isExpanded; |
| 53 | + print("Item at index $index is now ${items[index].isExpanded}"); |
| 54 | + }); |
| 55 | + }, |
| 56 | + children: items.map((item) => ExpansionPanel( |
| 57 | + isExpanded: item.isExpanded, |
| 58 | + headerBuilder: (context, isExpanded) => ReservationItemHeaderView(header: item.header), |
| 59 | + body: ReservationItemBodyView(body: item.body,) |
| 60 | + )).toList(), |
| 61 | + ), |
| 62 | + ], |
| 63 | + ), |
| 64 | + ), |
| 65 | + ); |
| 66 | + } |
| 67 | +} |
0 commit comments