Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Did some UI #16

Open
wants to merge 9 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
91 changes: 81 additions & 10 deletions live_score_flutter_app/README.md
Original file line number Diff line number Diff line change
@@ -1,16 +1,87 @@
# live_score_flutter_app
# Live Score Flutter App
<p align="center">
<img src="https://github.com/FaizFk/Live-Score-App/blob/dev/live_score_flutter_app/Screenshots/live_score_icon.png?raw=true" width="23%"></img>
</p>

A new Flutter project.
Many times a lot of games like cricket, football, badminton are occuing in your college but you are very lazy to attend these live or maybe you are at your home or not available at college and unfortunately you have to miss these events and its thrill.
But now no need to be disheartened, Live Score App will not only let you know the live score but also see its highlights moments. You will also get notified for the upcoming games in your college or any other college. You can take a look at the previous games too.
Made using Firebase and Flutter

## Getting Started
## Features

This project is a starting point for a Flutter application.
- **Ongoing Section:** View the score and highlights live
<p align="center">
<img src="https://github.com/FaizFk/Live-Score-App/blob/dev/live_score_flutter_app/Screenshots/ongoing.jpg?raw=true" width="23%"></img>
<img src="https://github.com/FaizFk/Live-Score-App/blob/dev/live_score_flutter_app/Screenshots/ongoing-details.jpg?raw=true" width="23%"></img>
</p>

A few resources to get you started if this is your first Flutter project:

