Skip to content

Commit

Permalink
Merge branch 'dscpesu:main' into main
Browse files Browse the repository at this point in the history
  • Loading branch information
Abhay-N-J authored Oct 14, 2023
2 parents d449a4c + 53fef9c commit 43f6ff6
Show file tree
Hide file tree
Showing 9 changed files with 114 additions and 62 deletions.
5 changes: 4 additions & 1 deletion android/app/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ plugins {
id "com.android.application"
id "kotlin-android"
id "dev.flutter.flutter-gradle-plugin"
id 'com.google.gms.google-services'
}

def localProperties = new Properties()
Expand Down Expand Up @@ -64,4 +65,6 @@ flutter {
source '../..'
}

dependencies {}
dependencies {
implementation(platform("com.google.firebase:firebase-bom:32.3.1"))
}
29 changes: 29 additions & 0 deletions android/app/google-services.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
{
"project_info": {
"project_number": "460920808849",
"project_id": "pes-buzz",
"storage_bucket": "pes-buzz.appspot.com"
},
"client": [
{
"client_info": {
"mobilesdk_app_id": "1:460920808849:android:c42126dc99119d1992a630",
"android_client_info": {
"package_name": "com.example.pesbuzz"
}
},
"oauth_client": [],
"api_key": [
{
"current_key": "AIzaSyBUCUxxOF-2piBk4nn8Za2oa2Uq7bDDe7Q"
}
],
"services": {
"appinvite_service": {
"other_platform_oauth_client": []
}
}
}
],
"configuration_version": "1"
}
1 change: 1 addition & 0 deletions android/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ buildscript {
dependencies {
classpath 'com.android.tools.build:gradle:7.3.0'
classpath "org.jetbrains.kotlin:kotlin-gradle-plugin:$kotlin_version"
classpath 'com.google.gms:google-services:4.3.13'
}
}

Expand Down
5 changes: 4 additions & 1 deletion lib/main.dart
Original file line number Diff line number Diff line change
@@ -1,7 +1,10 @@
import 'package:flutter/material.dart';
import 'package:pesbuzz/screens/splash_screen.dart';
import 'package:firebase_core/firebase_core.dart';

