Skip to content

Commit 6ff6b23

Browse files
committed
modified hand ball stats
1 parent ad39163 commit 6ff6b23

File tree

10 files changed

+626
-99
lines changed

10 files changed

+626
-99
lines changed

lib/apis/Apis.dart

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -63,4 +63,11 @@ class Apis {
6363
static String addBlog = "${apiUrl}blogs/add";
6464
static String updateBlog = "${apiUrl}blogs/edit";
6565
static String deleteBlog = "${apiUrl}blogs/delete";
66+
67+
// hand ball stats
68+
static String addHandBallStats = "${apiUrl}handBall/add";
69+
static String getHandBallStats = "${apiUrl}handBall/get/";
70+
static String updateHandBallStats = "${apiUrl}handBall/update/";
71+
static String deleteHandBallStats = "${apiUrl}handBall/delete/";
72+
static String fetchHandBallPlayer = "${apiUrl}handBall/player/";
6673
}
Lines changed: 43 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,43 @@
1+
import 'package:samba_stats/services/player_service.dart';
2+
3+
import '../models/handball_player_model.dart';
4+
import '/exports/exports.dart';
5+
6+
class PlayerController with ChangeNotifier {
7+
// fetching single hand ball data
8+
HandBallPlayerModel _handBallData = HandBallPlayerModel(
9+
id: '',
10+
league: '',
11+
player: '',
12+
shirtNo: '',
13+
to: 0,
14+
gls: 0,
15+
ast: 0,
16+
mx: 0,
17+
blk: 0,
18+
ste: 0,
19+
ks: 0,
20+
twoMin: 0,
21+
rc: 0,
22+
createdAt: DateTime.now(),
23+
updatedAt: DateTime.now(),
24+
v: 0,
25+
);
26+
HandBallPlayerModel get handBallData => _handBallData;
27+
Future<void> fetchSingleHandBallPlayer(
28+
String playerId, String leagueId) async {
29+
PlayerService.getHandBallPlayers(playerId: playerId, leagueId: leagueId)
30+
.then((result) {
31+
_handBallData = result;
32+
notifyListeners();
33+
});
34+
}
35+
36+
// handle loading
37+
bool _isLoading = false;
38+
bool get isLoading => _isLoading;
39+
set isLoading(bool val) {
40+
_isLoading = val;
41+
notifyListeners();
42+
}
43+
}

lib/main.dart

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@
66
import 'package:flutter/services.dart';
77
import 'controllers/fixture_controller.dart';
88
import 'controllers/match_date_controller.dart';
9+
import 'controllers/player_controller.dart';
910
import 'theme/Theme.dart';
1011

