diff --git a/lib/Screens/OmUI/main_screen.dart b/lib/Screens/OmUI/main_screen.dart index 8ee9634..e57fab4 100644 --- a/lib/Screens/OmUI/main_screen.dart +++ b/lib/Screens/OmUI/main_screen.dart @@ -2,6 +2,7 @@ import 'package:flutter/material.dart'; import 'package:gdsc_ui_design/Screens/OmUI/HomePage.dart'; import 'package:gdsc_ui_design/Screens/OmUI/MembersPage.dart'; import 'package:gdsc_ui_design/Screens/OmUI/RegisteredPage.dart'; +import 'package:gdsc_ui_design/Screens/OmUI/schedule_info.dart'; import 'package:gdsc_ui_design/Screens/OmUI/sponsors_page.dart'; import 'package:gdsc_ui_design/utils/app_styles.dart'; import 'package:gdsc_ui_design/utils/size_config.dart'; @@ -62,6 +63,14 @@ class _MainScreenState extends State { selectedStyle: kRalewayMedium), SponserPage(), ), + ScreenHiddenDrawer( + ItemHiddenMenu( + name: 'Schedule Information', + baseStyle: kRalewayMedium, + colorLineSelected: kBlue, + selectedStyle: kRalewayMedium), + ScheduleInfoPage(), + ), ]; } diff --git a/lib/Screens/OmUI/schedule_info.dart b/lib/Screens/OmUI/schedule_info.dart new file mode 100644 index 0000000..749cd0c --- /dev/null +++ b/lib/Screens/OmUI/schedule_info.dart @@ -0,0 +1,134 @@ +import 'dart:convert'; +import 'package:gdsc_ui_design/utils/app_styles.dart'; +import 'package:http/http.dart' as http; +import 'package:flutter/material.dart'; +import 'package:gdsc_ui_design/models/schedule_data_model%20.dart'; + +class ScheduleInfoPage extends StatefulWidget { + const ScheduleInfoPage({super.key}); + + @override + State createState() => _ScheduleInfoPageState(); +} + +class _ScheduleInfoPageState extends State { + late Future scheduleData; + + @override + void initState() { + super.initState(); + // Fetch the schedule data when the widget is initialized + scheduleData = fetchScheduleData(); + } + + Future fetchScheduleData() async { + final response = await http + .get(Uri.parse('https://du-hacks-apis.vercel.app/api/v2/schedule')); + + if (response.statusCode == 200) { + // If server returns an OK response, parse the JSON + return ScheduleDataModel.fromJson(json.decode(response.body)); + } else { + // If the server did not return a 200 OK response, + // throw an exception. + throw Exception('Failed to load data'); + } + } + + void getData() async { + try { + ScheduleDataModel scheduleData = await fetchScheduleData(); + // Do something with the data + } catch (e) { + print('Error: $e'); + } + } + + @override + Widget build(BuildContext context) { + return FutureBuilder( + future: scheduleData, + builder: (context, snapshot) { + if (snapshot.connectionState == ConnectionState.waiting) { + // Show loading indicator while the data is being fetched + return Center(child: CircularProgressIndicator()); + } else if (snapshot.hasError) { + // Show error message if there's an error fetching the data + return Text('Error: ${snapshot.error}'); + } else if (!snapshot.hasData || snapshot.data!.data!.isEmpty) { + // Show a message if the data is empty + return Text('No schedule data available.'); + } else { + // Show the schedule data + return ListView.builder( + itemCount: snapshot.data!.data!.length, + itemBuilder: (context, index) { + final item = snapshot.data!.data![index]; + return Card( + margin: EdgeInsets.all(8.0), + elevation: 4.0, + shadowColor: kBlack0D.withOpacity(0.2), + shape: RoundedRectangleBorder( + borderRadius: BorderRadius.circular(8.0), + ), + child: Container( + decoration: BoxDecoration( + color: kLightBlue, + borderRadius: BorderRadius.all(Radius.circular(8.0)), + ), + padding: EdgeInsets.all(16.0), + width: double.maxFinite, + child: Column( + crossAxisAlignment: CrossAxisAlignment.start, + children: [ + Text( + item.title!, + style: TextStyle( + fontSize: 18, + fontWeight: FontWeight.bold, + color: kBlack0D, + ), + ), + SizedBox(height: 4.0), + Text( + item.description!, + style: TextStyle( + fontSize: 14, + color: kBlack0D, + ), + ), + SizedBox(height: 8.0), + Row( + children: [ + Icon(Icons.date_range, color: kBlack0D), + SizedBox(width: 4.0), + Text( + item.date!, + style: TextStyle( + fontSize: 14, + color: kBlack0D, + ), + ), + SizedBox(width: 16.0), + Icon(Icons.access_time, color: kBlack0D), + SizedBox(width: 4.0), + Text( + item.time!, + style: TextStyle( + fontSize: 14, + color: kBlack0D, + ), + ), + ], + ), + ], + ), + ), + ); + }, + ); + } + }, + ); + } +} diff --git a/lib/main.dart b/lib/main.dart index da952a3..ef48d72 100644 --- a/lib/main.dart +++ b/lib/main.dart @@ -18,8 +18,4 @@ void main() { debugShowCheckedModeBanner: false, home: SplaceScreen(), )); - - - - } diff --git a/lib/models/schedule_data_model .dart b/lib/models/schedule_data_model .dart new file mode 100644 index 0000000..fa08199 --- /dev/null +++ b/lib/models/schedule_data_model .dart @@ -0,0 +1,50 @@ +class ScheduleDataModel { + List? data; + + ScheduleDataModel({this.data}); + + ScheduleDataModel.fromJson(Map json) { + if (json['data'] != null) { + data = []; + json['data'].forEach((v) { + data!.add(new Data.fromJson(v)); + }); + } + } + + Map toJson() { + final Map data = new Map(); + if (this.data != null) { + data['data'] = this.data!.map((v) => v.toJson()).toList(); + } + return data; + } +} + +class Data { + String? sId; + String? title; + String? description; + String? date; + String? time; + + Data({this.sId, this.title, this.description, this.date, this.time}); + + Data.fromJson(Map json) { + sId = json['_id']; + title = json['title']; + description = json['description']; + date = json['date']; + time = json['time']; + } + + Map toJson() { + final Map data = new Map(); + data['_id'] = this.sId; + data['title'] = this.title; + data['description'] = this.description; + data['date'] = this.date; + data['time'] = this.time; + return data; + } +} \ No newline at end of file