void main() {
void main() async {
WidgetsFlutterBinding.ensureInitialized();
await Firebase.initializeApp();
runApp(MyApp());
}

Expand Down
63 changes: 4 additions & 59 deletions lib/screens/home_screen.dart
Original file line number Diff line number Diff line change
@@ -1,66 +1,12 @@
import 'package:flutter/material.dart';
import '/models/news_item_model.dart';
import 'package:pesbuzz/widgets/list_view_builder_tab.dart';
import '/widgets/display_firestore_data.dart';

class HomeScreen extends StatefulWidget {
@override
_HomeScreenState createState() => _HomeScreenState();
}

class _HomeScreenState extends State<HomeScreen> {
final List<NewsItemModel> newsItems = [
NewsItemModel(
id: '1',
date: 'October 15, 2023',
headline: 'Kodikon 3.0',
clubName: 'Embrione',
description: 'Join us for the annual college hackathon!',
category: 'Trendy',
imageUrl:
'https://yt3.googleusercontent.com/aEjE7dcPEV6WGjqSN8oY8ckgKjm5tv2TSwL0lhJVhy9_3NM3WIUfDzuie6DVLggwLEJ3etM3=s900-c-k-c0x00ffffff-no-rj',
),
NewsItemModel(
id: '2',
date: 'October 16, 2023',
headline: 'Hallothon',
clubName: 'Hallothon',
description: 'Join us for the annual college hackathon!',
category: 'Trendy',
imageUrl:
'https://yt3.googleusercontent.com/aEjE7dcPEV6WGjqSN8oY8ckgKjm5tv2TSwL0lhJVhy9_3NM3WIUfDzuie6DVLggwLEJ3etM3=s900-c-k-c0x00ffffff-no-rj',
),
NewsItemModel(
id: '3',
date: 'October 20, 2023',
headline: 'Cricket Tournament Finals',
clubName: 'Sports Club',
description: 'Join us for the annual sports hackathon!',
category: 'Sports',
imageUrl:
'https://yt3.googleusercontent.com/aEjE7dcPEV6WGjqSN8oY8ckgKjm5tv2TSwL0lhJVhy9_3NM3WIUfDzuie6DVLggwLEJ3etM3=s900-c-k-c0x00ffffff-no-rj',
),
NewsItemModel(
id: '4',
date: 'October 25, 2023',
headline: 'ISA 1 review',
clubName: 'CSE',
description: 'Join us for the annual college ISA review',
category: 'Department',
imageUrl:
'https://yt3.googleusercontent.com/aEjE7dcPEV6WGjqSN8oY8ckgKjm5tv2TSwL0lhJVhy9_3NM3WIUfDzuie6DVLggwLEJ3etM3=s900-c-k-c0x00ffffff-no-rj',
),
NewsItemModel(
id: '5',
date: 'October 26, 2023',
headline: 'ISA 1 review',
clubName: 'ECE',
description: 'Join us for the annual college ISA review',
category: 'Department',
imageUrl:
'https://yt3.googleusercontent.com/aEjE7dcPEV6WGjqSN8oY8ckgKjm5tv2TSwL0lhJVhy9_3NM3WIUfDzuie6DVLggwLEJ3etM3=s900-c-k-c0x00ffffff-no-rj',
),
];

PageController pageController = PageController();
int currentIndex = 0;

Expand All @@ -69,7 +15,6 @@ class _HomeScreenState extends State<HomeScreen> {
return Scaffold(
appBar: AppBar(
title: const Text('PES Buzz'),
centerTitle: true,
backgroundColor: const Color(0xFF4169E1),
),
body: PageView(
Expand All @@ -80,9 +25,9 @@ class _HomeScreenState extends State<HomeScreen> {
});
},
children: <Widget>[
ListViewBuilderByTab(category: 'Trendy', newsItems: newsItems),
ListViewBuilderByTab(category: 'Sports', newsItems: newsItems),
ListViewBuilderByTab(category: 'Department', newsItems: newsItems),
DisplayFirestoreData(category: 'Trendy'),
DisplayFirestoreData(category: 'Sports'),
DisplayFirestoreData(category: 'Department'),
],
),
bottomNavigationBar: BottomNavigationBar(
Expand Down
27 changes: 27 additions & 0 deletions lib/services/firestore_service.dart
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
import 'package:cloud_firestore/cloud_firestore.dart';
import '/models/news_item_model.dart';

class FirestoreService {
final FirebaseFirestore _firestore = FirebaseFirestore.instance;

Future<List<NewsItemModel>> fetchNewsItemsByCategory(String category) async {
final snapshot = await _firestore
.collection('news-items')
.where('category', isEqualTo: category)
.get();

final newsItems = snapshot.docs.map((doc) {
return NewsItemModel(
id: doc.id,
date: doc['date'],
headline: doc['headline'],
clubName: doc['clubName'],
description: doc['description'],
category: doc['category'],
imageUrl: doc['imageUrl'],
);
}).toList();

return newsItems;
}
}
34 changes: 34 additions & 0 deletions lib/widgets/display_firestore_data.dart
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
import 'package:flutter/material.dart';
import '/models/news_item_model.dart';
import '/services/firestore_service.dart';
import '/widgets/list_view_builder_tab.dart';
import 'package:flutter_spinkit/flutter_spinkit.dart';

class DisplayFirestoreData extends StatelessWidget {
final FirestoreService firestoreService = FirestoreService();
final String category;

DisplayFirestoreData({required this.category});

@override
Widget build(BuildContext context) {
return FutureBuilder<List<NewsItemModel>>(
future: firestoreService.fetchNewsItemsByCategory(category),
builder: (context, snapshot) {
if (snapshot.connectionState == ConnectionState.waiting) {
return (const Center(
child: SpinKitDualRing(
color: Color(0xFF4169E1),
size: 30.0,
),
));
} else if (snapshot.data == null) {
return const Center(child: Text('An error occurred.'));
} else {
return ListViewBuilderByTab(
category: category, newsItems: snapshot.data!);
}
},
);
}
}
10 changes: 9 additions & 1 deletion pubspec.lock
Original file line number Diff line number Diff line change
Expand Up @@ -114,7 +114,7 @@ packages:
source: hosted
version: "2.1.0"
firebase_core:
dependency: transitive
dependency: "direct main"
description:
name: firebase_core
sha256: "95580fa07c8ca3072a2bb1fecd792616a33f8683477d25b7d29d3a6a399e6ece"
Expand Down Expand Up @@ -150,6 +150,14 @@ packages:
url: "https://pub.dev"
source: hosted
version: "2.0.3"
flutter_spinkit:
dependency: "direct main"
description:
name: flutter_spinkit
sha256: b39c753e909d4796906c5696a14daf33639a76e017136c8d82bf3e620ce5bb8e
url: "https://pub.dev"
source: hosted
version: "5.2.0"
flutter_test:
dependency: "direct dev"
description: flutter
Expand Down
2 changes: 2 additions & 0 deletions pubspec.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,9 @@ dependencies:
# Use with the CupertinoIcons class for iOS style icons.
cupertino_icons: ^1.0.2
google_fonts: ^6.1.0
firebase_core: ^2.17.0
cloud_firestore: ^4.9.3
flutter_spinkit: ^5.2.0
another_flutter_splash_screen: ^1.2.0

dev_dependencies:
Expand Down

0 comments on commit 43f6ff6

Please sign in to comment.