From c7c50b8ecf86b9d53f13c4210355567b6cdf2ba7 Mon Sep 17 00:00:00 2001 From: sidhdhi canopas Date: Thu, 5 Dec 2024 10:30:00 +0530 Subject: [PATCH 1/5] record match event and partnership --- data/lib/api/ball_score/ball_score_model.dart | 4 +- .../api/match_event/match_event_model.dart | 98 ++ .../match_event_model.freezed.dart | 985 ++++++++++++++++++ .../api/match_event/match_event_model.g.dart | 143 +++ .../api/partnership/partnership_model.dart | 48 + .../partnership_model.freezed.dart | 619 +++++++++++ .../api/partnership/partnership_model.g.dart | 61 ++ .../ball_score/ball_score_service.dart | 3 +- .../match_event/match_event_service.dart | 54 + .../partnership/partnership_service.dart | 55 + .../utils/constant/firestore_constant.dart | 2 + .../score_board/score_board_view_model.dart | 326 ++++++ 12 files changed, 2395 insertions(+), 3 deletions(-) create mode 100644 data/lib/api/match_event/match_event_model.dart create mode 100644 data/lib/api/match_event/match_event_model.freezed.dart create mode 100644 data/lib/api/match_event/match_event_model.g.dart create mode 100644 data/lib/api/partnership/partnership_model.dart create mode 100644 data/lib/api/partnership/partnership_model.freezed.dart create mode 100644 data/lib/api/partnership/partnership_model.g.dart create mode 100644 data/lib/service/match_event/match_event_service.dart create mode 100644 data/lib/service/partnership/partnership_service.dart diff --git a/data/lib/api/ball_score/ball_score_model.dart b/data/lib/api/ball_score/ball_score_model.dart index 0e588ba3..1cd20e4d 100644 --- a/data/lib/api/ball_score/ball_score_model.dart +++ b/data/lib/api/ball_score/ball_score_model.dart @@ -285,7 +285,9 @@ class ExtraSummary with _$ExtraSummary { }) = _ExtraSummary; } -extension BallScoreModelBoolean on BallScoreModel? { +extension BallScoreModelData on BallScoreModel? { + double get formattedOver => double.parse("${(this?.over_number ?? 1) - 1}.${this?.ball_number ?? 0}"); + bool? isLegalDelivery() { if (this == null) { return null; diff --git a/data/lib/api/match_event/match_event_model.dart b/data/lib/api/match_event/match_event_model.dart new file mode 100644 index 00000000..cf14e3a2 --- /dev/null +++ b/data/lib/api/match_event/match_event_model.dart @@ -0,0 +1,98 @@ +// ignore_for_file: non_constant_identifier_names + +import 'package:cloud_firestore/cloud_firestore.dart'; +import 'package:freezed_annotation/freezed_annotation.dart'; + +import '../../converter/timestamp_json_converter.dart'; +import '../ball_score/ball_score_model.dart'; + +part 'match_event_model.freezed.dart'; +part 'match_event_model.g.dart'; + +@Freezed() +class MatchEventModel with _$MatchEventModel { + @JsonSerializable(anyMap: true, explicitToJson: true, includeIfNull: false) + const factory MatchEventModel({ + required String id, + required String match_id, + required String inning_id, + required EventType type, + String? bowler_id, + @Default([]) List ball_ids, + @Default([]) List wickets, + @Default([]) List milestone, + @TimeStampJsonConverter() required DateTime time, + String? batsman_id, + @Default(0) double over, + FieldingPositionType? fielding_position, + + }) = _MatchEventModel; + + factory MatchEventModel.fromJson(Map json) => + _$MatchEventModelFromJson(json); + + factory MatchEventModel.fromFireStore( + DocumentSnapshot> snapshot, + SnapshotOptions? options, + ) => + MatchEventModel.fromJson(snapshot.data()!); +} + +@JsonEnum(valueField: "value") +enum EventType { + hatTrick(1), + century(2), + fifty(3), + wicket(4), + six(5), + four(6); + + final int value; + + const EventType(this.value); +} + +@freezed +class MatchEventWicket with _$MatchEventWicket { + @JsonSerializable(anyMap: true, explicitToJson: true) + const factory MatchEventWicket({ + @TimeStampJsonConverter() required DateTime time, + required String ball_id, + required String batsman_id, + required WicketType wicket_type, + required double over, + String? wicket_taker_id, + }) = _MatchEventWicket; + + factory MatchEventWicket.fromJson(Map json) => + _$MatchEventWicketFromJson(json); + + factory MatchEventWicket.fromFireStore( + DocumentSnapshot> snapshot, + SnapshotOptions? options, + ) => + MatchEventWicket.fromJson(snapshot.data()!); +} + +@freezed +class MatchEventMilestone with _$MatchEventMilestone { + @JsonSerializable(anyMap: true, explicitToJson: true) + const factory MatchEventMilestone({ + @TimeStampJsonConverter() required DateTime time, + required String ball_id, + @Default(0.0) double over, + @Default(0) int runs, + @Default(0) int ball_faced, + @Default(0) int fours, + @Default(0) int sixes, + }) = _MatchEventMilestone; + + factory MatchEventMilestone.fromJson(Map json) => + _$MatchEventMilestoneFromJson(json); + + factory MatchEventMilestone.fromFireStore( + DocumentSnapshot> snapshot, + SnapshotOptions? options, + ) => + MatchEventMilestone.fromJson(snapshot.data()!); +} \ No newline at end of file diff --git a/data/lib/api/match_event/match_event_model.freezed.dart b/data/lib/api/match_event/match_event_model.freezed.dart new file mode 100644 index 00000000..82402fd3 --- /dev/null +++ b/data/lib/api/match_event/match_event_model.freezed.dart @@ -0,0 +1,985 @@ +// coverage:ignore-file +// GENERATED CODE - DO NOT MODIFY BY HAND +// ignore_for_file: type=lint +// ignore_for_file: unused_element, deprecated_member_use, deprecated_member_use_from_same_package, use_function_type_syntax_for_parameters, unnecessary_const, avoid_init_to_null, invalid_override_different_default_values_named, prefer_expression_function_bodies, annotate_overrides, invalid_annotation_target, unnecessary_question_mark + +part of 'match_event_model.dart'; + +// ************************************************************************** +// FreezedGenerator +// ************************************************************************** + +T _$identity(T value) => value; + +final _privateConstructorUsedError = UnsupportedError( + 'It seems like you constructed your class using `MyClass._()`. This constructor is only meant to be used by freezed and you are not supposed to need it nor use it.\nPlease check the documentation here for more information: https://github.com/rrousselGit/freezed#adding-getters-and-methods-to-our-models'); + +MatchEventModel _$MatchEventModelFromJson(Map json) { + return _MatchEventModel.fromJson(json); +} + +/// @nodoc +mixin _$MatchEventModel { + String get id => throw _privateConstructorUsedError; + String get match_id => throw _privateConstructorUsedError; + String get inning_id => throw _privateConstructorUsedError; + EventType get type => throw _privateConstructorUsedError; + String? get bowler_id => throw _privateConstructorUsedError; + List get ball_ids => throw _privateConstructorUsedError; + List get wickets => throw _privateConstructorUsedError; + List get milestone => throw _privateConstructorUsedError; + @TimeStampJsonConverter() + DateTime get time => throw _privateConstructorUsedError; + String? get batsman_id => throw _privateConstructorUsedError; + double get over => throw _privateConstructorUsedError; + FieldingPositionType? get fielding_position => + throw _privateConstructorUsedError; + + /// Serializes this MatchEventModel to a JSON map. + Map toJson() => throw _privateConstructorUsedError; + + /// Create a copy of MatchEventModel + /// with the given fields replaced by the non-null parameter values. + @JsonKey(includeFromJson: false, includeToJson: false) + $MatchEventModelCopyWith get copyWith => + throw _privateConstructorUsedError; +} + +/// @nodoc +abstract class $MatchEventModelCopyWith<$Res> { + factory $MatchEventModelCopyWith( + MatchEventModel value, $Res Function(MatchEventModel) then) = + _$MatchEventModelCopyWithImpl<$Res, MatchEventModel>; + @useResult + $Res call( + {String id, + String match_id, + String inning_id, + EventType type, + String? bowler_id, + List ball_ids, + List wickets, + List milestone, + @TimeStampJsonConverter() DateTime time, + String? batsman_id, + double over, + FieldingPositionType? fielding_position}); +} + +/// @nodoc +class _$MatchEventModelCopyWithImpl<$Res, $Val extends MatchEventModel> + implements $MatchEventModelCopyWith<$Res> { + _$MatchEventModelCopyWithImpl(this._value, this._then); + + // ignore: unused_field + final $Val _value; + // ignore: unused_field + final $Res Function($Val) _then; + + /// Create a copy of MatchEventModel + /// with the given fields replaced by the non-null parameter values. + @pragma('vm:prefer-inline') + @override + $Res call({ + Object? id = null, + Object? match_id = null, + Object? inning_id = null, + Object? type = null, + Object? bowler_id = freezed, + Object? ball_ids = null, + Object? wickets = null, + Object? milestone = null, + Object? time = null, + Object? batsman_id = freezed, + Object? over = null, + Object? fielding_position = freezed, + }) { + return _then(_value.copyWith( + id: null == id + ? _value.id + : id // ignore: cast_nullable_to_non_nullable + as String, + match_id: null == match_id + ? _value.match_id + : match_id // ignore: cast_nullable_to_non_nullable + as String, + inning_id: null == inning_id + ? _value.inning_id + : inning_id // ignore: cast_nullable_to_non_nullable + as String, + type: null == type + ? _value.type + : type // ignore: cast_nullable_to_non_nullable + as EventType, + bowler_id: freezed == bowler_id + ? _value.bowler_id + : bowler_id // ignore: cast_nullable_to_non_nullable + as String?, + ball_ids: null == ball_ids + ? _value.ball_ids + : ball_ids // ignore: cast_nullable_to_non_nullable + as List, + wickets: null == wickets + ? _value.wickets + : wickets // ignore: cast_nullable_to_non_nullable + as List, + milestone: null == milestone + ? _value.milestone + : milestone // ignore: cast_nullable_to_non_nullable + as List, + time: null == time + ? _value.time + : time // ignore: cast_nullable_to_non_nullable + as DateTime, + batsman_id: freezed == batsman_id + ? _value.batsman_id + : batsman_id // ignore: cast_nullable_to_non_nullable + as String?, + over: null == over + ? _value.over + : over // ignore: cast_nullable_to_non_nullable + as double, + fielding_position: freezed == fielding_position + ? _value.fielding_position + : fielding_position // ignore: cast_nullable_to_non_nullable + as FieldingPositionType?, + ) as $Val); + } +} + +/// @nodoc +abstract class _$$MatchEventModelImplCopyWith<$Res> + implements $MatchEventModelCopyWith<$Res> { + factory _$$MatchEventModelImplCopyWith(_$MatchEventModelImpl value, + $Res Function(_$MatchEventModelImpl) then) = + __$$MatchEventModelImplCopyWithImpl<$Res>; + @override + @useResult + $Res call( + {String id, + String match_id, + String inning_id, + EventType type, + String? bowler_id, + List ball_ids, + List wickets, + List milestone, + @TimeStampJsonConverter() DateTime time, + String? batsman_id, + double over, + FieldingPositionType? fielding_position}); +} + +/// @nodoc +class __$$MatchEventModelImplCopyWithImpl<$Res> + extends _$MatchEventModelCopyWithImpl<$Res, _$MatchEventModelImpl> + implements _$$MatchEventModelImplCopyWith<$Res> { + __$$MatchEventModelImplCopyWithImpl( + _$MatchEventModelImpl _value, $Res Function(_$MatchEventModelImpl) _then) + : super(_value, _then); + + /// Create a copy of MatchEventModel + /// with the given fields replaced by the non-null parameter values. + @pragma('vm:prefer-inline') + @override + $Res call({ + Object? id = null, + Object? match_id = null, + Object? inning_id = null, + Object? type = null, + Object? bowler_id = freezed, + Object? ball_ids = null, + Object? wickets = null, + Object? milestone = null, + Object? time = null, + Object? batsman_id = freezed, + Object? over = null, + Object? fielding_position = freezed, + }) { + return _then(_$MatchEventModelImpl( + id: null == id + ? _value.id + : id // ignore: cast_nullable_to_non_nullable + as String, + match_id: null == match_id + ? _value.match_id + : match_id // ignore: cast_nullable_to_non_nullable + as String, + inning_id: null == inning_id + ? _value.inning_id + : inning_id // ignore: cast_nullable_to_non_nullable + as String, + type: null == type + ? _value.type + : type // ignore: cast_nullable_to_non_nullable + as EventType, + bowler_id: freezed == bowler_id + ? _value.bowler_id + : bowler_id // ignore: cast_nullable_to_non_nullable + as String?, + ball_ids: null == ball_ids + ? _value._ball_ids + : ball_ids // ignore: cast_nullable_to_non_nullable + as List, + wickets: null == wickets + ? _value._wickets + : wickets // ignore: cast_nullable_to_non_nullable + as List, + milestone: null == milestone + ? _value._milestone + : milestone // ignore: cast_nullable_to_non_nullable + as List, + time: null == time + ? _value.time + : time // ignore: cast_nullable_to_non_nullable + as DateTime, + batsman_id: freezed == batsman_id + ? _value.batsman_id + : batsman_id // ignore: cast_nullable_to_non_nullable + as String?, + over: null == over + ? _value.over + : over // ignore: cast_nullable_to_non_nullable + as double, + fielding_position: freezed == fielding_position + ? _value.fielding_position + : fielding_position // ignore: cast_nullable_to_non_nullable + as FieldingPositionType?, + )); + } +} + +/// @nodoc + +@JsonSerializable(anyMap: true, explicitToJson: true, includeIfNull: false) +class _$MatchEventModelImpl implements _MatchEventModel { + const _$MatchEventModelImpl( + {required this.id, + required this.match_id, + required this.inning_id, + required this.type, + this.bowler_id, + final List ball_ids = const [], + final List wickets = const [], + final List milestone = const [], + @TimeStampJsonConverter() required this.time, + this.batsman_id, + this.over = 0, + this.fielding_position}) + : _ball_ids = ball_ids, + _wickets = wickets, + _milestone = milestone; + + factory _$MatchEventModelImpl.fromJson(Map json) => + _$$MatchEventModelImplFromJson(json); + + @override + final String id; + @override + final String match_id; + @override + final String inning_id; + @override + final EventType type; + @override + final String? bowler_id; + final List _ball_ids; + @override + @JsonKey() + List get ball_ids { + if (_ball_ids is EqualUnmodifiableListView) return _ball_ids; + // ignore: implicit_dynamic_type + return EqualUnmodifiableListView(_ball_ids); + } + + final List _wickets; + @override + @JsonKey() + List get wickets { + if (_wickets is EqualUnmodifiableListView) return _wickets; + // ignore: implicit_dynamic_type + return EqualUnmodifiableListView(_wickets); + } + + final List _milestone; + @override + @JsonKey() + List get milestone { + if (_milestone is EqualUnmodifiableListView) return _milestone; + // ignore: implicit_dynamic_type + return EqualUnmodifiableListView(_milestone); + } + + @override + @TimeStampJsonConverter() + final DateTime time; + @override + final String? batsman_id; + @override + @JsonKey() + final double over; + @override + final FieldingPositionType? fielding_position; + + @override + String toString() { + return 'MatchEventModel(id: $id, match_id: $match_id, inning_id: $inning_id, type: $type, bowler_id: $bowler_id, ball_ids: $ball_ids, wickets: $wickets, milestone: $milestone, time: $time, batsman_id: $batsman_id, over: $over, fielding_position: $fielding_position)'; + } + + @override + bool operator ==(Object other) { + return identical(this, other) || + (other.runtimeType == runtimeType && + other is _$MatchEventModelImpl && + (identical(other.id, id) || other.id == id) && + (identical(other.match_id, match_id) || + other.match_id == match_id) && + (identical(other.inning_id, inning_id) || + other.inning_id == inning_id) && + (identical(other.type, type) || other.type == type) && + (identical(other.bowler_id, bowler_id) || + other.bowler_id == bowler_id) && + const DeepCollectionEquality().equals(other._ball_ids, _ball_ids) && + const DeepCollectionEquality().equals(other._wickets, _wickets) && + const DeepCollectionEquality() + .equals(other._milestone, _milestone) && + (identical(other.time, time) || other.time == time) && + (identical(other.batsman_id, batsman_id) || + other.batsman_id == batsman_id) && + (identical(other.over, over) || other.over == over) && + (identical(other.fielding_position, fielding_position) || + other.fielding_position == fielding_position)); + } + + @JsonKey(includeFromJson: false, includeToJson: false) + @override + int get hashCode => Object.hash( + runtimeType, + id, + match_id, + inning_id, + type, + bowler_id, + const DeepCollectionEquality().hash(_ball_ids), + const DeepCollectionEquality().hash(_wickets), + const DeepCollectionEquality().hash(_milestone), + time, + batsman_id, + over, + fielding_position); + + /// Create a copy of MatchEventModel + /// with the given fields replaced by the non-null parameter values. + @JsonKey(includeFromJson: false, includeToJson: false) + @override + @pragma('vm:prefer-inline') + _$$MatchEventModelImplCopyWith<_$MatchEventModelImpl> get copyWith => + __$$MatchEventModelImplCopyWithImpl<_$MatchEventModelImpl>( + this, _$identity); + + @override + Map toJson() { + return _$$MatchEventModelImplToJson( + this, + ); + } +} + +abstract class _MatchEventModel implements MatchEventModel { + const factory _MatchEventModel( + {required final String id, + required final String match_id, + required final String inning_id, + required final EventType type, + final String? bowler_id, + final List ball_ids, + final List wickets, + final List milestone, + @TimeStampJsonConverter() required final DateTime time, + final String? batsman_id, + final double over, + final FieldingPositionType? fielding_position}) = _$MatchEventModelImpl; + + factory _MatchEventModel.fromJson(Map json) = + _$MatchEventModelImpl.fromJson; + + @override + String get id; + @override + String get match_id; + @override + String get inning_id; + @override + EventType get type; + @override + String? get bowler_id; + @override + List get ball_ids; + @override + List get wickets; + @override + List get milestone; + @override + @TimeStampJsonConverter() + DateTime get time; + @override + String? get batsman_id; + @override + double get over; + @override + FieldingPositionType? get fielding_position; + + /// Create a copy of MatchEventModel + /// with the given fields replaced by the non-null parameter values. + @override + @JsonKey(includeFromJson: false, includeToJson: false) + _$$MatchEventModelImplCopyWith<_$MatchEventModelImpl> get copyWith => + throw _privateConstructorUsedError; +} + +MatchEventWicket _$MatchEventWicketFromJson(Map json) { + return _MatchEventWicket.fromJson(json); +} + +/// @nodoc +mixin _$MatchEventWicket { + @TimeStampJsonConverter() + DateTime get time => throw _privateConstructorUsedError; + String get ball_id => throw _privateConstructorUsedError; + String get batsman_id => throw _privateConstructorUsedError; + WicketType get wicket_type => throw _privateConstructorUsedError; + double get over => throw _privateConstructorUsedError; + String? get wicket_taker_id => throw _privateConstructorUsedError; + + /// Serializes this MatchEventWicket to a JSON map. + Map toJson() => throw _privateConstructorUsedError; + + /// Create a copy of MatchEventWicket + /// with the given fields replaced by the non-null parameter values. + @JsonKey(includeFromJson: false, includeToJson: false) + $MatchEventWicketCopyWith get copyWith => + throw _privateConstructorUsedError; +} + +/// @nodoc +abstract class $MatchEventWicketCopyWith<$Res> { + factory $MatchEventWicketCopyWith( + MatchEventWicket value, $Res Function(MatchEventWicket) then) = + _$MatchEventWicketCopyWithImpl<$Res, MatchEventWicket>; + @useResult + $Res call( + {@TimeStampJsonConverter() DateTime time, + String ball_id, + String batsman_id, + WicketType wicket_type, + double over, + String? wicket_taker_id}); +} + +/// @nodoc +class _$MatchEventWicketCopyWithImpl<$Res, $Val extends MatchEventWicket> + implements $MatchEventWicketCopyWith<$Res> { + _$MatchEventWicketCopyWithImpl(this._value, this._then); + + // ignore: unused_field + final $Val _value; + // ignore: unused_field + final $Res Function($Val) _then; + + /// Create a copy of MatchEventWicket + /// with the given fields replaced by the non-null parameter values. + @pragma('vm:prefer-inline') + @override + $Res call({ + Object? time = null, + Object? ball_id = null, + Object? batsman_id = null, + Object? wicket_type = null, + Object? over = null, + Object? wicket_taker_id = freezed, + }) { + return _then(_value.copyWith( + time: null == time + ? _value.time + : time // ignore: cast_nullable_to_non_nullable + as DateTime, + ball_id: null == ball_id + ? _value.ball_id + : ball_id // ignore: cast_nullable_to_non_nullable + as String, + batsman_id: null == batsman_id + ? _value.batsman_id + : batsman_id // ignore: cast_nullable_to_non_nullable + as String, + wicket_type: null == wicket_type + ? _value.wicket_type + : wicket_type // ignore: cast_nullable_to_non_nullable + as WicketType, + over: null == over + ? _value.over + : over // ignore: cast_nullable_to_non_nullable + as double, + wicket_taker_id: freezed == wicket_taker_id + ? _value.wicket_taker_id + : wicket_taker_id // ignore: cast_nullable_to_non_nullable + as String?, + ) as $Val); + } +} + +/// @nodoc +abstract class _$$MatchEventWicketImplCopyWith<$Res> + implements $MatchEventWicketCopyWith<$Res> { + factory _$$MatchEventWicketImplCopyWith(_$MatchEventWicketImpl value, + $Res Function(_$MatchEventWicketImpl) then) = + __$$MatchEventWicketImplCopyWithImpl<$Res>; + @override + @useResult + $Res call( + {@TimeStampJsonConverter() DateTime time, + String ball_id, + String batsman_id, + WicketType wicket_type, + double over, + String? wicket_taker_id}); +} + +/// @nodoc +class __$$MatchEventWicketImplCopyWithImpl<$Res> + extends _$MatchEventWicketCopyWithImpl<$Res, _$MatchEventWicketImpl> + implements _$$MatchEventWicketImplCopyWith<$Res> { + __$$MatchEventWicketImplCopyWithImpl(_$MatchEventWicketImpl _value, + $Res Function(_$MatchEventWicketImpl) _then) + : super(_value, _then); + + /// Create a copy of MatchEventWicket + /// with the given fields replaced by the non-null parameter values. + @pragma('vm:prefer-inline') + @override + $Res call({ + Object? time = null, + Object? ball_id = null, + Object? batsman_id = null, + Object? wicket_type = null, + Object? over = null, + Object? wicket_taker_id = freezed, + }) { + return _then(_$MatchEventWicketImpl( + time: null == time + ? _value.time + : time // ignore: cast_nullable_to_non_nullable + as DateTime, + ball_id: null == ball_id + ? _value.ball_id + : ball_id // ignore: cast_nullable_to_non_nullable + as String, + batsman_id: null == batsman_id + ? _value.batsman_id + : batsman_id // ignore: cast_nullable_to_non_nullable + as String, + wicket_type: null == wicket_type + ? _value.wicket_type + : wicket_type // ignore: cast_nullable_to_non_nullable + as WicketType, + over: null == over + ? _value.over + : over // ignore: cast_nullable_to_non_nullable + as double, + wicket_taker_id: freezed == wicket_taker_id + ? _value.wicket_taker_id + : wicket_taker_id // ignore: cast_nullable_to_non_nullable + as String?, + )); + } +} + +/// @nodoc + +@JsonSerializable(anyMap: true, explicitToJson: true) +class _$MatchEventWicketImpl implements _MatchEventWicket { + const _$MatchEventWicketImpl( + {@TimeStampJsonConverter() required this.time, + required this.ball_id, + required this.batsman_id, + required this.wicket_type, + required this.over, + this.wicket_taker_id}); + + factory _$MatchEventWicketImpl.fromJson(Map json) => + _$$MatchEventWicketImplFromJson(json); + + @override + @TimeStampJsonConverter() + final DateTime time; + @override + final String ball_id; + @override + final String batsman_id; + @override + final WicketType wicket_type; + @override + final double over; + @override + final String? wicket_taker_id; + + @override + String toString() { + return 'MatchEventWicket(time: $time, ball_id: $ball_id, batsman_id: $batsman_id, wicket_type: $wicket_type, over: $over, wicket_taker_id: $wicket_taker_id)'; + } + + @override + bool operator ==(Object other) { + return identical(this, other) || + (other.runtimeType == runtimeType && + other is _$MatchEventWicketImpl && + (identical(other.time, time) || other.time == time) && + (identical(other.ball_id, ball_id) || other.ball_id == ball_id) && + (identical(other.batsman_id, batsman_id) || + other.batsman_id == batsman_id) && + (identical(other.wicket_type, wicket_type) || + other.wicket_type == wicket_type) && + (identical(other.over, over) || other.over == over) && + (identical(other.wicket_taker_id, wicket_taker_id) || + other.wicket_taker_id == wicket_taker_id)); + } + + @JsonKey(includeFromJson: false, includeToJson: false) + @override + int get hashCode => Object.hash(runtimeType, time, ball_id, batsman_id, + wicket_type, over, wicket_taker_id); + + /// Create a copy of MatchEventWicket + /// with the given fields replaced by the non-null parameter values. + @JsonKey(includeFromJson: false, includeToJson: false) + @override + @pragma('vm:prefer-inline') + _$$MatchEventWicketImplCopyWith<_$MatchEventWicketImpl> get copyWith => + __$$MatchEventWicketImplCopyWithImpl<_$MatchEventWicketImpl>( + this, _$identity); + + @override + Map toJson() { + return _$$MatchEventWicketImplToJson( + this, + ); + } +} + +abstract class _MatchEventWicket implements MatchEventWicket { + const factory _MatchEventWicket( + {@TimeStampJsonConverter() required final DateTime time, + required final String ball_id, + required final String batsman_id, + required final WicketType wicket_type, + required final double over, + final String? wicket_taker_id}) = _$MatchEventWicketImpl; + + factory _MatchEventWicket.fromJson(Map json) = + _$MatchEventWicketImpl.fromJson; + + @override + @TimeStampJsonConverter() + DateTime get time; + @override + String get ball_id; + @override + String get batsman_id; + @override + WicketType get wicket_type; + @override + double get over; + @override + String? get wicket_taker_id; + + /// Create a copy of MatchEventWicket + /// with the given fields replaced by the non-null parameter values. + @override + @JsonKey(includeFromJson: false, includeToJson: false) + _$$MatchEventWicketImplCopyWith<_$MatchEventWicketImpl> get copyWith => + throw _privateConstructorUsedError; +} + +MatchEventMilestone _$MatchEventMilestoneFromJson(Map json) { + return _MatchEventMilestone.fromJson(json); +} + +/// @nodoc +mixin _$MatchEventMilestone { + @TimeStampJsonConverter() + DateTime get time => throw _privateConstructorUsedError; + String get ball_id => throw _privateConstructorUsedError; + double get over => throw _privateConstructorUsedError; + int get runs => throw _privateConstructorUsedError; + int get ball_faced => throw _privateConstructorUsedError; + int get fours => throw _privateConstructorUsedError; + int get sixes => throw _privateConstructorUsedError; + + /// Serializes this MatchEventMilestone to a JSON map. + Map toJson() => throw _privateConstructorUsedError; + + /// Create a copy of MatchEventMilestone + /// with the given fields replaced by the non-null parameter values. + @JsonKey(includeFromJson: false, includeToJson: false) + $MatchEventMilestoneCopyWith get copyWith => + throw _privateConstructorUsedError; +} + +/// @nodoc +abstract class $MatchEventMilestoneCopyWith<$Res> { + factory $MatchEventMilestoneCopyWith( + MatchEventMilestone value, $Res Function(MatchEventMilestone) then) = + _$MatchEventMilestoneCopyWithImpl<$Res, MatchEventMilestone>; + @useResult + $Res call( + {@TimeStampJsonConverter() DateTime time, + String ball_id, + double over, + int runs, + int ball_faced, + int fours, + int sixes}); +} + +/// @nodoc +class _$MatchEventMilestoneCopyWithImpl<$Res, $Val extends MatchEventMilestone> + implements $MatchEventMilestoneCopyWith<$Res> { + _$MatchEventMilestoneCopyWithImpl(this._value, this._then); + + // ignore: unused_field + final $Val _value; + // ignore: unused_field + final $Res Function($Val) _then; + + /// Create a copy of MatchEventMilestone + /// with the given fields replaced by the non-null parameter values. + @pragma('vm:prefer-inline') + @override + $Res call({ + Object? time = null, + Object? ball_id = null, + Object? over = null, + Object? runs = null, + Object? ball_faced = null, + Object? fours = null, + Object? sixes = null, + }) { + return _then(_value.copyWith( + time: null == time + ? _value.time + : time // ignore: cast_nullable_to_non_nullable + as DateTime, + ball_id: null == ball_id + ? _value.ball_id + : ball_id // ignore: cast_nullable_to_non_nullable + as String, + over: null == over + ? _value.over + : over // ignore: cast_nullable_to_non_nullable + as double, + runs: null == runs + ? _value.runs + : runs // ignore: cast_nullable_to_non_nullable + as int, + ball_faced: null == ball_faced + ? _value.ball_faced + : ball_faced // ignore: cast_nullable_to_non_nullable + as int, + fours: null == fours + ? _value.fours + : fours // ignore: cast_nullable_to_non_nullable + as int, + sixes: null == sixes + ? _value.sixes + : sixes // ignore: cast_nullable_to_non_nullable + as int, + ) as $Val); + } +} + +/// @nodoc +abstract class _$$MatchEventMilestoneImplCopyWith<$Res> + implements $MatchEventMilestoneCopyWith<$Res> { + factory _$$MatchEventMilestoneImplCopyWith(_$MatchEventMilestoneImpl value, + $Res Function(_$MatchEventMilestoneImpl) then) = + __$$MatchEventMilestoneImplCopyWithImpl<$Res>; + @override + @useResult + $Res call( + {@TimeStampJsonConverter() DateTime time, + String ball_id, + double over, + int runs, + int ball_faced, + int fours, + int sixes}); +} + +/// @nodoc +class __$$MatchEventMilestoneImplCopyWithImpl<$Res> + extends _$MatchEventMilestoneCopyWithImpl<$Res, _$MatchEventMilestoneImpl> + implements _$$MatchEventMilestoneImplCopyWith<$Res> { + __$$MatchEventMilestoneImplCopyWithImpl(_$MatchEventMilestoneImpl _value, + $Res Function(_$MatchEventMilestoneImpl) _then) + : super(_value, _then); + + /// Create a copy of MatchEventMilestone + /// with the given fields replaced by the non-null parameter values. + @pragma('vm:prefer-inline') + @override + $Res call({ + Object? time = null, + Object? ball_id = null, + Object? over = null, + Object? runs = null, + Object? ball_faced = null, + Object? fours = null, + Object? sixes = null, + }) { + return _then(_$MatchEventMilestoneImpl( + time: null == time + ? _value.time + : time // ignore: cast_nullable_to_non_nullable + as DateTime, + ball_id: null == ball_id + ? _value.ball_id + : ball_id // ignore: cast_nullable_to_non_nullable + as String, + over: null == over + ? _value.over + : over // ignore: cast_nullable_to_non_nullable + as double, + runs: null == runs + ? _value.runs + : runs // ignore: cast_nullable_to_non_nullable + as int, + ball_faced: null == ball_faced + ? _value.ball_faced + : ball_faced // ignore: cast_nullable_to_non_nullable + as int, + fours: null == fours + ? _value.fours + : fours // ignore: cast_nullable_to_non_nullable + as int, + sixes: null == sixes + ? _value.sixes + : sixes // ignore: cast_nullable_to_non_nullable + as int, + )); + } +} + +/// @nodoc + +@JsonSerializable(anyMap: true, explicitToJson: true) +class _$MatchEventMilestoneImpl implements _MatchEventMilestone { + const _$MatchEventMilestoneImpl( + {@TimeStampJsonConverter() required this.time, + required this.ball_id, + this.over = 0.0, + this.runs = 0, + this.ball_faced = 0, + this.fours = 0, + this.sixes = 0}); + + factory _$MatchEventMilestoneImpl.fromJson(Map json) => + _$$MatchEventMilestoneImplFromJson(json); + + @override + @TimeStampJsonConverter() + final DateTime time; + @override + final String ball_id; + @override + @JsonKey() + final double over; + @override + @JsonKey() + final int runs; + @override + @JsonKey() + final int ball_faced; + @override + @JsonKey() + final int fours; + @override + @JsonKey() + final int sixes; + + @override + String toString() { + return 'MatchEventMilestone(time: $time, ball_id: $ball_id, over: $over, runs: $runs, ball_faced: $ball_faced, fours: $fours, sixes: $sixes)'; + } + + @override + bool operator ==(Object other) { + return identical(this, other) || + (other.runtimeType == runtimeType && + other is _$MatchEventMilestoneImpl && + (identical(other.time, time) || other.time == time) && + (identical(other.ball_id, ball_id) || other.ball_id == ball_id) && + (identical(other.over, over) || other.over == over) && + (identical(other.runs, runs) || other.runs == runs) && + (identical(other.ball_faced, ball_faced) || + other.ball_faced == ball_faced) && + (identical(other.fours, fours) || other.fours == fours) && + (identical(other.sixes, sixes) || other.sixes == sixes)); + } + + @JsonKey(includeFromJson: false, includeToJson: false) + @override + int get hashCode => Object.hash( + runtimeType, time, ball_id, over, runs, ball_faced, fours, sixes); + + /// Create a copy of MatchEventMilestone + /// with the given fields replaced by the non-null parameter values. + @JsonKey(includeFromJson: false, includeToJson: false) + @override + @pragma('vm:prefer-inline') + _$$MatchEventMilestoneImplCopyWith<_$MatchEventMilestoneImpl> get copyWith => + __$$MatchEventMilestoneImplCopyWithImpl<_$MatchEventMilestoneImpl>( + this, _$identity); + + @override + Map toJson() { + return _$$MatchEventMilestoneImplToJson( + this, + ); + } +} + +abstract class _MatchEventMilestone implements MatchEventMilestone { + const factory _MatchEventMilestone( + {@TimeStampJsonConverter() required final DateTime time, + required final String ball_id, + final double over, + final int runs, + final int ball_faced, + final int fours, + final int sixes}) = _$MatchEventMilestoneImpl; + + factory _MatchEventMilestone.fromJson(Map json) = + _$MatchEventMilestoneImpl.fromJson; + + @override + @TimeStampJsonConverter() + DateTime get time; + @override + String get ball_id; + @override + double get over; + @override + int get runs; + @override + int get ball_faced; + @override + int get fours; + @override + int get sixes; + + /// Create a copy of MatchEventMilestone + /// with the given fields replaced by the non-null parameter values. + @override + @JsonKey(includeFromJson: false, includeToJson: false) + _$$MatchEventMilestoneImplCopyWith<_$MatchEventMilestoneImpl> get copyWith => + throw _privateConstructorUsedError; +} diff --git a/data/lib/api/match_event/match_event_model.g.dart b/data/lib/api/match_event/match_event_model.g.dart new file mode 100644 index 00000000..e996256a --- /dev/null +++ b/data/lib/api/match_event/match_event_model.g.dart @@ -0,0 +1,143 @@ +// GENERATED CODE - DO NOT MODIFY BY HAND + +part of 'match_event_model.dart'; + +// ************************************************************************** +// JsonSerializableGenerator +// ************************************************************************** + +_$MatchEventModelImpl _$$MatchEventModelImplFromJson(Map json) => + _$MatchEventModelImpl( + id: json['id'] as String, + match_id: json['match_id'] as String, + inning_id: json['inning_id'] as String, + type: $enumDecode(_$EventTypeEnumMap, json['type']), + bowler_id: json['bowler_id'] as String?, + ball_ids: (json['ball_ids'] as List?) + ?.map((e) => e as String) + .toList() ?? + const [], + wickets: (json['wickets'] as List?) + ?.map((e) => MatchEventWicket.fromJson( + Map.from(e as Map))) + .toList() ?? + const [], + milestone: (json['milestone'] as List?) + ?.map((e) => MatchEventMilestone.fromJson( + Map.from(e as Map))) + .toList() ?? + const [], + time: const TimeStampJsonConverter().fromJson(json['time'] as Object), + batsman_id: json['batsman_id'] as String?, + over: (json['over'] as num?)?.toDouble() ?? 0, + fielding_position: $enumDecodeNullable( + _$FieldingPositionTypeEnumMap, json['fielding_position']), + ); + +Map _$$MatchEventModelImplToJson( + _$MatchEventModelImpl instance) { + final val = { + 'id': instance.id, + 'match_id': instance.match_id, + 'inning_id': instance.inning_id, + 'type': _$EventTypeEnumMap[instance.type]!, + }; + + void writeNotNull(String key, dynamic value) { + if (value != null) { + val[key] = value; + } + } + + writeNotNull('bowler_id', instance.bowler_id); + val['ball_ids'] = instance.ball_ids; + val['wickets'] = instance.wickets.map((e) => e.toJson()).toList(); + val['milestone'] = instance.milestone.map((e) => e.toJson()).toList(); + val['time'] = const TimeStampJsonConverter().toJson(instance.time); + writeNotNull('batsman_id', instance.batsman_id); + val['over'] = instance.over; + writeNotNull('fielding_position', + _$FieldingPositionTypeEnumMap[instance.fielding_position]); + return val; +} + +const _$EventTypeEnumMap = { + EventType.hatTrick: 1, + EventType.century: 2, + EventType.fifty: 3, + EventType.wicket: 4, + EventType.six: 5, + EventType.four: 6, +}; + +const _$FieldingPositionTypeEnumMap = { + FieldingPositionType.deepMidWicket: 1, + FieldingPositionType.longOn: 2, + FieldingPositionType.longOff: 3, + FieldingPositionType.deepCover: 4, + FieldingPositionType.deepPoint: 5, + FieldingPositionType.thirdMan: 6, + FieldingPositionType.deepFineLeg: 7, + FieldingPositionType.deepSquareLeg: 8, +}; + +_$MatchEventWicketImpl _$$MatchEventWicketImplFromJson(Map json) => + _$MatchEventWicketImpl( + time: const TimeStampJsonConverter().fromJson(json['time'] as Object), + ball_id: json['ball_id'] as String, + batsman_id: json['batsman_id'] as String, + wicket_type: $enumDecode(_$WicketTypeEnumMap, json['wicket_type']), + over: (json['over'] as num).toDouble(), + wicket_taker_id: json['wicket_taker_id'] as String?, + ); + +Map _$$MatchEventWicketImplToJson( + _$MatchEventWicketImpl instance) => + { + 'time': const TimeStampJsonConverter().toJson(instance.time), + 'ball_id': instance.ball_id, + 'batsman_id': instance.batsman_id, + 'wicket_type': _$WicketTypeEnumMap[instance.wicket_type]!, + 'over': instance.over, + 'wicket_taker_id': instance.wicket_taker_id, + }; + +const _$WicketTypeEnumMap = { + WicketType.bowled: 1, + WicketType.caught: 2, + WicketType.caughtBehind: 3, + WicketType.caughtAndBowled: 4, + WicketType.lbw: 5, + WicketType.stumped: 6, + WicketType.runOut: 7, + WicketType.hitWicket: 8, + WicketType.hitBallTwice: 9, + WicketType.handledBall: 10, + WicketType.obstructingField: 11, + WicketType.timedOut: 12, + WicketType.retired: 13, + WicketType.retiredHurt: 14, +}; + +_$MatchEventMilestoneImpl _$$MatchEventMilestoneImplFromJson(Map json) => + _$MatchEventMilestoneImpl( + time: const TimeStampJsonConverter().fromJson(json['time'] as Object), + ball_id: json['ball_id'] as String, + over: (json['over'] as num?)?.toDouble() ?? 0.0, + runs: (json['runs'] as num?)?.toInt() ?? 0, + ball_faced: (json['ball_faced'] as num?)?.toInt() ?? 0, + fours: (json['fours'] as num?)?.toInt() ?? 0, + sixes: (json['sixes'] as num?)?.toInt() ?? 0, + ); + +Map _$$MatchEventMilestoneImplToJson( + _$MatchEventMilestoneImpl instance) => + { + 'time': const TimeStampJsonConverter().toJson(instance.time), + 'ball_id': instance.ball_id, + 'over': instance.over, + 'runs': instance.runs, + 'ball_faced': instance.ball_faced, + 'fours': instance.fours, + 'sixes': instance.sixes, + }; diff --git a/data/lib/api/partnership/partnership_model.dart b/data/lib/api/partnership/partnership_model.dart new file mode 100644 index 00000000..d27c8246 --- /dev/null +++ b/data/lib/api/partnership/partnership_model.dart @@ -0,0 +1,48 @@ +// ignore_for_file: non_constant_identifier_names + +import 'package:cloud_firestore/cloud_firestore.dart'; +import 'package:freezed_annotation/freezed_annotation.dart'; + +part 'partnership_model.freezed.dart'; +part 'partnership_model.g.dart'; + +@freezed +class PartnershipModel with _$PartnershipModel { + @JsonSerializable(anyMap: true, explicitToJson: true) + const factory PartnershipModel({ + required String id, + required String match_id, + required String inning_id, + required List player_ids, + @Default([]) List players, + @Default(0) int runs, + @Default(0) int extras, + @Default(0) int ball_faced, + @Default(0.0) double start_over, + @Default(0.0) double end_over, + }) = _PartnershipModel; + + factory PartnershipModel.fromJson(Map json) => + _$PartnershipModelFromJson(json); + + factory PartnershipModel.fromFireStore( + DocumentSnapshot> snapshot, + SnapshotOptions? options, + ) => + PartnershipModel.fromJson(snapshot.data()!); +} + +@freezed +class PartnershipPlayer with _$PartnershipPlayer { + @JsonSerializable(anyMap: true, explicitToJson: true) + const factory PartnershipPlayer({ + required String player_id, + @Default(0) int runs, + @Default(0) int ball_faced, + @Default(0) int fours, + @Default(0) int sixes, + }) = _PartnershipPlayer; + + factory PartnershipPlayer.fromJson(Map json) => + _$PartnershipPlayerFromJson(json); +} \ No newline at end of file diff --git a/data/lib/api/partnership/partnership_model.freezed.dart b/data/lib/api/partnership/partnership_model.freezed.dart new file mode 100644 index 00000000..4d425264 --- /dev/null +++ b/data/lib/api/partnership/partnership_model.freezed.dart @@ -0,0 +1,619 @@ +// coverage:ignore-file +// GENERATED CODE - DO NOT MODIFY BY HAND +// ignore_for_file: type=lint +// ignore_for_file: unused_element, deprecated_member_use, deprecated_member_use_from_same_package, use_function_type_syntax_for_parameters, unnecessary_const, avoid_init_to_null, invalid_override_different_default_values_named, prefer_expression_function_bodies, annotate_overrides, invalid_annotation_target, unnecessary_question_mark + +part of 'partnership_model.dart'; + +// ************************************************************************** +// FreezedGenerator +// ************************************************************************** + +T _$identity(T value) => value; + +final _privateConstructorUsedError = UnsupportedError( + 'It seems like you constructed your class using `MyClass._()`. This constructor is only meant to be used by freezed and you are not supposed to need it nor use it.\nPlease check the documentation here for more information: https://github.com/rrousselGit/freezed#adding-getters-and-methods-to-our-models'); + +PartnershipModel _$PartnershipModelFromJson(Map json) { + return _PartnershipModel.fromJson(json); +} + +/// @nodoc +mixin _$PartnershipModel { + String get id => throw _privateConstructorUsedError; + String get match_id => throw _privateConstructorUsedError; + String get inning_id => throw _privateConstructorUsedError; + List get player_ids => throw _privateConstructorUsedError; + List get players => throw _privateConstructorUsedError; + int get runs => throw _privateConstructorUsedError; + int get extras => throw _privateConstructorUsedError; + int get ball_faced => throw _privateConstructorUsedError; + double get start_over => throw _privateConstructorUsedError; + double get end_over => throw _privateConstructorUsedError; + + /// Serializes this PartnershipModel to a JSON map. + Map toJson() => throw _privateConstructorUsedError; + + /// Create a copy of PartnershipModel + /// with the given fields replaced by the non-null parameter values. + @JsonKey(includeFromJson: false, includeToJson: false) + $PartnershipModelCopyWith get copyWith => + throw _privateConstructorUsedError; +} + +/// @nodoc +abstract class $PartnershipModelCopyWith<$Res> { + factory $PartnershipModelCopyWith( + PartnershipModel value, $Res Function(PartnershipModel) then) = + _$PartnershipModelCopyWithImpl<$Res, PartnershipModel>; + @useResult + $Res call( + {String id, + String match_id, + String inning_id, + List player_ids, + List players, + int runs, + int extras, + int ball_faced, + double start_over, + double end_over}); +} + +/// @nodoc +class _$PartnershipModelCopyWithImpl<$Res, $Val extends PartnershipModel> + implements $PartnershipModelCopyWith<$Res> { + _$PartnershipModelCopyWithImpl(this._value, this._then); + + // ignore: unused_field + final $Val _value; + // ignore: unused_field + final $Res Function($Val) _then; + + /// Create a copy of PartnershipModel + /// with the given fields replaced by the non-null parameter values. + @pragma('vm:prefer-inline') + @override + $Res call({ + Object? id = null, + Object? match_id = null, + Object? inning_id = null, + Object? player_ids = null, + Object? players = null, + Object? runs = null, + Object? extras = null, + Object? ball_faced = null, + Object? start_over = null, + Object? end_over = null, + }) { + return _then(_value.copyWith( + id: null == id + ? _value.id + : id // ignore: cast_nullable_to_non_nullable + as String, + match_id: null == match_id + ? _value.match_id + : match_id // ignore: cast_nullable_to_non_nullable + as String, + inning_id: null == inning_id + ? _value.inning_id + : inning_id // ignore: cast_nullable_to_non_nullable + as String, + player_ids: null == player_ids + ? _value.player_ids + : player_ids // ignore: cast_nullable_to_non_nullable + as List, + players: null == players + ? _value.players + : players // ignore: cast_nullable_to_non_nullable + as List, + runs: null == runs + ? _value.runs + : runs // ignore: cast_nullable_to_non_nullable + as int, + extras: null == extras + ? _value.extras + : extras // ignore: cast_nullable_to_non_nullable + as int, + ball_faced: null == ball_faced + ? _value.ball_faced + : ball_faced // ignore: cast_nullable_to_non_nullable + as int, + start_over: null == start_over + ? _value.start_over + : start_over // ignore: cast_nullable_to_non_nullable + as double, + end_over: null == end_over + ? _value.end_over + : end_over // ignore: cast_nullable_to_non_nullable + as double, + ) as $Val); + } +} + +/// @nodoc +abstract class _$$PartnershipModelImplCopyWith<$Res> + implements $PartnershipModelCopyWith<$Res> { + factory _$$PartnershipModelImplCopyWith(_$PartnershipModelImpl value, + $Res Function(_$PartnershipModelImpl) then) = + __$$PartnershipModelImplCopyWithImpl<$Res>; + @override + @useResult + $Res call( + {String id, + String match_id, + String inning_id, + List player_ids, + List players, + int runs, + int extras, + int ball_faced, + double start_over, + double end_over}); +} + +/// @nodoc +class __$$PartnershipModelImplCopyWithImpl<$Res> + extends _$PartnershipModelCopyWithImpl<$Res, _$PartnershipModelImpl> + implements _$$PartnershipModelImplCopyWith<$Res> { + __$$PartnershipModelImplCopyWithImpl(_$PartnershipModelImpl _value, + $Res Function(_$PartnershipModelImpl) _then) + : super(_value, _then); + + /// Create a copy of PartnershipModel + /// with the given fields replaced by the non-null parameter values. + @pragma('vm:prefer-inline') + @override + $Res call({ + Object? id = null, + Object? match_id = null, + Object? inning_id = null, + Object? player_ids = null, + Object? players = null, + Object? runs = null, + Object? extras = null, + Object? ball_faced = null, + Object? start_over = null, + Object? end_over = null, + }) { + return _then(_$PartnershipModelImpl( + id: null == id + ? _value.id + : id // ignore: cast_nullable_to_non_nullable + as String, + match_id: null == match_id + ? _value.match_id + : match_id // ignore: cast_nullable_to_non_nullable + as String, + inning_id: null == inning_id + ? _value.inning_id + : inning_id // ignore: cast_nullable_to_non_nullable + as String, + player_ids: null == player_ids + ? _value._player_ids + : player_ids // ignore: cast_nullable_to_non_nullable + as List, + players: null == players + ? _value._players + : players // ignore: cast_nullable_to_non_nullable + as List, + runs: null == runs + ? _value.runs + : runs // ignore: cast_nullable_to_non_nullable + as int, + extras: null == extras + ? _value.extras + : extras // ignore: cast_nullable_to_non_nullable + as int, + ball_faced: null == ball_faced + ? _value.ball_faced + : ball_faced // ignore: cast_nullable_to_non_nullable + as int, + start_over: null == start_over + ? _value.start_over + : start_over // ignore: cast_nullable_to_non_nullable + as double, + end_over: null == end_over + ? _value.end_over + : end_over // ignore: cast_nullable_to_non_nullable + as double, + )); + } +} + +/// @nodoc + +@JsonSerializable(anyMap: true, explicitToJson: true) +class _$PartnershipModelImpl implements _PartnershipModel { + const _$PartnershipModelImpl( + {required this.id, + required this.match_id, + required this.inning_id, + required final List player_ids, + final List players = const [], + this.runs = 0, + this.extras = 0, + this.ball_faced = 0, + this.start_over = 0.0, + this.end_over = 0.0}) + : _player_ids = player_ids, + _players = players; + + factory _$PartnershipModelImpl.fromJson(Map json) => + _$$PartnershipModelImplFromJson(json); + + @override + final String id; + @override + final String match_id; + @override + final String inning_id; + final List _player_ids; + @override + List get player_ids { + if (_player_ids is EqualUnmodifiableListView) return _player_ids; + // ignore: implicit_dynamic_type + return EqualUnmodifiableListView(_player_ids); + } + + final List _players; + @override + @JsonKey() + List get players { + if (_players is EqualUnmodifiableListView) return _players; + // ignore: implicit_dynamic_type + return EqualUnmodifiableListView(_players); + } + + @override + @JsonKey() + final int runs; + @override + @JsonKey() + final int extras; + @override + @JsonKey() + final int ball_faced; + @override + @JsonKey() + final double start_over; + @override + @JsonKey() + final double end_over; + + @override + String toString() { + return 'PartnershipModel(id: $id, match_id: $match_id, inning_id: $inning_id, player_ids: $player_ids, players: $players, runs: $runs, extras: $extras, ball_faced: $ball_faced, start_over: $start_over, end_over: $end_over)'; + } + + @override + bool operator ==(Object other) { + return identical(this, other) || + (other.runtimeType == runtimeType && + other is _$PartnershipModelImpl && + (identical(other.id, id) || other.id == id) && + (identical(other.match_id, match_id) || + other.match_id == match_id) && + (identical(other.inning_id, inning_id) || + other.inning_id == inning_id) && + const DeepCollectionEquality() + .equals(other._player_ids, _player_ids) && + const DeepCollectionEquality().equals(other._players, _players) && + (identical(other.runs, runs) || other.runs == runs) && + (identical(other.extras, extras) || other.extras == extras) && + (identical(other.ball_faced, ball_faced) || + other.ball_faced == ball_faced) && + (identical(other.start_over, start_over) || + other.start_over == start_over) && + (identical(other.end_over, end_over) || + other.end_over == end_over)); + } + + @JsonKey(includeFromJson: false, includeToJson: false) + @override + int get hashCode => Object.hash( + runtimeType, + id, + match_id, + inning_id, + const DeepCollectionEquality().hash(_player_ids), + const DeepCollectionEquality().hash(_players), + runs, + extras, + ball_faced, + start_over, + end_over); + + /// Create a copy of PartnershipModel + /// with the given fields replaced by the non-null parameter values. + @JsonKey(includeFromJson: false, includeToJson: false) + @override + @pragma('vm:prefer-inline') + _$$PartnershipModelImplCopyWith<_$PartnershipModelImpl> get copyWith => + __$$PartnershipModelImplCopyWithImpl<_$PartnershipModelImpl>( + this, _$identity); + + @override + Map toJson() { + return _$$PartnershipModelImplToJson( + this, + ); + } +} + +abstract class _PartnershipModel implements PartnershipModel { + const factory _PartnershipModel( + {required final String id, + required final String match_id, + required final String inning_id, + required final List player_ids, + final List players, + final int runs, + final int extras, + final int ball_faced, + final double start_over, + final double end_over}) = _$PartnershipModelImpl; + + factory _PartnershipModel.fromJson(Map json) = + _$PartnershipModelImpl.fromJson; + + @override + String get id; + @override + String get match_id; + @override + String get inning_id; + @override + List get player_ids; + @override + List get players; + @override + int get runs; + @override + int get extras; + @override + int get ball_faced; + @override + double get start_over; + @override + double get end_over; + + /// Create a copy of PartnershipModel + /// with the given fields replaced by the non-null parameter values. + @override + @JsonKey(includeFromJson: false, includeToJson: false) + _$$PartnershipModelImplCopyWith<_$PartnershipModelImpl> get copyWith => + throw _privateConstructorUsedError; +} + +PartnershipPlayer _$PartnershipPlayerFromJson(Map json) { + return _PartnershipPlayer.fromJson(json); +} + +/// @nodoc +mixin _$PartnershipPlayer { + String get player_id => throw _privateConstructorUsedError; + int get runs => throw _privateConstructorUsedError; + int get ball_faced => throw _privateConstructorUsedError; + int get fours => throw _privateConstructorUsedError; + int get sixes => throw _privateConstructorUsedError; + + /// Serializes this PartnershipPlayer to a JSON map. + Map toJson() => throw _privateConstructorUsedError; + + /// Create a copy of PartnershipPlayer + /// with the given fields replaced by the non-null parameter values. + @JsonKey(includeFromJson: false, includeToJson: false) + $PartnershipPlayerCopyWith get copyWith => + throw _privateConstructorUsedError; +} + +/// @nodoc +abstract class $PartnershipPlayerCopyWith<$Res> { + factory $PartnershipPlayerCopyWith( + PartnershipPlayer value, $Res Function(PartnershipPlayer) then) = + _$PartnershipPlayerCopyWithImpl<$Res, PartnershipPlayer>; + @useResult + $Res call({String player_id, int runs, int ball_faced, int fours, int sixes}); +} + +/// @nodoc +class _$PartnershipPlayerCopyWithImpl<$Res, $Val extends PartnershipPlayer> + implements $PartnershipPlayerCopyWith<$Res> { + _$PartnershipPlayerCopyWithImpl(this._value, this._then); + + // ignore: unused_field + final $Val _value; + // ignore: unused_field + final $Res Function($Val) _then; + + /// Create a copy of PartnershipPlayer + /// with the given fields replaced by the non-null parameter values. + @pragma('vm:prefer-inline') + @override + $Res call({ + Object? player_id = null, + Object? runs = null, + Object? ball_faced = null, + Object? fours = null, + Object? sixes = null, + }) { + return _then(_value.copyWith( + player_id: null == player_id + ? _value.player_id + : player_id // ignore: cast_nullable_to_non_nullable + as String, + runs: null == runs + ? _value.runs + : runs // ignore: cast_nullable_to_non_nullable + as int, + ball_faced: null == ball_faced + ? _value.ball_faced + : ball_faced // ignore: cast_nullable_to_non_nullable + as int, + fours: null == fours + ? _value.fours + : fours // ignore: cast_nullable_to_non_nullable + as int, + sixes: null == sixes + ? _value.sixes + : sixes // ignore: cast_nullable_to_non_nullable + as int, + ) as $Val); + } +} + +/// @nodoc +abstract class _$$PartnershipPlayerImplCopyWith<$Res> + implements $PartnershipPlayerCopyWith<$Res> { + factory _$$PartnershipPlayerImplCopyWith(_$PartnershipPlayerImpl value, + $Res Function(_$PartnershipPlayerImpl) then) = + __$$PartnershipPlayerImplCopyWithImpl<$Res>; + @override + @useResult + $Res call({String player_id, int runs, int ball_faced, int fours, int sixes}); +} + +/// @nodoc +class __$$PartnershipPlayerImplCopyWithImpl<$Res> + extends _$PartnershipPlayerCopyWithImpl<$Res, _$PartnershipPlayerImpl> + implements _$$PartnershipPlayerImplCopyWith<$Res> { + __$$PartnershipPlayerImplCopyWithImpl(_$PartnershipPlayerImpl _value, + $Res Function(_$PartnershipPlayerImpl) _then) + : super(_value, _then); + + /// Create a copy of PartnershipPlayer + /// with the given fields replaced by the non-null parameter values. + @pragma('vm:prefer-inline') + @override + $Res call({ + Object? player_id = null, + Object? runs = null, + Object? ball_faced = null, + Object? fours = null, + Object? sixes = null, + }) { + return _then(_$PartnershipPlayerImpl( + player_id: null == player_id + ? _value.player_id + : player_id // ignore: cast_nullable_to_non_nullable + as String, + runs: null == runs + ? _value.runs + : runs // ignore: cast_nullable_to_non_nullable + as int, + ball_faced: null == ball_faced + ? _value.ball_faced + : ball_faced // ignore: cast_nullable_to_non_nullable + as int, + fours: null == fours + ? _value.fours + : fours // ignore: cast_nullable_to_non_nullable + as int, + sixes: null == sixes + ? _value.sixes + : sixes // ignore: cast_nullable_to_non_nullable + as int, + )); + } +} + +/// @nodoc + +@JsonSerializable(anyMap: true, explicitToJson: true) +class _$PartnershipPlayerImpl implements _PartnershipPlayer { + const _$PartnershipPlayerImpl( + {required this.player_id, + this.runs = 0, + this.ball_faced = 0, + this.fours = 0, + this.sixes = 0}); + + factory _$PartnershipPlayerImpl.fromJson(Map json) => + _$$PartnershipPlayerImplFromJson(json); + + @override + final String player_id; + @override + @JsonKey() + final int runs; + @override + @JsonKey() + final int ball_faced; + @override + @JsonKey() + final int fours; + @override + @JsonKey() + final int sixes; + + @override + String toString() { + return 'PartnershipPlayer(player_id: $player_id, runs: $runs, ball_faced: $ball_faced, fours: $fours, sixes: $sixes)'; + } + + @override + bool operator ==(Object other) { + return identical(this, other) || + (other.runtimeType == runtimeType && + other is _$PartnershipPlayerImpl && + (identical(other.player_id, player_id) || + other.player_id == player_id) && + (identical(other.runs, runs) || other.runs == runs) && + (identical(other.ball_faced, ball_faced) || + other.ball_faced == ball_faced) && + (identical(other.fours, fours) || other.fours == fours) && + (identical(other.sixes, sixes) || other.sixes == sixes)); + } + + @JsonKey(includeFromJson: false, includeToJson: false) + @override + int get hashCode => + Object.hash(runtimeType, player_id, runs, ball_faced, fours, sixes); + + /// Create a copy of PartnershipPlayer + /// with the given fields replaced by the non-null parameter values. + @JsonKey(includeFromJson: false, includeToJson: false) + @override + @pragma('vm:prefer-inline') + _$$PartnershipPlayerImplCopyWith<_$PartnershipPlayerImpl> get copyWith => + __$$PartnershipPlayerImplCopyWithImpl<_$PartnershipPlayerImpl>( + this, _$identity); + + @override + Map toJson() { + return _$$PartnershipPlayerImplToJson( + this, + ); + } +} + +abstract class _PartnershipPlayer implements PartnershipPlayer { + const factory _PartnershipPlayer( + {required final String player_id, + final int runs, + final int ball_faced, + final int fours, + final int sixes}) = _$PartnershipPlayerImpl; + + factory _PartnershipPlayer.fromJson(Map json) = + _$PartnershipPlayerImpl.fromJson; + + @override + String get player_id; + @override + int get runs; + @override + int get ball_faced; + @override + int get fours; + @override + int get sixes; + + /// Create a copy of PartnershipPlayer + /// with the given fields replaced by the non-null parameter values. + @override + @JsonKey(includeFromJson: false, includeToJson: false) + _$$PartnershipPlayerImplCopyWith<_$PartnershipPlayerImpl> get copyWith => + throw _privateConstructorUsedError; +} diff --git a/data/lib/api/partnership/partnership_model.g.dart b/data/lib/api/partnership/partnership_model.g.dart new file mode 100644 index 00000000..755edd29 --- /dev/null +++ b/data/lib/api/partnership/partnership_model.g.dart @@ -0,0 +1,61 @@ +// GENERATED CODE - DO NOT MODIFY BY HAND + +part of 'partnership_model.dart'; + +// ************************************************************************** +// JsonSerializableGenerator +// ************************************************************************** + +_$PartnershipModelImpl _$$PartnershipModelImplFromJson(Map json) => + _$PartnershipModelImpl( + id: json['id'] as String, + match_id: json['match_id'] as String, + inning_id: json['inning_id'] as String, + player_ids: (json['player_ids'] as List) + .map((e) => e as String) + .toList(), + players: (json['players'] as List?) + ?.map((e) => PartnershipPlayer.fromJson( + Map.from(e as Map))) + .toList() ?? + const [], + runs: (json['runs'] as num?)?.toInt() ?? 0, + extras: (json['extras'] as num?)?.toInt() ?? 0, + ball_faced: (json['ball_faced'] as num?)?.toInt() ?? 0, + start_over: (json['start_over'] as num?)?.toDouble() ?? 0.0, + end_over: (json['end_over'] as num?)?.toDouble() ?? 0.0, + ); + +Map _$$PartnershipModelImplToJson( + _$PartnershipModelImpl instance) => + { + 'id': instance.id, + 'match_id': instance.match_id, + 'inning_id': instance.inning_id, + 'player_ids': instance.player_ids, + 'players': instance.players.map((e) => e.toJson()).toList(), + 'runs': instance.runs, + 'extras': instance.extras, + 'ball_faced': instance.ball_faced, + 'start_over': instance.start_over, + 'end_over': instance.end_over, + }; + +_$PartnershipPlayerImpl _$$PartnershipPlayerImplFromJson(Map json) => + _$PartnershipPlayerImpl( + player_id: json['player_id'] as String, + runs: (json['runs'] as num?)?.toInt() ?? 0, + ball_faced: (json['ball_faced'] as num?)?.toInt() ?? 0, + fours: (json['fours'] as num?)?.toInt() ?? 0, + sixes: (json['sixes'] as num?)?.toInt() ?? 0, + ); + +Map _$$PartnershipPlayerImplToJson( + _$PartnershipPlayerImpl instance) => + { + 'player_id': instance.player_id, + 'runs': instance.runs, + 'ball_faced': instance.ball_faced, + 'fours': instance.fours, + 'sixes': instance.sixes, + }; diff --git a/data/lib/service/ball_score/ball_score_service.dart b/data/lib/service/ball_score/ball_score_service.dart index 41bccc52..68078d7f 100644 --- a/data/lib/service/ball_score/ball_score_service.dart +++ b/data/lib/service/ball_score/ball_score_service.dart @@ -60,8 +60,7 @@ class BallScoreService { try { final scoreRef = _ballScoreCollection.doc(); await _firestore.runTransaction(maxAttempts: 1, (transaction) async { - final overCount = - double.parse("${score.over_number - 1}.${score.ball_number}"); + final overCount = score.formattedOver; // update matchTeamScore and squad(if needed) await _matchService.updateTeamScoreAndSquadViaTransaction( diff --git a/data/lib/service/match_event/match_event_service.dart b/data/lib/service/match_event/match_event_service.dart new file mode 100644 index 00000000..841eb315 --- /dev/null +++ b/data/lib/service/match_event/match_event_service.dart @@ -0,0 +1,54 @@ +import 'package:cloud_firestore/cloud_firestore.dart'; +import 'package:flutter_riverpod/flutter_riverpod.dart'; + +import '../../api/match_event/match_event_model.dart'; +import '../../errors/app_error.dart'; +import '../../utils/constant/firestore_constant.dart'; + +final matchEventServiceProvider = Provider( + (ref) => MatchEventService(FirebaseFirestore.instance), +); + +class MatchEventService { + final FirebaseFirestore _firestore; + + MatchEventService(this._firestore); + + CollectionReference get _matchEventCollection => + _firestore.collection(FireStoreConst.matchEventsCollection).withConverter( + fromFirestore: MatchEventModel.fromFireStore, + toFirestore: (MatchEventModel event, _) => event.toJson(), + ); + + String get generateMatchEventId => _matchEventCollection.doc().id; + + Stream> streamEventsByMatches(String matchId) { + return _matchEventCollection + .where(FireStoreConst.matchId, isEqualTo: matchId) + .snapshots() + .asyncMap((snapshot) async { + return snapshot.docs.map((mainDoc) => mainDoc.data()).toList(); + }).handleError((error, stack) => throw AppError.fromError(error, stack)); + } + + Future updateMatchEvent(MatchEventModel event) async { + try { + final eventRef = _matchEventCollection.doc(event.id); + await eventRef.set( + event, + SetOptions(merge: true), + ); + return eventRef.id; + } catch (error, stack) { + throw AppError.fromError(error, stack); + } + } + + Future deleteMatchEvent(String eventId) async { + try { + await _matchEventCollection.doc(eventId).delete(); + } catch (error, stack) { + throw AppError.fromError(error, stack); + } + } +} diff --git a/data/lib/service/partnership/partnership_service.dart b/data/lib/service/partnership/partnership_service.dart new file mode 100644 index 00000000..a00e09f6 --- /dev/null +++ b/data/lib/service/partnership/partnership_service.dart @@ -0,0 +1,55 @@ +import 'package:cloud_firestore/cloud_firestore.dart'; +import 'package:flutter_riverpod/flutter_riverpod.dart'; + +import '../../api/partnership/partnership_model.dart'; +import '../../errors/app_error.dart'; +import '../../utils/constant/firestore_constant.dart'; + +final partnershipServiceProvider = Provider( + (ref) => PartnershipService(FirebaseFirestore.instance), +); + +class PartnershipService { + final FirebaseFirestore _firestore; + + PartnershipService(this._firestore); + + CollectionReference get _partnershipCollection => _firestore + .collection(FireStoreConst.partnershipsCollection) + .withConverter( + fromFirestore: PartnershipModel.fromFireStore, + toFirestore: (PartnershipModel partnership, _) => partnership.toJson(), + ); + + String get generatePartnershipId => _partnershipCollection.doc().id; + + Future updatePartnership(PartnershipModel partnership) async { + try { + final partnershipRef = _partnershipCollection.doc(partnership.id); + await partnershipRef.set( + partnership.copyWith(id: partnershipRef.id), + SetOptions(merge: true), + ); + return partnershipRef.id; + } catch (error, stack) { + throw AppError.fromError(error, stack); + } + } + + Stream> streamPartnershipByMatches(String matchId) { + return _partnershipCollection + .where(FireStoreConst.matchId, isEqualTo: matchId) + .snapshots() + .asyncMap((snapshot) async { + return snapshot.docs.map((mainDoc) => mainDoc.data()).toList(); + }).handleError((error, stack) => throw AppError.fromError(error, stack)); + } + + Future deletePartnership(String partnershipId) async { + try { + await _partnershipCollection.doc(partnershipId).delete(); + } catch (error, stack) { + throw AppError.fromError(error, stack); + } + } +} diff --git a/data/lib/utils/constant/firestore_constant.dart b/data/lib/utils/constant/firestore_constant.dart index 371604d6..c70823a3 100644 --- a/data/lib/utils/constant/firestore_constant.dart +++ b/data/lib/utils/constant/firestore_constant.dart @@ -10,6 +10,8 @@ class FireStoreConst { static const String userSessionCollection = "user_sessions"; static const String supportCollection = "contact_support"; static const String tournamentCollection = "tournaments"; + static const String matchEventsCollection = "match_events"; + static const String partnershipsCollection = "partnerships"; // matches field const static const String id = "id"; diff --git a/khelo/lib/ui/flow/score_board/score_board_view_model.dart b/khelo/lib/ui/flow/score_board/score_board_view_model.dart index 16e8c97b..81d7e8c0 100644 --- a/khelo/lib/ui/flow/score_board/score_board_view_model.dart +++ b/khelo/lib/ui/flow/score_board/score_board_view_model.dart @@ -5,12 +5,16 @@ import 'package:collection/collection.dart'; import 'package:data/api/ball_score/ball_score_model.dart'; import 'package:data/api/innings/inning_model.dart'; import 'package:data/api/match/match_model.dart'; +import 'package:data/api/match_event/match_event_model.dart'; +import 'package:data/api/partnership/partnership_model.dart'; import 'package:data/api/user/user_models.dart'; import 'package:data/errors/app_error.dart'; import 'package:data/extensions/list_extensions.dart'; import 'package:data/service/ball_score/ball_score_service.dart'; import 'package:data/service/innings/inning_service.dart'; import 'package:data/service/match/match_service.dart'; +import 'package:data/service/match_event/match_event_service.dart'; +import 'package:data/service/partnership/partnership_service.dart'; import 'package:data/utils/combine_latest.dart'; import 'package:flutter/material.dart'; import 'package:flutter_riverpod/flutter_riverpod.dart'; @@ -26,6 +30,8 @@ final scoreBoardStateProvider = StateNotifierProvider.autoDispose< ref.read(matchServiceProvider), ref.read(inningServiceProvider), ref.read(ballScoreServiceProvider), + ref.read(matchEventServiceProvider), + ref.read(partnershipServiceProvider), ); }); @@ -33,23 +39,34 @@ class ScoreBoardViewNotifier extends StateNotifier { final MatchService _matchService; final InningsService _inningService; final BallScoreService _ballScoreService; + final MatchEventService _matchEventService; + final PartnershipService _partnershipService; + StreamSubscription? _matchStreamSubscription; StreamSubscription>? _ballScoreStreamSubscription; StreamSubscription? _matchSettingSubscription; + StreamSubscription>? _matchEventSubscription; + StreamSubscription>? _matchPartnershipSubscription; final StreamController _matchStreamController = StreamController.broadcast(); String? matchId; + List matchEvents = []; + List partnerships = []; ScoreBoardViewNotifier( this._matchService, this._inningService, this._ballScoreService, + this._matchEventService, + this._partnershipService, ) : super(const ScoreBoardViewState()); void setData(String matchId) { this.matchId = matchId; _loadMatchesAndInning(); _loadMatchSetting(); + _loadMatchEvent(); + _loadMatchPartnership(); } void _loadMatchSetting() { @@ -156,6 +173,39 @@ class ScoreBoardViewNotifier extends StateNotifier { } } + void _loadMatchEvent() { + try { + if (matchId == null) return; + _matchEventSubscription?.cancel(); + _matchEventSubscription = _matchEventService + .streamEventsByMatches(matchId!) + .listen((events) => matchEvents = events, onError: (e) { + debugPrint( + "ScoreBoardViewNotifier: error while loading match event -> $e"); + }); + } catch (e) { + debugPrint( + "ScoreBoardViewNotifier: error while loading match event -> $e"); + } + } + + void _loadMatchPartnership() { + try { + if (matchId == null) return; + _matchPartnershipSubscription?.cancel(); + _matchPartnershipSubscription = _partnershipService + .streamPartnershipByMatches(matchId!) + .listen((matchPartnership) => partnerships = matchPartnership, + onError: (e) { + debugPrint( + "ScoreBoardViewNotifier: error while loading partnership -> $e"); + }); + } catch (e) { + debugPrint( + "ScoreBoardViewNotifier: error while loading partnership -> $e"); + } + } + bool _isSelectInning( InningModel inning, bool isIndexEven, @@ -638,6 +688,11 @@ class ScoreBoardViewNotifier extends StateNotifier { final otherBowlingInning = state.allInnings.firstWhereOrNull((element) => element.team_id == bowlingTeamId && element.id != bowlingTeamInningId); + await addMatchEventIfNeeded(ball); + if (wicketType != null) { + await addMatchPartnershipIfNeeded( + strikerId, nonStrikerId, matchId, ballInningId, ball); + } await _ballScoreService.addBallScoreAndUpdateTeamDetails( score: ball, matchId: matchId, @@ -662,6 +717,196 @@ class ScoreBoardViewNotifier extends StateNotifier { } } + Future addMatchEventIfNeeded(BallScoreModel ball) async { + try { + if (ball.is_four || ball.is_six) { + await _matchEventService.updateMatchEvent(MatchEventModel( + id: _matchEventService.generateMatchEventId, + match_id: ball.match_id, + inning_id: ball.inning_id, + type: ball.is_six ? EventType.six : EventType.four, + bowler_id: ball.bowler_id, + batsman_id: ball.batsman_id, + over: ball.formattedOver, + fielding_position: ball.fielding_position, + time: ball.score_time ?? DateTime.now(), + ball_ids: [ball.id], + )); + } else if (ball.wicket_type != null) { + await handleWicketMatchEvent(ball); + if (ball.player_out_id != ball.batsman_id) { + await handleMilestonesMatchEvent(ball, ball.player_out_id!); + } + } + + await handleMilestonesMatchEvent(ball, ball.batsman_id); + } catch (e) { + debugPrint( + "ScoreBoardViewNotifier: error while adding match event -> $e"); + } + } + + Future handleWicketMatchEvent(BallScoreModel ball) async { + final lastBall = state.currentScoresList.lastWhereOrNull( + (ball) => + ball.wicket_type != WicketType.retired && + ball.wicket_type != WicketType.retiredHurt && + ball.wicket_type != WicketType.timedOut, + ); + MatchEventModel matchEvent; + if (lastBall?.wicket_type != null && + lastBall?.bowler_id == ball.bowler_id) { + matchEvent = matchEvents + .where((element) => + (element.type == EventType.wicket || + element.type == EventType.hatTrick) && + element.bowler_id == ball.bowler_id && + element.ball_ids.contains(lastBall?.id)) + .firstOrNull ?? + MatchEventModel( + id: _matchEventService.generateMatchEventId, + match_id: ball.match_id, + inning_id: ball.inning_id, + type: EventType.wicket, + bowler_id: ball.bowler_id, + time: ball.score_time ?? DateTime.now()); + } else { + matchEvent = MatchEventModel( + id: _matchEventService.generateMatchEventId, + match_id: ball.match_id, + inning_id: ball.inning_id, + type: EventType.wicket, + bowler_id: ball.bowler_id, + time: ball.score_time ?? DateTime.now()); + } + final wicket = matchEvent.wickets.toList(); + wicket.add(MatchEventWicket( + time: ball.score_time ?? DateTime.now(), + ball_id: ball.id, + batsman_id: ball.player_out_id ?? ball.batsman_id, + wicket_type: ball.wicket_type!, + over: ball.formattedOver, + )); + await _matchEventService.updateMatchEvent(matchEvent.copyWith( + ball_ids: wicket.map((e) => e.ball_id).toList(), + type: (wicket.length == 1 ? EventType.wicket : EventType.hatTrick), + wickets: wicket)); + } + + Future handleMilestonesMatchEvent( + BallScoreModel ball, String playerId) async { + final currentBattingStat = + state.currentScoresList.calculateBattingStats(currentUserId: playerId); + + final currentRun = currentBattingStat.runScored; + final updatedList = state.currentScoresList.toList(); + updatedList.add(ball); + + final updatedBattingStat = + updatedList.calculateBattingStats(currentUserId: playerId); + + final runsAfterUpdate = updatedBattingStat.runScored; + if ((currentRun < 50 && runsAfterUpdate >= 50) || + (currentRun < 100 && runsAfterUpdate >= 100)) { + MatchEventModel? matchEvent; + matchEvent = matchEvents.firstWhereOrNull( + (element) => + (element.type == EventType.fifty || + element.type == EventType.century) && + element.batsman_id == playerId && + element.inning_id == ball.inning_id, + ); + + final mileStone = matchEvent?.milestone.toList() ?? []; + + mileStone.add(MatchEventMilestone( + time: ball.score_time ?? DateTime.now(), + runs: updatedBattingStat.runScored, + over: ball.formattedOver, + ball_faced: updatedBattingStat.ballFaced, + fours: updatedBattingStat.fours, + sixes: updatedBattingStat.sixes, + ball_id: ball.id, + )); + + await _matchEventService.updateMatchEvent(MatchEventModel( + id: matchEvent?.id ?? _matchEventService.generateMatchEventId, + match_id: matchEvent?.match_id ?? ball.match_id, + inning_id: matchEvent?.inning_id ?? ball.inning_id, + type: runsAfterUpdate >= 100 ? EventType.century : EventType.fifty, + batsman_id: playerId, + ball_ids: mileStone.map((e) => e.ball_id).toList(), + milestone: mileStone, + time: ball.score_time ?? DateTime.now())); + } + } + + Future addMatchPartnershipIfNeeded( + String strikerId, + String nonStrikerId, + String matchId, + String inningId, + BallScoreModel ball, + ) async { + final scores = state.currentScoresList + .where((element) => + [strikerId, nonStrikerId].contains(element.batsman_id) && + [strikerId, nonStrikerId].contains(element.non_striker_id)) + .toList(); + scores.add(ball); + + int totalRuns = 0; + int extras = 0; + int ballFaced = 0; + + for (var element in scores) { + totalRuns += (element.extras_awarded ?? 0) + element.runs_scored; + + if ((element.extras_type == null || + element.extras_type == ExtrasType.legBye || + element.extras_type == ExtrasType.bye) && + (element.wicket_type != WicketType.retired && + element.wicket_type != WicketType.retiredHurt && + element.wicket_type != WicketType.timedOut)) { + ballFaced++; + } + extras += (element.extras_awarded ?? 0); + } + + scores.sort((a, b) => (a.score_time ?? DateTime.now()) + .compareTo(b.score_time ?? DateTime.now())); + + if (totalRuns > 50) { + final player = [strikerId, nonStrikerId].map( + (id) { + final stat = scores.calculateBattingStats(currentUserId: id); + return PartnershipPlayer( + player_id: id, + sixes: stat.sixes, + fours: stat.fours, + runs: stat.runScored, + ball_faced: stat.ballFaced, + ); + }, + ).toList(); + + final partnership = PartnershipModel( + id: _partnershipService.generatePartnershipId, + match_id: matchId, + inning_id: inningId, + player_ids: [strikerId, nonStrikerId], + players: player, + runs: totalRuns, + extras: extras, + ball_faced: ballFaced, + start_over: scores.first.formattedOver, + end_over: scores.last.formattedOver, + ); + + await _partnershipService.updatePartnership(partnership); + } + } + MatchPlayer? _getUpdatedOutPlayerStatus( WicketType? wicketType, String? playerOutId, @@ -957,6 +1202,11 @@ class ScoreBoardViewNotifier extends StateNotifier { element.team_id == bowlingTeamId && element.id != bowlingTeamInningId); + await undoMatchEventIfNeeded(lastBall); + if (lastBall.wicket_type != null) { + await undoPartnerShipIfNeeded(lastBall); + } + await _ballScoreService.deleteBallAndUpdateTeamDetails( ballId: lastBall.id, matchId: matchId, @@ -980,6 +1230,80 @@ class ScoreBoardViewNotifier extends StateNotifier { } } + Future undoMatchEventIfNeeded(BallScoreModel ball) async { + final events = + matchEvents.where((element) => element.ball_ids.contains(ball.id)); + + for (final event in events) { + if (event.type == EventType.six || event.type == EventType.four) { + await _matchEventService.deleteMatchEvent(event.id); + } else if (event.type == EventType.hatTrick || + event.type == EventType.wicket) { + if (event.wickets.length == 1) { + await _matchEventService.deleteMatchEvent(event.id); + } else { + final wickets = event.wickets.toList(); + wickets.removeWhere((element) => element.ball_id == ball.id); + _matchEventService.updateMatchEvent(event.copyWith( + ball_ids: wickets.map((e) => e.ball_id).toList(), + type: EventType.wicket, + wickets: wickets, + )); + } + } + } + + await handleMilestoneUndo(ball); + } + + Future handleMilestoneUndo(BallScoreModel ball) async { + final mileStoneEvent = matchEvents.firstWhereOrNull((element) => + (element.type == EventType.fifty || + element.type == EventType.century) && + element.batsman_id == ball.batsman_id && + element.inning_id == ball.inning_id); + + final scores = state.currentScoresList.toList(); + scores.remove(ball); + final updatedBattingStat = + scores.calculateBattingStats(currentUserId: ball.batsman_id); + + if (mileStoneEvent != null && + (updatedBattingStat.runScored < + (mileStoneEvent.type == EventType.fifty ? 50 : 100))) { + final milestone = mileStoneEvent.milestone.toList(); + milestone.removeWhere((element) => + (updatedBattingStat.runScored < 100 && element.runs >= 100) || + (updatedBattingStat.runScored < 50 && element.runs >= 50)); + + if (milestone.isEmpty) { + await _matchEventService.deleteMatchEvent(mileStoneEvent.id); + } else { + await _matchEventService.updateMatchEvent(mileStoneEvent.copyWith( + ball_ids: milestone.map((e) => e.ball_id).toList(), + type: updatedBattingStat.runScored >= 100 + ? EventType.century + : EventType.fifty, + milestone: milestone, + )); + } + } + } + + Future undoPartnerShipIfNeeded(BallScoreModel ball) async { + try { + final partnership = partnerships + .where((element) => element.end_over == ball.formattedOver) + .firstOrNull; + + if (partnership != null) { + await _partnershipService.deletePartnership(partnership.id); + } + } catch (e) { + debugPrint("ScoreboardViewNotifier: error while undo partnership -> $e"); + } + } + List? _getUndoPlayerStatus(BallScoreModel lastBall) { if (lastBall.wicket_type == null) { return null; @@ -1563,6 +1887,8 @@ class ScoreBoardViewNotifier extends StateNotifier { await _matchStreamSubscription?.cancel(); await _ballScoreStreamSubscription?.cancel(); await _matchSettingSubscription?.cancel(); + await _matchEventSubscription?.cancel(); + await _matchPartnershipSubscription?.cancel(); await _matchStreamController.close(); } From 2fe641f0e0f4172068d4bb3980d4dc93e4a72af5 Mon Sep 17 00:00:00 2001 From: sidhdhi canopas Date: Thu, 5 Dec 2024 10:53:30 +0530 Subject: [PATCH 2/5] fix ball score having different ids --- data/lib/service/ball_score/ball_score_service.dart | 8 ++------ 1 file changed, 2 insertions(+), 6 deletions(-) diff --git a/data/lib/service/ball_score/ball_score_service.dart b/data/lib/service/ball_score/ball_score_service.dart index 68078d7f..9eda93a2 100644 --- a/data/lib/service/ball_score/ball_score_service.dart +++ b/data/lib/service/ball_score/ball_score_service.dart @@ -58,7 +58,7 @@ class BallScoreService { MatchPlayer? updatedPlayer, }) async { try { - final scoreRef = _ballScoreCollection.doc(); + final scoreRef = _ballScoreCollection.doc(score.id); await _firestore.runTransaction(maxAttempts: 1, (transaction) async { final overCount = score.formattedOver; @@ -88,11 +88,7 @@ class BallScoreService { ); // add ball - transaction.set( - scoreRef, - score.copyWith(id: scoreRef.id), - SetOptions(merge: true), - ); + transaction.set(scoreRef, score, SetOptions(merge: true)); }).catchError((error, stack) { throw AppError.fromError(error, stack); }); From 62557d13777b1084dfe0c34feacb3a28492c6ebf Mon Sep 17 00:00:00 2001 From: sidhdhi canopas Date: Thu, 5 Dec 2024 11:22:20 +0530 Subject: [PATCH 3/5] rename identifier and improve code --- .../flow/score_board/score_board_screen.dart | 4 +- .../score_board/score_board_view_model.dart | 83 ++++++++----------- 2 files changed, 37 insertions(+), 50 deletions(-) diff --git a/khelo/lib/ui/flow/score_board/score_board_screen.dart b/khelo/lib/ui/flow/score_board/score_board_screen.dart index 465e4f69..9ca07e6f 100644 --- a/khelo/lib/ui/flow/score_board/score_board_screen.dart +++ b/khelo/lib/ui/flow/score_board/score_board_screen.dart @@ -275,7 +275,7 @@ class _ScoreBoardScreenState extends ConsumerState { final endMatch = await MatchCompleteSheet.show(context); if (endMatch != null && context.mounted) { if (endMatch) { - notifier.endMatch(); + notifier.endMatchWithStatus(MatchStatus.finish); } else { notifier.undoLastBall(); } @@ -661,7 +661,7 @@ class _ScoreBoardScreenState extends ConsumerState { title: context.l10n.common_end_match_title, message: context.l10n.score_board_end_match_description_text, confirmBtnText: context.l10n.common_end_match_title, - onConfirm: notifier.abandonMatch, + onConfirm: () => notifier.endMatchWithStatus(MatchStatus.abandoned), ); } }); diff --git a/khelo/lib/ui/flow/score_board/score_board_view_model.dart b/khelo/lib/ui/flow/score_board/score_board_view_model.dart index 9e005d68..13ece04e 100644 --- a/khelo/lib/ui/flow/score_board/score_board_view_model.dart +++ b/khelo/lib/ui/flow/score_board/score_board_view_model.dart @@ -694,8 +694,7 @@ class ScoreBoardViewNotifier extends StateNotifier { element.id != bowlingTeamInningId); await addMatchEventIfNeeded(ball); if (wicketType != null) { - await addMatchPartnershipIfNeeded( - strikerId, nonStrikerId, matchId, ballInningId, ball); + await addMatchPartnershipIfNeeded(ball); } await _ballScoreService.addBallScoreAndUpdateTeamDetails( score: ball, @@ -800,16 +799,15 @@ class ScoreBoardViewNotifier extends StateNotifier { Future handleMilestonesMatchEvent( BallScoreModel ball, String playerId) async { final currentBattingStat = - state.currentScoresList.calculateBattingStats(currentUserId: playerId); + state.currentScoresList.calculateBattingStats(playerId); - final currentRun = currentBattingStat.runScored; + final currentRun = currentBattingStat.run_scored; final updatedList = state.currentScoresList.toList(); updatedList.add(ball); - final updatedBattingStat = - updatedList.calculateBattingStats(currentUserId: playerId); + final updatedBattingStat = updatedList.calculateBattingStats(playerId); - final runsAfterUpdate = updatedBattingStat.runScored; + final runsAfterUpdate = updatedBattingStat.run_scored; if ((currentRun < 50 && runsAfterUpdate >= 50) || (currentRun < 100 && runsAfterUpdate >= 100)) { MatchEventModel? matchEvent; @@ -825,9 +823,9 @@ class ScoreBoardViewNotifier extends StateNotifier { mileStone.add(MatchEventMilestone( time: ball.score_time ?? DateTime.now(), - runs: updatedBattingStat.runScored, + runs: updatedBattingStat.run_scored, over: ball.formattedOver, - ball_faced: updatedBattingStat.ballFaced, + ball_faced: updatedBattingStat.ball_faced, fours: updatedBattingStat.fours, sixes: updatedBattingStat.sixes, ball_id: ball.id, @@ -845,17 +843,12 @@ class ScoreBoardViewNotifier extends StateNotifier { } } - Future addMatchPartnershipIfNeeded( - String strikerId, - String nonStrikerId, - String matchId, - String inningId, - BallScoreModel ball, - ) async { + Future addMatchPartnershipIfNeeded(BallScoreModel ball) async { + final batsMen = [ball.batsman_id, ball.non_striker_id]; final scores = state.currentScoresList .where((element) => - [strikerId, nonStrikerId].contains(element.batsman_id) && - [strikerId, nonStrikerId].contains(element.non_striker_id)) + batsMen.contains(element.batsman_id) && + batsMen.contains(element.non_striker_id)) .toList(); scores.add(ball); @@ -881,24 +874,24 @@ class ScoreBoardViewNotifier extends StateNotifier { .compareTo(b.score_time ?? DateTime.now())); if (totalRuns > 50) { - final player = [strikerId, nonStrikerId].map( + final player = batsMen.map( (id) { - final stat = scores.calculateBattingStats(currentUserId: id); + final stat = scores.calculateBattingStats(id); return PartnershipPlayer( player_id: id, sixes: stat.sixes, fours: stat.fours, - runs: stat.runScored, - ball_faced: stat.ballFaced, + runs: stat.run_scored, + ball_faced: stat.ball_faced, ); }, ).toList(); final partnership = PartnershipModel( id: _partnershipService.generatePartnershipId, - match_id: matchId, - inning_id: inningId, - player_ids: [strikerId, nonStrikerId], + match_id: ball.match_id, + inning_id: ball.inning_id, + player_ids: batsMen, players: player, runs: totalRuns, extras: extras, @@ -1297,23 +1290,22 @@ class ScoreBoardViewNotifier extends StateNotifier { final scores = state.currentScoresList.toList(); scores.remove(ball); - final updatedBattingStat = - scores.calculateBattingStats(currentUserId: ball.batsman_id); + final updatedBattingStat = scores.calculateBattingStats(ball.batsman_id); if (mileStoneEvent != null && - (updatedBattingStat.runScored < + (updatedBattingStat.run_scored < (mileStoneEvent.type == EventType.fifty ? 50 : 100))) { final milestone = mileStoneEvent.milestone.toList(); milestone.removeWhere((element) => - (updatedBattingStat.runScored < 100 && element.runs >= 100) || - (updatedBattingStat.runScored < 50 && element.runs >= 50)); + (updatedBattingStat.run_scored < 100 && element.runs >= 100) || + (updatedBattingStat.run_scored < 50 && element.runs >= 50)); if (milestone.isEmpty) { await _matchEventService.deleteMatchEvent(mileStoneEvent.id); } else { await _matchEventService.updateMatchEvent(mileStoneEvent.copyWith( ball_ids: milestone.map((e) => e.ball_id).toList(), - type: updatedBattingStat.runScored >= 100 + type: updatedBattingStat.run_scored >= 100 ? EventType.century : EventType.fifty, milestone: milestone, @@ -1454,6 +1446,11 @@ class ScoreBoardViewNotifier extends StateNotifier { } try { state = state.copyWith(actionError: null, isActionInProgress: true); + + final ball = _getLastBallExceptPenaltyBall(); + if (ball != null && ball.wicket_type == null) { + await addMatchPartnershipIfNeeded(ball); + } _addPlayerStats(); final batsMan = state.batsMans! .map((e) => e.copyWith( @@ -1501,22 +1498,7 @@ class ScoreBoardViewNotifier extends StateNotifier { } } - Future abandonMatch() async { - final matchId = state.match?.id; - if (matchId == null) { - return; - } - try { - state = state.copyWith(actionError: null, isActionInProgress: true); - await _matchService.updateMatchStatus(matchId, MatchStatus.abandoned); - state = state.copyWith(pop: true, isActionInProgress: false); - } catch (e) { - debugPrint("ScoreBoardViewNotifier: error while abandon match -> $e"); - state = state.copyWith(actionError: e, isActionInProgress: false); - } - } - - Future endMatch() async { + Future endMatchWithStatus(MatchStatus status) async { final matchId = state.match?.id; final currentInningTeamId = state.currentInning?.team_id; final currentInningId = state.currentInning?.id; @@ -1527,6 +1509,11 @@ class ScoreBoardViewNotifier extends StateNotifier { } try { state = state.copyWith(actionError: null, isActionInProgress: true); + + final ball = _getLastBallExceptPenaltyBall(); + if (ball != null && ball.wicket_type == null) { + await addMatchPartnershipIfNeeded(ball); + } _addPlayerStats(isMatchComplete: true); List batsMan = []; if (state.batsMans?.isNotEmpty ?? false) { @@ -1549,7 +1536,7 @@ class ScoreBoardViewNotifier extends StateNotifier { await _inningService.updateInningStatus( inningId: currentInningId, status: InningStatus.finish); - await _matchService.updateMatchStatus(matchId, MatchStatus.finish); + await _matchService.updateMatchStatus(matchId, status); state = state.copyWith(pop: true, isActionInProgress: false); } catch (e) { From 5bf694c4eba35aa920dc765e00d2797a93b305fd Mon Sep 17 00:00:00 2001 From: sidhdhi canopas Date: Thu, 5 Dec 2024 11:39:01 +0530 Subject: [PATCH 4/5] use combine --- .../score_board/score_board_view_model.dart | 52 ++++++------------- 1 file changed, 16 insertions(+), 36 deletions(-) diff --git a/khelo/lib/ui/flow/score_board/score_board_view_model.dart b/khelo/lib/ui/flow/score_board/score_board_view_model.dart index 13ece04e..c09e08d8 100644 --- a/khelo/lib/ui/flow/score_board/score_board_view_model.dart +++ b/khelo/lib/ui/flow/score_board/score_board_view_model.dart @@ -48,8 +48,7 @@ class ScoreBoardViewNotifier extends StateNotifier { StreamSubscription? _matchStreamSubscription; StreamSubscription>? _ballScoreStreamSubscription; StreamSubscription? _matchSettingSubscription; - StreamSubscription>? _matchEventSubscription; - StreamSubscription>? _matchPartnershipSubscription; + StreamSubscription? _matchEventSubscription; final StreamController _matchStreamController = StreamController.broadcast(); String? matchId; @@ -69,12 +68,12 @@ class ScoreBoardViewNotifier extends StateNotifier { this.matchId = matchId; _loadMatchesAndInning(); _loadMatchSetting(); - _loadMatchEvent(); - _loadMatchPartnership(); + _loadMatchEventAndPartnership(); } void _loadMatchSetting() { if (matchId == null) return; + _matchSettingSubscription?.cancel(); _matchSettingSubscription = _matchService.streamMatchSetting(matchId!).listen((setting) { state = state.copyWith(matchSetting: setting ?? state.matchSetting); @@ -177,37 +176,19 @@ class ScoreBoardViewNotifier extends StateNotifier { } } - void _loadMatchEvent() { - try { - if (matchId == null) return; - _matchEventSubscription?.cancel(); - _matchEventSubscription = _matchEventService - .streamEventsByMatches(matchId!) - .listen((events) => matchEvents = events, onError: (e) { - debugPrint( - "ScoreBoardViewNotifier: error while loading match event -> $e"); - }); - } catch (e) { - debugPrint( - "ScoreBoardViewNotifier: error while loading match event -> $e"); - } - } - - void _loadMatchPartnership() { - try { - if (matchId == null) return; - _matchPartnershipSubscription?.cancel(); - _matchPartnershipSubscription = _partnershipService - .streamPartnershipByMatches(matchId!) - .listen((matchPartnership) => partnerships = matchPartnership, - onError: (e) { - debugPrint( - "ScoreBoardViewNotifier: error while loading partnership -> $e"); - }); - } catch (e) { + void _loadMatchEventAndPartnership() { + if (matchId == null) return; + _matchEventSubscription?.cancel(); + _matchEventSubscription = combineLatest2( + _matchEventService.streamEventsByMatches(matchId!), + _partnershipService.streamPartnershipByMatches(matchId!), + ).listen((event) { + matchEvents = event.$1; + partnerships = event.$2; + }, onError: (e) { debugPrint( - "ScoreBoardViewNotifier: error while loading partnership -> $e"); - } + "ScoreBoardViewNotifier: error while loading match event and Partnerships -> $e"); + }); } bool _isSelectInning( @@ -1269,7 +1250,7 @@ class ScoreBoardViewNotifier extends StateNotifier { } else { final wickets = event.wickets.toList(); wickets.removeWhere((element) => element.ball_id == ball.id); - _matchEventService.updateMatchEvent(event.copyWith( + await _matchEventService.updateMatchEvent(event.copyWith( ball_ids: wickets.map((e) => e.ball_id).toList(), type: EventType.wicket, wickets: wickets, @@ -1909,7 +1890,6 @@ class ScoreBoardViewNotifier extends StateNotifier { await _ballScoreStreamSubscription?.cancel(); await _matchSettingSubscription?.cancel(); await _matchEventSubscription?.cancel(); - await _matchPartnershipSubscription?.cancel(); await _matchStreamController.close(); } From 7fcb328d77d0a49eb017aedb82861125dd07e303 Mon Sep 17 00:00:00 2001 From: sidhdhi canopas Date: Fri, 6 Dec 2024 09:47:09 +0530 Subject: [PATCH 5/5] minor change --- .../api/match_event/match_event_model.dart | 9 +- .../match_event_model.freezed.dart | 195 +++++++++--------- .../api/match_event/match_event_model.g.dart | 20 +- .../score_board/score_board_view_model.dart | 3 - 4 files changed, 111 insertions(+), 116 deletions(-) diff --git a/data/lib/api/match_event/match_event_model.dart b/data/lib/api/match_event/match_event_model.dart index cf14e3a2..ed3c8986 100644 --- a/data/lib/api/match_event/match_event_model.dart +++ b/data/lib/api/match_event/match_event_model.dart @@ -17,15 +17,14 @@ class MatchEventModel with _$MatchEventModel { required String match_id, required String inning_id, required EventType type, + @TimeStampJsonConverter() required DateTime time, String? bowler_id, + String? batsman_id, + FieldingPositionType? fielding_position, + @Default(0) double over, @Default([]) List ball_ids, @Default([]) List wickets, @Default([]) List milestone, - @TimeStampJsonConverter() required DateTime time, - String? batsman_id, - @Default(0) double over, - FieldingPositionType? fielding_position, - }) = _MatchEventModel; factory MatchEventModel.fromJson(Map json) => diff --git a/data/lib/api/match_event/match_event_model.freezed.dart b/data/lib/api/match_event/match_event_model.freezed.dart index 82402fd3..eba2b997 100644 --- a/data/lib/api/match_event/match_event_model.freezed.dart +++ b/data/lib/api/match_event/match_event_model.freezed.dart @@ -24,16 +24,16 @@ mixin _$MatchEventModel { String get match_id => throw _privateConstructorUsedError; String get inning_id => throw _privateConstructorUsedError; EventType get type => throw _privateConstructorUsedError; - String? get bowler_id => throw _privateConstructorUsedError; - List get ball_ids => throw _privateConstructorUsedError; - List get wickets => throw _privateConstructorUsedError; - List get milestone => throw _privateConstructorUsedError; @TimeStampJsonConverter() DateTime get time => throw _privateConstructorUsedError; + String? get bowler_id => throw _privateConstructorUsedError; String? get batsman_id => throw _privateConstructorUsedError; - double get over => throw _privateConstructorUsedError; FieldingPositionType? get fielding_position => throw _privateConstructorUsedError; + double get over => throw _privateConstructorUsedError; + List get ball_ids => throw _privateConstructorUsedError; + List get wickets => throw _privateConstructorUsedError; + List get milestone => throw _privateConstructorUsedError; /// Serializes this MatchEventModel to a JSON map. Map toJson() => throw _privateConstructorUsedError; @@ -56,14 +56,14 @@ abstract class $MatchEventModelCopyWith<$Res> { String match_id, String inning_id, EventType type, - String? bowler_id, - List ball_ids, - List wickets, - List milestone, @TimeStampJsonConverter() DateTime time, + String? bowler_id, String? batsman_id, + FieldingPositionType? fielding_position, double over, - FieldingPositionType? fielding_position}); + List ball_ids, + List wickets, + List milestone}); } /// @nodoc @@ -85,14 +85,14 @@ class _$MatchEventModelCopyWithImpl<$Res, $Val extends MatchEventModel> Object? match_id = null, Object? inning_id = null, Object? type = null, + Object? time = null, Object? bowler_id = freezed, + Object? batsman_id = freezed, + Object? fielding_position = freezed, + Object? over = null, Object? ball_ids = null, Object? wickets = null, Object? milestone = null, - Object? time = null, - Object? batsman_id = freezed, - Object? over = null, - Object? fielding_position = freezed, }) { return _then(_value.copyWith( id: null == id @@ -111,10 +111,26 @@ class _$MatchEventModelCopyWithImpl<$Res, $Val extends MatchEventModel> ? _value.type : type // ignore: cast_nullable_to_non_nullable as EventType, + time: null == time + ? _value.time + : time // ignore: cast_nullable_to_non_nullable + as DateTime, bowler_id: freezed == bowler_id ? _value.bowler_id : bowler_id // ignore: cast_nullable_to_non_nullable as String?, + batsman_id: freezed == batsman_id + ? _value.batsman_id + : batsman_id // ignore: cast_nullable_to_non_nullable + as String?, + fielding_position: freezed == fielding_position + ? _value.fielding_position + : fielding_position // ignore: cast_nullable_to_non_nullable + as FieldingPositionType?, + over: null == over + ? _value.over + : over // ignore: cast_nullable_to_non_nullable + as double, ball_ids: null == ball_ids ? _value.ball_ids : ball_ids // ignore: cast_nullable_to_non_nullable @@ -127,22 +143,6 @@ class _$MatchEventModelCopyWithImpl<$Res, $Val extends MatchEventModel> ? _value.milestone : milestone // ignore: cast_nullable_to_non_nullable as List, - time: null == time - ? _value.time - : time // ignore: cast_nullable_to_non_nullable - as DateTime, - batsman_id: freezed == batsman_id - ? _value.batsman_id - : batsman_id // ignore: cast_nullable_to_non_nullable - as String?, - over: null == over - ? _value.over - : over // ignore: cast_nullable_to_non_nullable - as double, - fielding_position: freezed == fielding_position - ? _value.fielding_position - : fielding_position // ignore: cast_nullable_to_non_nullable - as FieldingPositionType?, ) as $Val); } } @@ -160,14 +160,14 @@ abstract class _$$MatchEventModelImplCopyWith<$Res> String match_id, String inning_id, EventType type, - String? bowler_id, - List ball_ids, - List wickets, - List milestone, @TimeStampJsonConverter() DateTime time, + String? bowler_id, String? batsman_id, + FieldingPositionType? fielding_position, double over, - FieldingPositionType? fielding_position}); + List ball_ids, + List wickets, + List milestone}); } /// @nodoc @@ -187,14 +187,14 @@ class __$$MatchEventModelImplCopyWithImpl<$Res> Object? match_id = null, Object? inning_id = null, Object? type = null, + Object? time = null, Object? bowler_id = freezed, + Object? batsman_id = freezed, + Object? fielding_position = freezed, + Object? over = null, Object? ball_ids = null, Object? wickets = null, Object? milestone = null, - Object? time = null, - Object? batsman_id = freezed, - Object? over = null, - Object? fielding_position = freezed, }) { return _then(_$MatchEventModelImpl( id: null == id @@ -213,10 +213,26 @@ class __$$MatchEventModelImplCopyWithImpl<$Res> ? _value.type : type // ignore: cast_nullable_to_non_nullable as EventType, + time: null == time + ? _value.time + : time // ignore: cast_nullable_to_non_nullable + as DateTime, bowler_id: freezed == bowler_id ? _value.bowler_id : bowler_id // ignore: cast_nullable_to_non_nullable as String?, + batsman_id: freezed == batsman_id + ? _value.batsman_id + : batsman_id // ignore: cast_nullable_to_non_nullable + as String?, + fielding_position: freezed == fielding_position + ? _value.fielding_position + : fielding_position // ignore: cast_nullable_to_non_nullable + as FieldingPositionType?, + over: null == over + ? _value.over + : over // ignore: cast_nullable_to_non_nullable + as double, ball_ids: null == ball_ids ? _value._ball_ids : ball_ids // ignore: cast_nullable_to_non_nullable @@ -229,22 +245,6 @@ class __$$MatchEventModelImplCopyWithImpl<$Res> ? _value._milestone : milestone // ignore: cast_nullable_to_non_nullable as List, - time: null == time - ? _value.time - : time // ignore: cast_nullable_to_non_nullable - as DateTime, - batsman_id: freezed == batsman_id - ? _value.batsman_id - : batsman_id // ignore: cast_nullable_to_non_nullable - as String?, - over: null == over - ? _value.over - : over // ignore: cast_nullable_to_non_nullable - as double, - fielding_position: freezed == fielding_position - ? _value.fielding_position - : fielding_position // ignore: cast_nullable_to_non_nullable - as FieldingPositionType?, )); } } @@ -258,14 +258,14 @@ class _$MatchEventModelImpl implements _MatchEventModel { required this.match_id, required this.inning_id, required this.type, - this.bowler_id, - final List ball_ids = const [], - final List wickets = const [], - final List milestone = const [], @TimeStampJsonConverter() required this.time, + this.bowler_id, this.batsman_id, + this.fielding_position, this.over = 0, - this.fielding_position}) + final List ball_ids = const [], + final List wickets = const [], + final List milestone = const []}) : _ball_ids = ball_ids, _wickets = wickets, _milestone = milestone; @@ -282,7 +282,17 @@ class _$MatchEventModelImpl implements _MatchEventModel { @override final EventType type; @override + @TimeStampJsonConverter() + final DateTime time; + @override final String? bowler_id; + @override + final String? batsman_id; + @override + final FieldingPositionType? fielding_position; + @override + @JsonKey() + final double over; final List _ball_ids; @override @JsonKey() @@ -310,20 +320,9 @@ class _$MatchEventModelImpl implements _MatchEventModel { return EqualUnmodifiableListView(_milestone); } - @override - @TimeStampJsonConverter() - final DateTime time; - @override - final String? batsman_id; - @override - @JsonKey() - final double over; - @override - final FieldingPositionType? fielding_position; - @override String toString() { - return 'MatchEventModel(id: $id, match_id: $match_id, inning_id: $inning_id, type: $type, bowler_id: $bowler_id, ball_ids: $ball_ids, wickets: $wickets, milestone: $milestone, time: $time, batsman_id: $batsman_id, over: $over, fielding_position: $fielding_position)'; + return 'MatchEventModel(id: $id, match_id: $match_id, inning_id: $inning_id, type: $type, time: $time, bowler_id: $bowler_id, batsman_id: $batsman_id, fielding_position: $fielding_position, over: $over, ball_ids: $ball_ids, wickets: $wickets, milestone: $milestone)'; } @override @@ -337,18 +336,18 @@ class _$MatchEventModelImpl implements _MatchEventModel { (identical(other.inning_id, inning_id) || other.inning_id == inning_id) && (identical(other.type, type) || other.type == type) && + (identical(other.time, time) || other.time == time) && (identical(other.bowler_id, bowler_id) || other.bowler_id == bowler_id) && - const DeepCollectionEquality().equals(other._ball_ids, _ball_ids) && - const DeepCollectionEquality().equals(other._wickets, _wickets) && - const DeepCollectionEquality() - .equals(other._milestone, _milestone) && - (identical(other.time, time) || other.time == time) && (identical(other.batsman_id, batsman_id) || other.batsman_id == batsman_id) && - (identical(other.over, over) || other.over == over) && (identical(other.fielding_position, fielding_position) || - other.fielding_position == fielding_position)); + other.fielding_position == fielding_position) && + (identical(other.over, over) || other.over == over) && + const DeepCollectionEquality().equals(other._ball_ids, _ball_ids) && + const DeepCollectionEquality().equals(other._wickets, _wickets) && + const DeepCollectionEquality() + .equals(other._milestone, _milestone)); } @JsonKey(includeFromJson: false, includeToJson: false) @@ -359,14 +358,14 @@ class _$MatchEventModelImpl implements _MatchEventModel { match_id, inning_id, type, - bowler_id, - const DeepCollectionEquality().hash(_ball_ids), - const DeepCollectionEquality().hash(_wickets), - const DeepCollectionEquality().hash(_milestone), time, + bowler_id, batsman_id, + fielding_position, over, - fielding_position); + const DeepCollectionEquality().hash(_ball_ids), + const DeepCollectionEquality().hash(_wickets), + const DeepCollectionEquality().hash(_milestone)); /// Create a copy of MatchEventModel /// with the given fields replaced by the non-null parameter values. @@ -391,14 +390,14 @@ abstract class _MatchEventModel implements MatchEventModel { required final String match_id, required final String inning_id, required final EventType type, - final String? bowler_id, - final List ball_ids, - final List wickets, - final List milestone, @TimeStampJsonConverter() required final DateTime time, + final String? bowler_id, final String? batsman_id, + final FieldingPositionType? fielding_position, final double over, - final FieldingPositionType? fielding_position}) = _$MatchEventModelImpl; + final List ball_ids, + final List wickets, + final List milestone}) = _$MatchEventModelImpl; factory _MatchEventModel.fromJson(Map json) = _$MatchEventModelImpl.fromJson; @@ -412,22 +411,22 @@ abstract class _MatchEventModel implements MatchEventModel { @override EventType get type; @override - String? get bowler_id; - @override - List get ball_ids; - @override - List get wickets; - @override - List get milestone; - @override @TimeStampJsonConverter() DateTime get time; @override + String? get bowler_id; + @override String? get batsman_id; @override + FieldingPositionType? get fielding_position; + @override double get over; @override - FieldingPositionType? get fielding_position; + List get ball_ids; + @override + List get wickets; + @override + List get milestone; /// Create a copy of MatchEventModel /// with the given fields replaced by the non-null parameter values. diff --git a/data/lib/api/match_event/match_event_model.g.dart b/data/lib/api/match_event/match_event_model.g.dart index e996256a..7316fd78 100644 --- a/data/lib/api/match_event/match_event_model.g.dart +++ b/data/lib/api/match_event/match_event_model.g.dart @@ -12,7 +12,12 @@ _$MatchEventModelImpl _$$MatchEventModelImplFromJson(Map json) => match_id: json['match_id'] as String, inning_id: json['inning_id'] as String, type: $enumDecode(_$EventTypeEnumMap, json['type']), + time: const TimeStampJsonConverter().fromJson(json['time'] as Object), bowler_id: json['bowler_id'] as String?, + batsman_id: json['batsman_id'] as String?, + fielding_position: $enumDecodeNullable( + _$FieldingPositionTypeEnumMap, json['fielding_position']), + over: (json['over'] as num?)?.toDouble() ?? 0, ball_ids: (json['ball_ids'] as List?) ?.map((e) => e as String) .toList() ?? @@ -27,11 +32,6 @@ _$MatchEventModelImpl _$$MatchEventModelImplFromJson(Map json) => Map.from(e as Map))) .toList() ?? const [], - time: const TimeStampJsonConverter().fromJson(json['time'] as Object), - batsman_id: json['batsman_id'] as String?, - over: (json['over'] as num?)?.toDouble() ?? 0, - fielding_position: $enumDecodeNullable( - _$FieldingPositionTypeEnumMap, json['fielding_position']), ); Map _$$MatchEventModelImplToJson( @@ -41,6 +41,7 @@ Map _$$MatchEventModelImplToJson( 'match_id': instance.match_id, 'inning_id': instance.inning_id, 'type': _$EventTypeEnumMap[instance.type]!, + 'time': const TimeStampJsonConverter().toJson(instance.time), }; void writeNotNull(String key, dynamic value) { @@ -50,14 +51,13 @@ Map _$$MatchEventModelImplToJson( } writeNotNull('bowler_id', instance.bowler_id); - val['ball_ids'] = instance.ball_ids; - val['wickets'] = instance.wickets.map((e) => e.toJson()).toList(); - val['milestone'] = instance.milestone.map((e) => e.toJson()).toList(); - val['time'] = const TimeStampJsonConverter().toJson(instance.time); writeNotNull('batsman_id', instance.batsman_id); - val['over'] = instance.over; writeNotNull('fielding_position', _$FieldingPositionTypeEnumMap[instance.fielding_position]); + val['over'] = instance.over; + val['ball_ids'] = instance.ball_ids; + val['wickets'] = instance.wickets.map((e) => e.toJson()).toList(); + val['milestone'] = instance.milestone.map((e) => e.toJson()).toList(); return val; } diff --git a/khelo/lib/ui/flow/score_board/score_board_view_model.dart b/khelo/lib/ui/flow/score_board/score_board_view_model.dart index c09e08d8..4dad1db3 100644 --- a/khelo/lib/ui/flow/score_board/score_board_view_model.dart +++ b/khelo/lib/ui/flow/score_board/score_board_view_model.dart @@ -718,9 +718,6 @@ class ScoreBoardViewNotifier extends StateNotifier { )); } else if (ball.wicket_type != null) { await handleWicketMatchEvent(ball); - if (ball.player_out_id != ball.batsman_id) { - await handleMilestonesMatchEvent(ball, ball.player_out_id!); - } } await handleMilestonesMatchEvent(ball, ball.batsman_id);