1112
import '/exports/exports.dart';
@@ -58,6 +59,9 @@ void main() async {
5859
ChangeNotifierProvider(
5960
create: (_) => FixtureController(),
6061
),
62+
ChangeNotifierProvider(
63+
create: (_) => PlayerController(),
64+
),
6165
],
6266
child: Consumer<AppController>(
6367
builder: (context, controller, child) {
Lines changed: 84 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,84 @@
1+
import 'dart:convert';
2+
3+
HandBallPlayerModel handBallPlayerModelFromJson(String str) =>
4+
HandBallPlayerModel.fromJson(json.decode(str));
5+
6+
String handBallPlayerModelToJson(HandBallPlayerModel data) =>
7+
json.encode(data.toJson());
8+
9+
class HandBallPlayerModel {
10+
final String id;
11+
final String league;
12+
final String player;
13+
final String shirtNo;
14+
final int to;
15+
final int gls;
16+
final int ast;
17+
final int mx;
18+
final int blk;
19+
final int ste;
20+
final int ks;
21+
final int twoMin;
22+
final int rc;
23+
final DateTime createdAt;
24+
final DateTime updatedAt;
25+
final int v;
26+
27+
HandBallPlayerModel({
28+
required this.id,
29+
required this.league,
30+
required this.player,
31+
required this.shirtNo,
32+
required this.to,
33+
required this.gls,
34+
required this.ast,
35+
required this.mx,
36+
required this.blk,
37+
required this.ste,
38+
required this.ks,
39+
required this.twoMin,
40+
required this.rc,
41+
required this.createdAt,
42+
required this.updatedAt,
43+
required this.v,
44+
});
45+
46+
factory HandBallPlayerModel.fromJson(Map<String, dynamic> json) =>
47+
HandBallPlayerModel(
48+
id: json["_id"],
49+
league: json["league"],
50+
player: json["player"],
51+
shirtNo: json["shirtNo"],
52+
to: json["TO"],
53+
gls: json["GLS"],
54+
ast: json["AST"],
55+
mx: json["MX"],
56+
blk: json["BLK"],
57+
ste: json["STE"],
58+
ks: json["KS"],
59+
twoMin: json["TWO_MIN"],
60+
rc: json["RC"],
61+
createdAt: DateTime.parse(json["createdAt"]),
62+
updatedAt: DateTime.parse(json["updatedAt"]),
63+
v: json["__v"],
64+
);
65+
66+
Map<String, dynamic> toJson() => {
67+
"_id": id,
68+
"league": league,
69+
"player": player,
70+
"shirtNo": shirtNo,
71+
"TO": to,
72+
"GLS": gls,
73+
"AST": ast,
74+
"MX": mx,
75+
"BLK": blk,
76+
"STE": ste,
77+
"KS": ks,
78+
"TWO_MIN": twoMin,
79+
"RC": rc,
80+
"createdAt": createdAt.toIso8601String(),
81+
"updatedAt": updatedAt.toIso8601String(),
82+
"__v": v,
83+
};
84+
}

lib/services/player_service.dart

Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
import 'dart:convert';
22
import '../exports/exports.dart';
3+
import '../models/handball_player_model.dart';
34
import '../models/player.dart';
45

56
class PlayerService {
@@ -228,4 +229,41 @@ class PlayerService {
228229
debugPrint(e.message);
229230
}
230231
}
232+
233+
// get hand ball player data
234+
static Future<HandBallPlayerModel> getHandBallPlayers(
235+
{required String playerId, required String leagueId}) async {
236+
try {
237+
final response = await Client().get(
238+
Uri.parse("${Apis.fetchHandBallPlayer}$playerId/$leagueId"),
239+
);
240+
if (response.statusCode == 200) {
241+
Client().close();
242+
return handBallPlayerModelFromJson(response.body);
243+
} else {
244+
Client().close();
245+
return Future.error(jsonDecode(response.body)['message']);
246+
}
247+
} on Exception catch (e) {
248+
Client().close();
249+
return Future.error(e.toString());
250+
}
251+
}
252+
253+
// update player data
254+
static Future<bool> updateHandBallPlayer(Map<String, dynamic> data) async {
255+
try {
256+
Response response =
257+
await Client().post(Uri.parse(Apis.addHandBallStats), body: data);
258+
259+
if (response.statusCode == 200) {
260+
showMessage(msg: "Done..");
261+
return Future.value(true);
262+
} else {
263+
return Future.error(false);
264+
}
265+
} on ClientException catch (e) {
266+
return Future.error(false);
267+
}
268+
}
231269
}

lib/views/pages/sections/players/Players.dart

Lines changed: 33 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,9 @@ import 'dart:async';
22
import 'dart:developer';
33

44
// import '../teamPages/player_options.dart';
5+
import 'package:samba_stats/views/pages/sections/widgets/hand_ball_options.dart';
6+
7+
import '../../test.dart';
58
import '/exports/exports.dart';
69
import '/models/player.dart';
710
import '/services/player_service.dart';
@@ -181,14 +184,36 @@ class _PlayersState extends State<Players> with TickerProviderStateMixin {
181184
},
182185
trailing: IconButton(
183186
onPressed: () {
184-
showModalSheet(
185-
POptions(
186-
player: snap.data![index],
187-
teamId: widget.teamId!,
188-
leagueId: widget.leagueId!,
189-
),
190-
controller: _controller,
191-
);
187+
String league1 = "667a7dfe69692a12fae2c2a9";
188+
String league2 = "667a7d9769692a12fae2c16b";
189+
if (widget.leagueId != null) {
190+
if (widget.leagueId == league2 ||
191+
widget.leagueId == league1) {
192+
showModalSheet(
193+
POptions(
194+
player: snap.data![index],
195+
teamId: widget.teamId!,
196+
leagueId: widget.leagueId!,
197+
),
198+
controller: _controller,
199+
);
200+
// Routes.animateToPage(
201+
// HandBallOptions(
202+
// playerId: snap.data![index].id,
203+
// leagueId: widget.leagueId!,
204+
// ),
205+
// );
206+
} else {
207+
showModalSheet(
208+
POptions(
209+
player: snap.data![index],
210+
teamId: widget.teamId!,
211+
leagueId: widget.leagueId!,
212+
),
213+
controller: _controller,
214+
);
215+
}
216+
}
192217
},
193218
icon: const Icon(Icons.edit_rounded),
194219
),

lib/views/pages/sections/table_data/edit_table.dart

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -103,6 +103,8 @@ class _EditTableState extends State<EditTable> {
103103
],
104104
),
105105
),
106-
);
106+
107+
)
108+
;
107109
}
108110
}

0 commit comments

Comments
 (0)