Skip to content

Commit

Permalink
Add game of other category
Browse files Browse the repository at this point in the history
  • Loading branch information
FaizFk committed Jan 9, 2023
1 parent a2af2e2 commit 46c8b2a
Show file tree
Hide file tree
Showing 3 changed files with 72 additions and 55 deletions.
123 changes: 70 additions & 53 deletions live_score_flutter_app/lib/screens/admin_screen.dart
Original file line number Diff line number Diff line change
Expand Up @@ -9,9 +9,14 @@ import 'package:provider/provider.dart';
import '../models/game.dart';
import 'edit_game_screen.dart';

class AdminScreen extends StatelessWidget {
class AdminScreen extends StatefulWidget {
static const id = 'adminscreen';

@override
State<AdminScreen> createState() => _AdminScreenState();
}

class _AdminScreenState extends State<AdminScreen> {
@override
Widget build(BuildContext context) {
return Scaffold(
Expand All @@ -37,7 +42,15 @@ class AdminScreen extends StatelessWidget {
builder: (context, snapshot) {
if (snapshot.hasData) {
return Text.rich(
TextSpan(style:const TextStyle(color:Colors.black),children: [const TextSpan(text:"Hello, "),TextSpan(text:"${snapshot.data?.name}",style:const TextStyle(fontSize: 25.0))]),
TextSpan(
style: const TextStyle(color: Colors.black),
children: [
const TextSpan(text: "Hello, "),
TextSpan(
text: "${snapshot.data?.name}",
style:
const TextStyle(fontSize: 25.0))
]),
);
} else {
return const Text('Hello Loading...');
Expand Down Expand Up @@ -86,31 +99,37 @@ class AdminScreen extends StatelessWidget {
),
),
FutureBuilder(
future: Provider.of<GamesAdminProvider>(context,listen: false).getAdminGames,
future: Provider.of<GamesAdminProvider>(context, listen: false)
.getAdminGames,
builder: (context, snapshot) {
if (snapshot.hasData) {
return Expanded(
child: ListView.builder(
itemCount: snapshot.data?.length,
itemBuilder: (context, index) => GameCard(
game: snapshot.data![index],
isAdminCard: true,
onPressed: () {
Provider.of<GamesAdminProvider>(context,
listen: false)
.setCurrentGame(snapshot.data![index]);
Map<String, Game> args = {
'game': snapshot.data![index]
};
Navigator.pushNamed(context, EditGameScreen.id,
arguments: args);
},
if (snapshot.connectionState == ConnectionState.done) {
if (snapshot.hasData) {
List<Game> gamesList=snapshot.data??[];
gamesList.sort((a,b) => -1*a.createdOn.compareTo(b.createdOn));
return Expanded(
child: ListView.builder(
itemCount: gamesList.length,
itemBuilder: (context, index) => GameCard(
game: gamesList[index],
isAdminCard: true,
onPressed: () {
Provider.of<GamesAdminProvider>(context,
listen: false)
.setCurrentGame(gamesList[index]);
Map<String, Game> args = {
'game': gamesList[index]
};
Navigator.pushNamed(context, EditGameScreen.id,
arguments: args).then((value){setState(() {

});});
},
),
),
),
);
} else {
return const Center(child: CircularProgressIndicator());
);
}
}
return const Center(child: CircularProgressIndicator());
}),
],
),
Expand All @@ -132,37 +151,35 @@ class _AnnouncementDialogBoxState extends State<AnnouncementDialogBox> {
super.dispose();
}


@override
Widget build(BuildContext context) {
return AlertDialog(
icon: const Icon(Icons.announcement),
title: TextField(
controller: messageController,
autofocus: true,
decoration: const InputDecoration(hintText: "Enter your message"),
),
actions: [
TextButton(
onPressed: () {
Navigator.pop(context);
},
child: const Text('Cancel')),
TextButton(
onPressed: () async {
showDialog(
context: context,
barrierDismissible: false,
builder: (context) => const Center(
child: CircularProgressIndicator(),
));
await Provider.of<GamesAdminProvider>(context,
listen: false)
.addAnnouncement(messageController.text);
Navigator.popUntil(context, ModalRoute.withName('adminscreen'));
},
child: const Text('Announce'))
],
);
icon: const Icon(Icons.announcement),
title: TextField(
controller: messageController,
autofocus: true,
decoration: const InputDecoration(hintText: "Enter your message"),
),
actions: [
TextButton(
onPressed: () {
Navigator.pop(context);
},
child: const Text('Cancel')),
TextButton(
onPressed: () async {
showDialog(
context: context,
barrierDismissible: false,
builder: (context) => const Center(
child: CircularProgressIndicator(),
));
await Provider.of<GamesAdminProvider>(context, listen: false)
.addAnnouncement(messageController.text);
Navigator.popUntil(context, ModalRoute.withName('adminscreen'));
},
child: const Text('Announce'))
],
);
}
}
2 changes: 1 addition & 1 deletion live_score_flutter_app/lib/screens/create_game_screen.dart
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ class _CreateGameScreenState extends State<CreateGameScreen> {

String selectedItem = 'Football ⚽';

List<String> gamesList = ['Football ⚽', 'Cricket 🏏', 'Tennis 🎾'];
List<String> gamesList = ['Football ⚽', 'Cricket 🏏', 'Tennis 🎾','Other ❓'];

@override
Widget build(BuildContext context) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ class _PreviousGameDetailsScreenState extends State<PreviousGameDetailsScreen> {
const TextStyle(fontSize: 25, fontWeight: FontWeight.w700),
),
const SizedBox(width: 10.0),
Expanded(
Flexible(
child: Text(
'${widget.game.winner} 🏆',
style:
Expand Down

0 comments on commit 46c8b2a

Please sign in to comment.