Skip to content

Commit

Permalink
Merge pull request #8 from Jai-Shree-Krishna/Prices_Screen
Browse files Browse the repository at this point in the history
Closes #5
  • Loading branch information
om1512 committed Oct 1, 2023
2 parents 531a015 + 44a25b5 commit 572999c
Show file tree
Hide file tree
Showing 6 changed files with 167 additions and 0 deletions.
Binary file added assets/images/first-prize-trophy.jpg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added assets/images/second-prize-trophy.jpg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added assets/images/third-prize-trophy.jpg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
155 changes: 155 additions & 0 deletions lib/Screens/OmUI/PricesScreen.dart
Original file line number Diff line number Diff line change
@@ -0,0 +1,155 @@
import 'package:flutter/material.dart';
import 'package:gdsc_ui_design/utils/app_styles.dart';
import 'package:gdsc_ui_design/utils/size_config.dart';
import 'package:http/http.dart' as http;
import 'dart:convert';


class PrizePage extends StatelessWidget {
@override
Widget build(BuildContext context) {
return Scaffold(
body: FutureBuilder<List<Prize>>(
future: fetchPrizes(),
builder: (context, snapshot) {
if (snapshot.connectionState == ConnectionState.waiting) {
return CircularProgressIndicator();
} else if (snapshot.hasError) {
return Text('Error: ${snapshot.error}');
} else if (snapshot.hasData) {
List<Prize> prizes = snapshot.data!;
return PrizeCardList(prizes: prizes);
} else {
return Text('No data available.');
}
},
),
);
}
}

class Prize {
final String title;
final List<String> rewards;

Prize({required this.title, required this.rewards});

factory Prize.fromJson(Map<String, dynamic> json) {
return Prize(
title: json['title'],
rewards: List<String>.from(json['rewards']),
);
}
}

Future<List<Prize>> fetchPrizes() async {
final response = await http.get(Uri.parse('https://du-hacks-apis.vercel.app/api/v2/prizes/'));

if (response.statusCode == 200) {
List<dynamic> data = jsonDecode(response.body)['data'];

if (data is List) {
List<Prize> prizes = data.map((json) => Prize.fromJson(json)).toList();
return prizes;
} else {
throw Exception('API response data is not a list.');
}
} else {
throw Exception('Failed to fetch prizes');
}
}

class PrizeCardList extends StatelessWidget {
final List<Prize> prizes;

PrizeCardList({required this.prizes});

static const List <String> trophy = [
'assets/images/first-prize-trophy.jpg',
'assets/images/second-prize-trophy.jpg',
'assets/images/third-prize-trophy.jpg'
];

@override
Widget build(BuildContext context) {
return ListView.builder(
itemCount: prizes.length,
itemBuilder: (context, index) {
return PrizeCard(
title: prizes[index].title,
rewards: prizes[index].rewards,
glowColor: prizes[index].title == "First Prize"
? Color(0xFFFFD700)
: (prizes[index].title == "Second Prize" ? Color(0xFFC0C0C0) : Color(0xFFCD7F32)),
trophyImage: prizes[index].title == "First Prize"
? trophy[0]
: (prizes[index].title == "Second Prize" ? trophy[1] : trophy[2]),
);
},
);
}
}

class PrizeCard extends StatelessWidget {
final String title;
final List<String> rewards;
final Color glowColor;
final String trophyImage;

PrizeCard({
required this.title,
required this.rewards,
required this.glowColor,
required this.trophyImage,
});

@override
Widget build(BuildContext context) {
return Container(
width: 300,
margin: EdgeInsets.all(kPadding16),
decoration: BoxDecoration(
borderRadius: BorderRadius.circular(20.0),
boxShadow: [
BoxShadow(
color: glowColor.withOpacity(0.4),
blurRadius: 10,
spreadRadius: 5,
),
],
color: glowColor,
),
child: Column(
crossAxisAlignment: CrossAxisAlignment.stretch,
children: [
Container(
padding: EdgeInsets.all(16.0),
child: Text(
title,
textAlign: TextAlign.center,
style: kRalewaySemibold.copyWith(
fontSize: SizeConfig.blockSizeHorizontal! * 5,
),
),
),
Image.asset(
trophyImage,
height: 100,
width: 100,
),
for (String reward in rewards)
Container(
padding: EdgeInsets.all(kPadding8),
child: Text(
reward,
style: kRalewaySemibold.copyWith(
fontSize: SizeConfig.blockSizeHorizontal! * 3.5,
),
textAlign: TextAlign.center,
),
),
],
),
);
}
}
9 changes: 9 additions & 0 deletions lib/Screens/OmUI/main_screen.dart
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import 'package:gdsc_ui_design/Screens/OmUI/RegisteredPage.dart';
import 'package:gdsc_ui_design/utils/app_styles.dart';
import 'package:gdsc_ui_design/utils/size_config.dart';
import 'package:hidden_drawer_menu/hidden_drawer_menu.dart';
import 'package:gdsc_ui_design/Screens/OmUI/PricesScreen.dart';

class MainScreen extends StatefulWidget {
const MainScreen({super.key});
Expand Down Expand Up @@ -44,6 +45,14 @@ class _MainScreenState extends State<MainScreen> {
selectedStyle: kRalewayMedium),
MembersPage(),
),
ScreenHiddenDrawer(
ItemHiddenMenu(
name: 'Prize Information',
baseStyle: kRalewayMedium,
colorLineSelected: kBlue,
selectedStyle: kRalewayMedium),
PrizePage(),
),
];
}

Expand Down
3 changes: 3 additions & 0 deletions pubspec.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,9 @@ flutter:
# To add assets to your application, add an assets section, like this:
assets:
- assets/images/
- assets/images/first-prize-trophy.jpg
- assets/images/second-prize-trophy.jpg
- assets/images/third-prize-trophy.jpg
# - images/a_dot_burr.jpeg
# - images/a_dot_ham.jpeg

Expand Down

0 comments on commit 572999c

Please sign in to comment.