Skip to content

Commit

Permalink
Merge pull request #18 from vijaymehrotra/newbranchVijay
Browse files Browse the repository at this point in the history
Solved Issue Number #16
  • Loading branch information
om1512 authored Oct 15, 2023
2 parents 0ac7f2c + c97ebcf commit bc9fac8
Show file tree
Hide file tree
Showing 4 changed files with 193 additions and 4 deletions.
9 changes: 9 additions & 0 deletions lib/Screens/OmUI/main_screen.dart
Original file line number Diff line number Diff line change
Expand Up @@ -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';
Expand Down Expand Up @@ -62,6 +63,14 @@ class _MainScreenState extends State<MainScreen> {
selectedStyle: kRalewayMedium),
SponserPage(),
),
ScreenHiddenDrawer(
ItemHiddenMenu(
name: 'Schedule Information',
baseStyle: kRalewayMedium,
colorLineSelected: kBlue,
selectedStyle: kRalewayMedium),
ScheduleInfoPage(),
),
];
}

Expand Down
134 changes: 134 additions & 0 deletions lib/Screens/OmUI/schedule_info.dart
Original file line number Diff line number Diff line change
@@ -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<ScheduleInfoPage> createState() => _ScheduleInfoPageState();
}

class _ScheduleInfoPageState extends State<ScheduleInfoPage> {
late Future<ScheduleDataModel> scheduleData;

@override
void initState() {
super.initState();
// Fetch the schedule data when the widget is initialized
scheduleData = fetchScheduleData();
}

Future<ScheduleDataModel> 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<ScheduleDataModel>(
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,
),
),
],
),
],
),
),
);
},
);
}
},
);
}
}
4 changes: 0 additions & 4 deletions lib/main.dart
Original file line number Diff line number Diff line change
Expand Up @@ -18,8 +18,4 @@ void main() {
debugShowCheckedModeBanner: false,
home: SplaceScreen(),
));




}
50 changes: 50 additions & 0 deletions lib/models/schedule_data_model .dart
Original file line number Diff line number Diff line change
@@ -0,0 +1,50 @@
class ScheduleDataModel {
List<Data>? data;

ScheduleDataModel({this.data});

ScheduleDataModel.fromJson(Map<String, dynamic> json) {
if (json['data'] != null) {
data = <Data>[];
json['data'].forEach((v) {
data!.add(new Data.fromJson(v));
});
}
}

Map<String, dynamic> toJson() {
final Map<String, dynamic> data = new Map<String, dynamic>();
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<String, dynamic> json) {
sId = json['_id'];
title = json['title'];
description = json['description'];
date = json['date'];
time = json['time'];
}

Map<String, dynamic> toJson() {
final Map<String, dynamic> data = new Map<String, dynamic>();
data['_id'] = this.sId;
data['title'] = this.title;
data['description'] = this.description;
data['date'] = this.date;
data['time'] = this.time;
return data;
}
}

0 comments on commit bc9fac8

Please sign in to comment.