-
Notifications
You must be signed in to change notification settings - Fork 9
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #18 from vijaymehrotra/newbranchVijay
Solved Issue Number #16
- Loading branch information
Showing
4 changed files
with
193 additions
and
4 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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, | ||
), | ||
), | ||
], | ||
), | ||
], | ||
), | ||
), | ||
); | ||
}, | ||
); | ||
} | ||
}, | ||
); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -18,8 +18,4 @@ void main() { | |
debugShowCheckedModeBanner: false, | ||
home: SplaceScreen(), | ||
)); | ||
|
||
|
||
|
||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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; | ||
} | ||
} |