Skip to content

Commit

Permalink
Merge pull request #32 from ShubhKanodia/main
Browse files Browse the repository at this point in the history
Spinkit fixed, minor architecture, UI changes
  • Loading branch information
ShubhKanodia authored Oct 28, 2023
2 parents 2a344ba + d922c03 commit 408a681
Show file tree
Hide file tree
Showing 10 changed files with 330 additions and 98 deletions.
4 changes: 3 additions & 1 deletion lib/main.dart
Original file line number Diff line number Diff line change
Expand Up @@ -7,10 +7,12 @@ void main() async {
WidgetsFlutterBinding.ensureInitialized();
await Firebase.initializeApp(); // Initialize Firebase here

runApp(MyApp());
runApp(const MyApp());
}

class MyApp extends StatelessWidget {
const MyApp({super.key});

@override
Widget build(BuildContext context) {
return MaterialApp(
Expand Down
148 changes: 72 additions & 76 deletions lib/screens/home_screen.dart
Original file line number Diff line number Diff line change
@@ -1,8 +1,12 @@
import 'package:flutter/material.dart';
import 'package:font_awesome_flutter/font_awesome_flutter.dart';
import 'package:google_fonts/google_fonts.dart';
import '/widgets/display_firestore_data.dart';
import '/widgets/bottom_bar.dart';

class HomeScreen extends StatefulWidget {
const HomeScreen({super.key});

@override
_HomeScreenState createState() => _HomeScreenState();
}
Expand All @@ -11,53 +15,39 @@ class _HomeScreenState extends State<HomeScreen> {
PageController pageController = PageController();
int currentIndex = 0;

String _getMonth(int month) {
switch (month) {
case 1:
return 'January';
case 2:
return 'February';
case 3:
return 'March';
case 4:
return 'April';
case 5:
return 'May';
case 6:
return 'June';
case 7:
return 'July';
case 8:
return 'August';
case 9:
return 'September';
case 10:
return 'October';
case 11:
return 'November';
case 12:
return 'December';
default:
return 'Unknown';
}
//Callback to handle when bottom bar is tapped - the below function is passed as a parameter to bottom_bar.dart
void onTabTapped(int index) {
setState(() {
currentIndex = index;
pageController.animateToPage(
index,
duration: const Duration(milliseconds: 20),
curve: Curves.ease,
);
});
}

@override
Widget build(BuildContext context) {
return Scaffold(
appBar: AppBar(
backgroundColor: const Color(0xffE2F9EE),
leadingWidth: 65,
leadingWidth: 100,
leading: const Padding(
padding: EdgeInsets.only(left: 5.0),
child: Image(image: AssetImage('assets/logos/PesBuzzLogo.png')),
padding: EdgeInsets.only(left: 0),
child: Image(
image: AssetImage(
'assets/logos/PesBuzzLogo.png',
)),
),
title: const Text(
title: Text(
'PES Buzz',
style: TextStyle(
color: Colors.black,
fontWeight: FontWeight.bold,
fontSize: 28,
style: GoogleFonts.poppins(
textStyle: const TextStyle(
color: Colors.black,
fontSize: 30,
fontWeight: FontWeight.bold,
),
),
),
actions: [
Expand All @@ -73,13 +63,16 @@ class _HomeScreenState extends State<HomeScreen> {
body: Container(
decoration: const BoxDecoration(
gradient: LinearGradient(
begin: Alignment.topCenter,
end: Alignment.bottomCenter,
colors: [
Color(0xffE2F9EE),
Color(0xffFBFBD4),
],
),
begin: Alignment.topCenter,
end: Alignment.bottomCenter,
colors: [
Color(0xffE2F9EE),
Color.fromARGB(255, 218, 229, 194),
],
stops: [
0.25,
1.0
]),
),
child: Column(
crossAxisAlignment: CrossAxisAlignment.start,
Expand All @@ -103,7 +96,7 @@ class _HomeScreenState extends State<HomeScreen> {
currentIndex = index;
});
},
children: <Widget>[
children: const <Widget>[
DisplayFirestoreData(category: 'Trendy'),
DisplayFirestoreData(category: 'Sports'),
DisplayFirestoreData(category: 'Department'),
Expand All @@ -113,39 +106,42 @@ class _HomeScreenState extends State<HomeScreen> {
],
),
),
bottomNavigationBar: BottomNavigationBar(
unselectedItemColor: Colors.blueGrey,
selectedItemColor: Colors.black,
//BottomBar is now under bottom_bar.dart in widgets folder
bottomNavigationBar: BottomBar(
currentIndex: currentIndex,
onTap: (index) {
setState(() {
currentIndex = index;
pageController.animateToPage(
index,
duration: const Duration(milliseconds: 500),
curve: Curves.ease,
);
});
},
items: const [
BottomNavigationBarItem(
icon: Icon(Icons.trending_up),
label: 'Trendy',
),
BottomNavigationBarItem(
icon: Icon(Icons.sports_soccer),
label: 'Sports',
),
BottomNavigationBarItem(
icon: Icon(Icons.school),
label: 'Department',
),
BottomNavigationBarItem(
icon: Icon(Icons.bookmark_outline),
label: 'Bookmarks',
),
],
onTabTapped: onTabTapped,
),
);
}

String _getMonth(int month) {
switch (month) {
case 1:
return 'January';
case 2:
return 'February';
case 3:
return 'March';
case 4:
return 'April';
case 5:
return 'May';
case 6:
return 'June';
case 7:
return 'July';
case 8:
return 'August';
case 9:
return 'September';
case 10:
return 'October';
case 11:
return 'November';
case 12:
return 'December';
default:
return 'Unknown';
}
}
}
2 changes: 1 addition & 1 deletion lib/screens/splash_screen.dart
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ class _SplashScreenState extends State<SplashScreen> {
void _navigateToNextScreen() {
Navigator.of(context).pushReplacement(
PageRouteBuilder(
pageBuilder: (context, animation, secondaryAnimation) => HomeScreen(),
pageBuilder: (context, animation, secondaryAnimation) => const HomeScreen(),
transitionsBuilder: (context, animation, secondaryAnimation, child) {
const begin = Offset(1.0, 0.0);
const end = Offset.zero;
Expand Down
57 changes: 57 additions & 0 deletions lib/widgets/bottom_bar.dart
Original file line number Diff line number Diff line change
@@ -0,0 +1,57 @@
import 'package:flutter/material.dart';

class BottomBar extends StatelessWidget {
final int currentIndex;
final Function(int) onTabTapped;

const BottomBar(
{Key? key, required this.currentIndex, required this.onTabTapped})
: super(key: key);

@override
Widget build(BuildContext context) {
return BottomNavigationBar(
type: BottomNavigationBarType
.fixed, // Ensure the labels are always displayed
backgroundColor: Color.fromARGB(255, 34, 30, 30),
unselectedItemColor: Colors.blueGrey,
selectedItemColor: Colors.white,
currentIndex: currentIndex,
onTap: onTabTapped,
items: const [
BottomNavigationBarItem(
icon: Padding(
padding: EdgeInsets.only(top: 10.0),
child: Icon(Icons.trending_up),
),
label: 'Trendy',
),
BottomNavigationBarItem(
icon: Padding(
padding: EdgeInsets.only(top: 10.0),
child: Icon(Icons.calendar_month_outlined),
),
label: 'Events',
),
BottomNavigationBarItem(
icon: Padding(
padding: EdgeInsets.only(top: 10.0),
child: Icon(Icons.school),
),
label: 'Department',
),
BottomNavigationBarItem(
icon: Padding(
padding: EdgeInsets.only(top: 10.0),
child: Icon(Icons.bookmark_outline),
),
label: 'Bookmarks',
),
],
);
}
}



// Color.fromARGB(255, 34, 30, 30),
47 changes: 30 additions & 17 deletions lib/widgets/display_firestore_data.dart
Original file line number Diff line number Diff line change
Expand Up @@ -4,30 +4,43 @@ 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();
class DisplayFirestoreData extends StatefulWidget {
final String category;

DisplayFirestoreData({required this.category});
const DisplayFirestoreData({super.key, required this.category});

@override
State<DisplayFirestoreData> createState() => _DisplayFirestoreDataState();
}

class _DisplayFirestoreDataState extends State<DisplayFirestoreData> {
final FirestoreService firestoreService = FirestoreService();

@override
Widget build(BuildContext context) {
return FutureBuilder<List<NewsItemModel>>(
future: firestoreService.fetchNewsItemsByCategory(category),
future: firestoreService.fetchNewsItemsByCategory(widget.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!);
}
return AnimatedSwitcher(
duration: const Duration(milliseconds: 300),
child: snapshot.connectionState == ConnectionState.waiting
? Center(
key: UniqueKey(), //
child: const SpinKitDualRing(
color: Colors.black,
size: 30.0,
),
)
: snapshot.hasError
? Center(
key: UniqueKey(), // Use UniqueKey for the error widget
child: Text('An error occurred: ${snapshot.error}'),
)
: ListViewBuilderByTab(
category: widget.category,
newsItems: snapshot.data ?? [],
),
);
},
);
}
Expand Down
2 changes: 1 addition & 1 deletion lib/widgets/list_view_builder_tab.dart
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ class ListViewBuilderByTab extends StatelessWidget {
final String category;
final List<NewsItemModel> newsItems;

ListViewBuilderByTab({required this.category, required this.newsItems});
const ListViewBuilderByTab({super.key, required this.category, required this.newsItems});

@override
Widget build(BuildContext context) {
Expand Down
2 changes: 2 additions & 0 deletions macos/Flutter/GeneratedPluginRegistrant.swift
Original file line number Diff line number Diff line change
Expand Up @@ -8,9 +8,11 @@ import Foundation
import cloud_firestore
import firebase_core
import path_provider_foundation
import sqflite

func RegisterGeneratedPlugins(registry: FlutterPluginRegistry) {
FLTFirebaseFirestorePlugin.register(with: registry.registrar(forPlugin: "FLTFirebaseFirestorePlugin"))
FLTFirebaseCorePlugin.register(with: registry.registrar(forPlugin: "FLTFirebaseCorePlugin"))
PathProviderPlugin.register(with: registry.registrar(forPlugin: "PathProviderPlugin"))
SqflitePlugin.register(with: registry.registrar(forPlugin: "SqflitePlugin"))
}
Loading

0 comments on commit 408a681

Please sign in to comment.