- [Lab: Write your first Flutter app](https://docs.flutter.dev/get-started/codelab)
- [Cookbook: Useful Flutter samples](https://docs.flutter.dev/cookbook)

For help getting started with Flutter development, view the
[online documentation](https://docs.flutter.dev/), which offers tutorials,
samples, guidance on mobile development, and a full API reference.
- **Previous Section:** View the score, highlights and winner of the previous games

<p align="center">
<img src="https://github.com/FaizFk/Live-Score-App/blob/dev/live_score_flutter_app/Screenshots/previous.jpg?raw=true" width="23%"></img>
<img src="https://github.com/FaizFk/Live-Score-App/blob/dev/live_score_flutter_app/Screenshots/previous-details.jpg?raw=true" width="23%"></img>
</p>

- **Announcement Section:** Get notified about the upcoming games as well as choose to subscribe to your interest college notifications

<p align="center">
<img src="https://github.com/FaizFk/Live-Score-App/blob/dev/live_score_flutter_app/Screenshots/announcements.jpg?raw=true" width="23%"></img>
<img src="https://github.com/FaizFk/Live-Score-App/blob/dev/live_score_flutter_app/Screenshots/announcement-settings.jpg?raw=true" width="23%"></img>
</p>

- **Authentication Section:** Login or signup to create games
<p align="center">
<img src="https://github.com/FaizFk/Live-Score-App/blob/dev/live_score_flutter_app/Screenshots/login.jpg?raw=true" width="23%"></img>
<img src="https://github.com/FaizFk/Live-Score-App/blob/dev/live_score_flutter_app/Screenshots/signup.jpg?raw=true" width="23%"></img>
</p>

- **Admin Section:** Create games occuring in your college and update its score accordingly. You can also choose to notify users about upcoming games

<p align="center">
<img src="https://github.com/FaizFk/Live-Score-App/blob/dev/live_score_flutter_app/Screenshots/admin-screen.jpg?raw=true" width="23%"></img>
<img src="https://github.com/FaizFk/Live-Score-App/blob/dev/live_score_flutter_app/Screenshots/score-controller.jpg?raw=true" width="23%"></img>
<img src="https://github.com/FaizFk/Live-Score-App/blob/dev/live_score_flutter_app/Screenshots/create-game.jpg?raw=true" width="23%"></img>
</p>


# Demo Video

Here is the demo video of working of this app: [Watch the Video](https://youtu.be/RqpSwHATNSU)

## How to Run

1. Download or Clone the repo
2. Install all the packages by typing the following command into your terminal

```sh
flutter pub get
```
3. Go to [games-admin-provider](lib/providers/games_admin_provider.dart) file and replace **${dotenv.env["SERVER_KEY"]}** with the firebase server key

```dart
Future<void> sendNotificationToDevices(
String title, String body, String topic) async {
await http.post(Uri.parse('https://fcm.googleapis.com/fcm/send'),
headers: <String, String>{
'Content-Type': 'application/json',
'Authorization': 'key=${dotenv.env["SERVER_KEY"]}',
},
body: jsonEncode({
"condition": "'$topic' in topics || 'All' in topics",
'notification': {
'android_channel_id': 'pushnotificationapp',
'title': title,
'body': body,
},
}));
}
```

### Apk link:
[Live Score Apk Download](https://drive.google.com/file/d/15Oe7inzXqqoRK0KAg_L7alOm9GaOZX8C/view?usp=share_link)

## Contact

- [Faiz Khan](https://github.com/FaizFk/) | [LinkedIn](https://linkedin.com/in/faiz-khan-4793731ba/)
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
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 live_score_flutter_app/Screenshots/login.jpg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
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 live_score_flutter_app/Screenshots/ongoing.jpg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
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 live_score_flutter_app/Screenshots/previous.jpg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
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 live_score_flutter_app/Screenshots/signup.jpg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.example.live_score_flutter_app">
<application
android:label="live_score_flutter_app"
android:label="Live Score"
android:name="${applicationName}"
android:icon="@mipmap/ic_launcher">
<activity
Expand Down
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
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 live_score_flutter_app/assets/login_bg.png
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 live_score_flutter_app/assets/signup_bg.png
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 live_score_flutter_app/assets/sports_auth.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
5 changes: 3 additions & 2 deletions live_score_flutter_app/lib/main.dart
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,6 @@ import 'firebase_options.dart';
import 'package:firebase_messaging/firebase_messaging.dart';
import 'notificationservice/local_notification_service.dart';


Future<void> backgroundHandler(RemoteMessage message) async {
print(message.data.toString());
print(message.notification!.title);
Expand Down Expand Up @@ -74,13 +73,15 @@ class _MyAppState extends State<MyApp> {
}
},
);

//Subscribing to topic 'All' if first installing the app
GameUsersProvider.subscribeToAllIfFirstTime();
}

// This widget is the root of your application.
@override
Widget build(BuildContext context) {
bool isAuth = FirebaseAuth.instance.currentUser != null;

return MultiProvider(
providers: [
ChangeNotifierProvider(create: (context) => GamesAdminProvider()),
Expand Down
54 changes: 30 additions & 24 deletions live_score_flutter_app/lib/providers/games_admin_provider.dart
Original file line number Diff line number Diff line change
Expand Up @@ -32,16 +32,15 @@ class GamesAdminProvider extends ChangeNotifier {
notifyListeners();
}

Future<void> sendNotificationToDevices(String title, String body) async {
Future<void> sendNotificationToDevices(
String title, String body, String topic) async {
await http.post(Uri.parse('https://fcm.googleapis.com/fcm/send'),
headers: <String, String>{
'Content-Type': 'application/json',
'Authorization': 'key=${dotenv.env["SERVER_KEY"]}',
},
body: jsonEncode({
"registration_ids": [
"f63uvo1ORx-dMmGaZkkO3w:APA91bH4Js6NtsmiFvEWAYHDk_1MWsKAsJYtp621i5QnHBxwnq6otIjhTH52raY4iOW4_juE--BPj2rpBVRdG1krUdR4t8YWN1JBAonQLBTVxd1RMz7FvhYypij6yLELZye67SsIt3WW"
],
"condition": "'$topic' in topics || 'All' in topics",
'notification': {
'android_channel_id': 'pushnotificationapp',
'title': title,
Expand All @@ -64,7 +63,10 @@ class GamesAdminProvider extends ChangeNotifier {
id: myDoc.id,
);
await myDoc.set(announcement.toJson());
await sendNotificationToDevices('${announcement.creatorName} (${announcement.collegeName})', announcement.message);
await sendNotificationToDevices(
'${announcement.creatorName} (${announcement.collegeName})',
announcement.message,
announcement.collegeName.replaceAll(' ', ''));
Utils.showSnackbar('Your message was announced');
} catch (e) {
print(e);
Expand Down Expand Up @@ -117,28 +119,32 @@ class GamesAdminProvider extends ChangeNotifier {

Future<void> changeScore(
{bool isIncrease = true, bool isScore1 = true}) async {
if (isScore1) {
if (isIncrease) {
await _dbOngoingGamesRT
.child('${currentGame.id}/score1')
.set(++_currentGame.score1);
} else {
await _dbOngoingGamesRT
.child('${currentGame.id}/score1')
.set(_currentGame.score1 > 0 ? --_currentGame.score1 : 0);
}
} else {
if (isIncrease) {
await _dbOngoingGamesRT
.child('${currentGame.id}/score2')
.set(++_currentGame.score2);
try {
if (isScore1) {
if (isIncrease) {
await _dbOngoingGamesRT
.child('${currentGame.id}/score1')
.set(++_currentGame.score1);
} else {
await _dbOngoingGamesRT
.child('${currentGame.id}/score1')
.set(_currentGame.score1 > 0 ? --_currentGame.score1 : 0);
}
} else {
await _dbOngoingGamesRT
.child('${currentGame.id}/score2')
.set((_currentGame.score2) > 0 ? --_currentGame.score2 : 0);
if (isIncrease) {
await _dbOngoingGamesRT
.child('${currentGame.id}/score2')
.set(++_currentGame.score2);
} else {
await _dbOngoingGamesRT
.child('${currentGame.id}/score2')
.set((_currentGame.score2) > 0 ? --_currentGame.score2 : 0);
}
}
notifyListeners();
} catch (e) {
Utils.showSnackbar('Please check your internet connection');
}
notifyListeners();
}

Future<void> sendKeyMoments(String message) async {
Expand Down
76 changes: 69 additions & 7 deletions live_score_flutter_app/lib/providers/games_users_provider.dart
Original file line number Diff line number Diff line change
Expand Up @@ -95,14 +95,76 @@ class GameUsersProvider extends ChangeNotifier {

Future<List<String>> getAllCollegesOngoing() async {
List<String> collegeList = [];
final snapshotGames = await _dbOngoingGamesRT.get();
if (snapshotGames.exists) {
Map<dynamic, dynamic> result =
snapshotGames.value as Map<dynamic, dynamic>;
collegeList = List<String>.from(result.values.map((e) {
return e['college'];
}).toSet());
try {
final snapshotGames = await _dbOngoingGamesRT.get();
if (snapshotGames.exists) {
Map<dynamic, dynamic> result =
snapshotGames.value as Map<dynamic, dynamic>;
collegeList = List<String>.from(result.values.map((e) {
return e['college'];
}).toSet());
}
} catch (e) {
Utils.showSnackbar("Something went wrong");
}
return collegeList;
}

Future<Map<String, bool>> getAllColleges() async {
Map<String, bool> collegeMap = {};
List<String> collegeList = [];
try {
final snapshotUsers = await _dbUsers.get();
if (snapshotUsers.size > 0) {
collegeList = List<String>.from(
snapshotUsers.docs.map((e) => e['collegeName']).toSet());
}
for (String college in ['All', ...collegeList]) {
collegeMap[college] = await isSubscribedToCollege(college);
}
} catch (e) {
print(e);
Utils.showSnackbar('Something went wrong, Check your network connection');
}
return collegeMap;
}

static Future<void> subscribeToAllIfFirstTime() async {
try {
final pref = await SharedPreferences.getInstance();
if (pref.getBool('All') == null) {
await FirebaseMessaging.instance.subscribeToTopic('All');
await pref.setBool('All', true);
}
} catch (e) {
print(e);
Utils.showSnackbar('something went wrong');
}
}

Future<void> subscribeToCollege(bool value, String college) async {
college = college.replaceAll(' ', '');
try {
final pref = await SharedPreferences.getInstance();
if (value) {
await FirebaseMessaging.instance.subscribeToTopic(college);
await pref.setBool(college, true);
} else {
await FirebaseMessaging.instance.unsubscribeFromTopic(college);
await pref.setBool(college, false);
}
} catch (e) {
print(e);
Utils.showSnackbar(
"Can't subscribe to the college. Check your connection");
}
}

Future<bool> isSubscribedToCollege(String college) async {
college = college.replaceAll(' ', '');
bool isSubscribed = false;
final pref = await SharedPreferences.getInstance();
isSubscribed = pref.getBool(college) ?? false;
return isSubscribed;
}
}
Loading