forked from eatvio/eatvio_app
fixed pagination
This commit is contained in:
@@ -1,5 +1,6 @@
|
||||
import 'package:eatvio_app/features/chat/models/chat_room_settings_model.dart';
|
||||
import 'package:eatvio_app/features/chat/models/chat_user_model.dart';
|
||||
import 'package:eatvio_app/features/plans/models/chosen_plan_model.dart';
|
||||
import 'package:freezed_annotation/freezed_annotation.dart';
|
||||
|
||||
part 'chat_room_model.freezed.dart';
|
||||
@@ -11,7 +12,15 @@ class ChatRoomModel with _$ChatRoomModel {
|
||||
required String id,
|
||||
@JsonKey(name: 'chat_room_setting') required ChatRoomSettingsModel chatRoomSettings,
|
||||
required Map<String, ChatUserModel> users,
|
||||
@JsonKey(name: 'chosen_plan', fromJson: _parseChosenPlan) required ChosenPlanModel? chosenPlan,
|
||||
}) = _ChatRoomModel;
|
||||
|
||||
factory ChatRoomModel.fromJson(Map<String, Object?> json) => _$ChatRoomModelFromJson(json);
|
||||
}
|
||||
|
||||
ChosenPlanModel? _parseChosenPlan(json) {
|
||||
if (json is Map<String, dynamic>) {
|
||||
return ChosenPlanModel.fromJson(json);
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
@@ -25,6 +25,8 @@ mixin _$ChatRoomModel {
|
||||
ChatRoomSettingsModel get chatRoomSettings =>
|
||||
throw _privateConstructorUsedError;
|
||||
Map<String, ChatUserModel> get users => throw _privateConstructorUsedError;
|
||||
@JsonKey(name: 'chosen_plan', fromJson: _parseChosenPlan)
|
||||
ChosenPlanModel? get chosenPlan => throw _privateConstructorUsedError;
|
||||
|
||||
/// Serializes this ChatRoomModel to a JSON map.
|
||||
Map<String, dynamic> toJson() => throw _privateConstructorUsedError;
|
||||
@@ -46,9 +48,12 @@ abstract class $ChatRoomModelCopyWith<$Res> {
|
||||
{String id,
|
||||
@JsonKey(name: 'chat_room_setting')
|
||||
ChatRoomSettingsModel chatRoomSettings,
|
||||
Map<String, ChatUserModel> users});
|
||||
Map<String, ChatUserModel> users,
|
||||
@JsonKey(name: 'chosen_plan', fromJson: _parseChosenPlan)
|
||||
ChosenPlanModel? chosenPlan});
|
||||
|
||||
$ChatRoomSettingsModelCopyWith<$Res> get chatRoomSettings;
|
||||
$ChosenPlanModelCopyWith<$Res>? get chosenPlan;
|
||||
}
|
||||
|
||||
/// @nodoc
|
||||
@@ -69,6 +74,7 @@ class _$ChatRoomModelCopyWithImpl<$Res, $Val extends ChatRoomModel>
|
||||
Object? id = null,
|
||||
Object? chatRoomSettings = null,
|
||||
Object? users = null,
|
||||
Object? chosenPlan = freezed,
|
||||
}) {
|
||||
return _then(_value.copyWith(
|
||||
id: null == id
|
||||
@@ -83,6 +89,10 @@ class _$ChatRoomModelCopyWithImpl<$Res, $Val extends ChatRoomModel>
|
||||
? _value.users
|
||||
: users // ignore: cast_nullable_to_non_nullable
|
||||
as Map<String, ChatUserModel>,
|
||||
chosenPlan: freezed == chosenPlan
|
||||
? _value.chosenPlan
|
||||
: chosenPlan // ignore: cast_nullable_to_non_nullable
|
||||
as ChosenPlanModel?,
|
||||
) as $Val);
|
||||
}
|
||||
|
||||
@@ -96,6 +106,20 @@ class _$ChatRoomModelCopyWithImpl<$Res, $Val extends ChatRoomModel>
|
||||
return _then(_value.copyWith(chatRoomSettings: value) as $Val);
|
||||
});
|
||||
}
|
||||
|
||||
/// Create a copy of ChatRoomModel
|
||||
/// with the given fields replaced by the non-null parameter values.
|
||||
@override
|
||||
@pragma('vm:prefer-inline')
|
||||
$ChosenPlanModelCopyWith<$Res>? get chosenPlan {
|
||||
if (_value.chosenPlan == null) {
|
||||
return null;
|
||||
}
|
||||
|
||||
return $ChosenPlanModelCopyWith<$Res>(_value.chosenPlan!, (value) {
|
||||
return _then(_value.copyWith(chosenPlan: value) as $Val);
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
/// @nodoc
|
||||
@@ -110,10 +134,14 @@ abstract class _$$ChatRoomModelImplCopyWith<$Res>
|
||||
{String id,
|
||||
@JsonKey(name: 'chat_room_setting')
|
||||
ChatRoomSettingsModel chatRoomSettings,
|
||||
Map<String, ChatUserModel> users});
|
||||
Map<String, ChatUserModel> users,
|
||||
@JsonKey(name: 'chosen_plan', fromJson: _parseChosenPlan)
|
||||
ChosenPlanModel? chosenPlan});
|
||||
|
||||
@override
|
||||
$ChatRoomSettingsModelCopyWith<$Res> get chatRoomSettings;
|
||||
@override
|
||||
$ChosenPlanModelCopyWith<$Res>? get chosenPlan;
|
||||
}
|
||||
|
||||
/// @nodoc
|
||||
@@ -132,6 +160,7 @@ class __$$ChatRoomModelImplCopyWithImpl<$Res>
|
||||
Object? id = null,
|
||||
Object? chatRoomSettings = null,
|
||||
Object? users = null,
|
||||
Object? chosenPlan = freezed,
|
||||
}) {
|
||||
return _then(_$ChatRoomModelImpl(
|
||||
id: null == id
|
||||
@@ -146,6 +175,10 @@ class __$$ChatRoomModelImplCopyWithImpl<$Res>
|
||||
? _value._users
|
||||
: users // ignore: cast_nullable_to_non_nullable
|
||||
as Map<String, ChatUserModel>,
|
||||
chosenPlan: freezed == chosenPlan
|
||||
? _value.chosenPlan
|
||||
: chosenPlan // ignore: cast_nullable_to_non_nullable
|
||||
as ChosenPlanModel?,
|
||||
));
|
||||
}
|
||||
}
|
||||
@@ -156,7 +189,9 @@ class _$ChatRoomModelImpl implements _ChatRoomModel {
|
||||
const _$ChatRoomModelImpl(
|
||||
{required this.id,
|
||||
@JsonKey(name: 'chat_room_setting') required this.chatRoomSettings,
|
||||
required final Map<String, ChatUserModel> users})
|
||||
required final Map<String, ChatUserModel> users,
|
||||
@JsonKey(name: 'chosen_plan', fromJson: _parseChosenPlan)
|
||||
required this.chosenPlan})
|
||||
: _users = users;
|
||||
|
||||
factory _$ChatRoomModelImpl.fromJson(Map<String, dynamic> json) =>
|
||||
@@ -175,9 +210,13 @@ class _$ChatRoomModelImpl implements _ChatRoomModel {
|
||||
return EqualUnmodifiableMapView(_users);
|
||||
}
|
||||
|
||||
@override
|
||||
@JsonKey(name: 'chosen_plan', fromJson: _parseChosenPlan)
|
||||
final ChosenPlanModel? chosenPlan;
|
||||
|
||||
@override
|
||||
String toString() {
|
||||
return 'ChatRoomModel(id: $id, chatRoomSettings: $chatRoomSettings, users: $users)';
|
||||
return 'ChatRoomModel(id: $id, chatRoomSettings: $chatRoomSettings, users: $users, chosenPlan: $chosenPlan)';
|
||||
}
|
||||
|
||||
@override
|
||||
@@ -188,13 +227,15 @@ class _$ChatRoomModelImpl implements _ChatRoomModel {
|
||||
(identical(other.id, id) || other.id == id) &&
|
||||
(identical(other.chatRoomSettings, chatRoomSettings) ||
|
||||
other.chatRoomSettings == chatRoomSettings) &&
|
||||
const DeepCollectionEquality().equals(other._users, _users));
|
||||
const DeepCollectionEquality().equals(other._users, _users) &&
|
||||
(identical(other.chosenPlan, chosenPlan) ||
|
||||
other.chosenPlan == chosenPlan));
|
||||
}
|
||||
|
||||
@JsonKey(includeFromJson: false, includeToJson: false)
|
||||
@override
|
||||
int get hashCode => Object.hash(runtimeType, id, chatRoomSettings,
|
||||
const DeepCollectionEquality().hash(_users));
|
||||
const DeepCollectionEquality().hash(_users), chosenPlan);
|
||||
|
||||
/// Create a copy of ChatRoomModel
|
||||
/// with the given fields replaced by the non-null parameter values.
|
||||
@@ -217,7 +258,9 @@ abstract class _ChatRoomModel implements ChatRoomModel {
|
||||
{required final String id,
|
||||
@JsonKey(name: 'chat_room_setting')
|
||||
required final ChatRoomSettingsModel chatRoomSettings,
|
||||
required final Map<String, ChatUserModel> users}) = _$ChatRoomModelImpl;
|
||||
required final Map<String, ChatUserModel> users,
|
||||
@JsonKey(name: 'chosen_plan', fromJson: _parseChosenPlan)
|
||||
required final ChosenPlanModel? chosenPlan}) = _$ChatRoomModelImpl;
|
||||
|
||||
factory _ChatRoomModel.fromJson(Map<String, dynamic> json) =
|
||||
_$ChatRoomModelImpl.fromJson;
|
||||
@@ -229,6 +272,9 @@ abstract class _ChatRoomModel implements ChatRoomModel {
|
||||
ChatRoomSettingsModel get chatRoomSettings;
|
||||
@override
|
||||
Map<String, ChatUserModel> get users;
|
||||
@override
|
||||
@JsonKey(name: 'chosen_plan', fromJson: _parseChosenPlan)
|
||||
ChosenPlanModel? get chosenPlan;
|
||||
|
||||
/// Create a copy of ChatRoomModel
|
||||
/// with the given fields replaced by the non-null parameter values.
|
||||
|
||||
@@ -15,6 +15,7 @@ _$ChatRoomModelImpl _$$ChatRoomModelImplFromJson(Map<String, dynamic> json) =>
|
||||
(k, e) =>
|
||||
MapEntry(k, ChatUserModel.fromJson(e as Map<String, dynamic>)),
|
||||
),
|
||||
chosenPlan: _parseChosenPlan(json['chosen_plan']),
|
||||
);
|
||||
|
||||
Map<String, dynamic> _$$ChatRoomModelImplToJson(_$ChatRoomModelImpl instance) =>
|
||||
@@ -22,4 +23,5 @@ Map<String, dynamic> _$$ChatRoomModelImplToJson(_$ChatRoomModelImpl instance) =>
|
||||
'id': instance.id,
|
||||
'chat_room_setting': instance.chatRoomSettings,
|
||||
'users': instance.users,
|
||||
'chosen_plan': instance.chosenPlan,
|
||||
};
|
||||
|
||||
@@ -1,16 +1,28 @@
|
||||
import 'package:eatvio_app/features/chat/models/chat_message_model.dart';
|
||||
import 'package:freezed_annotation/freezed_annotation.dart';
|
||||
|
||||
part 'chat_room_preview_model.freezed.dart';
|
||||
part 'chat_room_preview_model.g.dart';
|
||||
part 'chat_room_pagination_model.freezed.dart';
|
||||
part 'chat_room_pagination_model.g.dart';
|
||||
|
||||
@freezed
|
||||
class ChatRoomPreviewModel with _$ChatRoomPreviewModel {
|
||||
const factory ChatRoomPreviewModel({
|
||||
@JsonKey(name: "chatRooms") required List<ChatRoom> chatRooms,
|
||||
class ChatRoomPaginationModel with _$ChatRoomPaginationModel {
|
||||
const factory ChatRoomPaginationModel({
|
||||
@JsonKey(name: "chatRooms") required ChatRooms chatRooms,
|
||||
@JsonKey(name: "number_of_unread_chat_rooms") required int unreadChatsCount,
|
||||
}) = _ChatRoomPreviewModel;
|
||||
|
||||
factory ChatRoomPreviewModel.fromJson(Map<String, dynamic> json) => _$ChatRoomPreviewModelFromJson(json);
|
||||
factory ChatRoomPaginationModel.fromJson(Map<String, dynamic> json) => _$ChatRoomPaginationModelFromJson(json);
|
||||
}
|
||||
|
||||
@freezed
|
||||
class ChatRooms with _$ChatRooms {
|
||||
const factory ChatRooms({
|
||||
@JsonKey(name: "data") required List<ChatRoom> data,
|
||||
@JsonKey(name: "last_page") required int lastPage,
|
||||
@JsonKey(name: "current_page") required int currentPage,
|
||||
}) = _ChatRooms;
|
||||
|
||||
factory ChatRooms.fromJson(Map<String, dynamic> json) => _$ChatRoomsFromJson(json);
|
||||
}
|
||||
|
||||
@freezed
|
||||
@@ -3,7 +3,7 @@
|
||||
// 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 'chat_room_preview_model.dart';
|
||||
part of 'chat_room_pagination_model.dart';
|
||||
|
||||
// **************************************************************************
|
||||
// FreezedGenerator
|
||||
@@ -14,92 +14,125 @@ T _$identity<T>(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');
|
||||
|
||||
ChatRoomPreviewModel _$ChatRoomPreviewModelFromJson(Map<String, dynamic> json) {
|
||||
ChatRoomPaginationModel _$ChatRoomPaginationModelFromJson(
|
||||
Map<String, dynamic> json) {
|
||||
return _ChatRoomPreviewModel.fromJson(json);
|
||||
}
|
||||
|
||||
/// @nodoc
|
||||
mixin _$ChatRoomPreviewModel {
|
||||
mixin _$ChatRoomPaginationModel {
|
||||
@JsonKey(name: "chatRooms")
|
||||
List<ChatRoom> get chatRooms => throw _privateConstructorUsedError;
|
||||
ChatRooms get chatRooms => throw _privateConstructorUsedError;
|
||||
@JsonKey(name: "number_of_unread_chat_rooms")
|
||||
int get unreadChatsCount => throw _privateConstructorUsedError;
|
||||
|
||||
/// Serializes this ChatRoomPreviewModel to a JSON map.
|
||||
/// Serializes this ChatRoomPaginationModel to a JSON map.
|
||||
Map<String, dynamic> toJson() => throw _privateConstructorUsedError;
|
||||
|
||||
/// Create a copy of ChatRoomPreviewModel
|
||||
/// Create a copy of ChatRoomPaginationModel
|
||||
/// with the given fields replaced by the non-null parameter values.
|
||||
@JsonKey(includeFromJson: false, includeToJson: false)
|
||||
$ChatRoomPreviewModelCopyWith<ChatRoomPreviewModel> get copyWith =>
|
||||
$ChatRoomPaginationModelCopyWith<ChatRoomPaginationModel> get copyWith =>
|
||||
throw _privateConstructorUsedError;
|
||||
}
|
||||
|
||||
/// @nodoc
|
||||
abstract class $ChatRoomPreviewModelCopyWith<$Res> {
|
||||
factory $ChatRoomPreviewModelCopyWith(ChatRoomPreviewModel value,
|
||||
$Res Function(ChatRoomPreviewModel) then) =
|
||||
_$ChatRoomPreviewModelCopyWithImpl<$Res, ChatRoomPreviewModel>;
|
||||
abstract class $ChatRoomPaginationModelCopyWith<$Res> {
|
||||
factory $ChatRoomPaginationModelCopyWith(ChatRoomPaginationModel value,
|
||||
$Res Function(ChatRoomPaginationModel) then) =
|
||||
_$ChatRoomPaginationModelCopyWithImpl<$Res, ChatRoomPaginationModel>;
|
||||
@useResult
|
||||
$Res call({@JsonKey(name: "chatRooms") List<ChatRoom> chatRooms});
|
||||
$Res call(
|
||||
{@JsonKey(name: "chatRooms") ChatRooms chatRooms,
|
||||
@JsonKey(name: "number_of_unread_chat_rooms") int unreadChatsCount});
|
||||
|
||||
$ChatRoomsCopyWith<$Res> get chatRooms;
|
||||
}
|
||||
|
||||
/// @nodoc
|
||||
class _$ChatRoomPreviewModelCopyWithImpl<$Res,
|
||||
$Val extends ChatRoomPreviewModel>
|
||||
implements $ChatRoomPreviewModelCopyWith<$Res> {
|
||||
_$ChatRoomPreviewModelCopyWithImpl(this._value, this._then);
|
||||
class _$ChatRoomPaginationModelCopyWithImpl<$Res,
|
||||
$Val extends ChatRoomPaginationModel>
|
||||
implements $ChatRoomPaginationModelCopyWith<$Res> {
|
||||
_$ChatRoomPaginationModelCopyWithImpl(this._value, this._then);
|
||||
|
||||
// ignore: unused_field
|
||||
final $Val _value;
|
||||
// ignore: unused_field
|
||||
final $Res Function($Val) _then;
|
||||
|
||||
/// Create a copy of ChatRoomPreviewModel
|
||||
/// Create a copy of ChatRoomPaginationModel
|
||||
/// with the given fields replaced by the non-null parameter values.
|
||||
@pragma('vm:prefer-inline')
|
||||
@override
|
||||
$Res call({
|
||||
Object? chatRooms = null,
|
||||
Object? unreadChatsCount = null,
|
||||
}) {
|
||||
return _then(_value.copyWith(
|
||||
chatRooms: null == chatRooms
|
||||
? _value.chatRooms
|
||||
: chatRooms // ignore: cast_nullable_to_non_nullable
|
||||
as List<ChatRoom>,
|
||||
as ChatRooms,
|
||||
unreadChatsCount: null == unreadChatsCount
|
||||
? _value.unreadChatsCount
|
||||
: unreadChatsCount // ignore: cast_nullable_to_non_nullable
|
||||
as int,
|
||||
) as $Val);
|
||||
}
|
||||
|
||||
/// Create a copy of ChatRoomPaginationModel
|
||||
/// with the given fields replaced by the non-null parameter values.
|
||||
@override
|
||||
@pragma('vm:prefer-inline')
|
||||
$ChatRoomsCopyWith<$Res> get chatRooms {
|
||||
return $ChatRoomsCopyWith<$Res>(_value.chatRooms, (value) {
|
||||
return _then(_value.copyWith(chatRooms: value) as $Val);
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
/// @nodoc
|
||||
abstract class _$$ChatRoomPreviewModelImplCopyWith<$Res>
|
||||
implements $ChatRoomPreviewModelCopyWith<$Res> {
|
||||
implements $ChatRoomPaginationModelCopyWith<$Res> {
|
||||
factory _$$ChatRoomPreviewModelImplCopyWith(_$ChatRoomPreviewModelImpl value,
|
||||
$Res Function(_$ChatRoomPreviewModelImpl) then) =
|
||||
__$$ChatRoomPreviewModelImplCopyWithImpl<$Res>;
|
||||
@override
|
||||
@useResult
|
||||
$Res call({@JsonKey(name: "chatRooms") List<ChatRoom> chatRooms});
|
||||
$Res call(
|
||||
{@JsonKey(name: "chatRooms") ChatRooms chatRooms,
|
||||
@JsonKey(name: "number_of_unread_chat_rooms") int unreadChatsCount});
|
||||
|
||||
@override
|
||||
$ChatRoomsCopyWith<$Res> get chatRooms;
|
||||
}
|
||||
|
||||
/// @nodoc
|
||||
class __$$ChatRoomPreviewModelImplCopyWithImpl<$Res>
|
||||
extends _$ChatRoomPreviewModelCopyWithImpl<$Res, _$ChatRoomPreviewModelImpl>
|
||||
extends _$ChatRoomPaginationModelCopyWithImpl<$Res,
|
||||
_$ChatRoomPreviewModelImpl>
|
||||
implements _$$ChatRoomPreviewModelImplCopyWith<$Res> {
|
||||
__$$ChatRoomPreviewModelImplCopyWithImpl(_$ChatRoomPreviewModelImpl _value,
|
||||
$Res Function(_$ChatRoomPreviewModelImpl) _then)
|
||||
: super(_value, _then);
|
||||
|
||||
/// Create a copy of ChatRoomPreviewModel
|
||||
/// Create a copy of ChatRoomPaginationModel
|
||||
/// with the given fields replaced by the non-null parameter values.
|
||||
@pragma('vm:prefer-inline')
|
||||
@override
|
||||
$Res call({
|
||||
Object? chatRooms = null,
|
||||
Object? unreadChatsCount = null,
|
||||
}) {
|
||||
return _then(_$ChatRoomPreviewModelImpl(
|
||||
chatRooms: null == chatRooms
|
||||
? _value._chatRooms
|
||||
? _value.chatRooms
|
||||
: chatRooms // ignore: cast_nullable_to_non_nullable
|
||||
as List<ChatRoom>,
|
||||
as ChatRooms,
|
||||
unreadChatsCount: null == unreadChatsCount
|
||||
? _value.unreadChatsCount
|
||||
: unreadChatsCount // ignore: cast_nullable_to_non_nullable
|
||||
as int,
|
||||
));
|
||||
}
|
||||
}
|
||||
@@ -108,24 +141,23 @@ class __$$ChatRoomPreviewModelImplCopyWithImpl<$Res>
|
||||
@JsonSerializable()
|
||||
class _$ChatRoomPreviewModelImpl implements _ChatRoomPreviewModel {
|
||||
const _$ChatRoomPreviewModelImpl(
|
||||
{@JsonKey(name: "chatRooms") required final List<ChatRoom> chatRooms})
|
||||
: _chatRooms = chatRooms;
|
||||
{@JsonKey(name: "chatRooms") required this.chatRooms,
|
||||
@JsonKey(name: "number_of_unread_chat_rooms")
|
||||
required this.unreadChatsCount});
|
||||
|
||||
factory _$ChatRoomPreviewModelImpl.fromJson(Map<String, dynamic> json) =>
|
||||
_$$ChatRoomPreviewModelImplFromJson(json);
|
||||
|
||||
final List<ChatRoom> _chatRooms;
|
||||
@override
|
||||
@JsonKey(name: "chatRooms")
|
||||
List<ChatRoom> get chatRooms {
|
||||
if (_chatRooms is EqualUnmodifiableListView) return _chatRooms;
|
||||
// ignore: implicit_dynamic_type
|
||||
return EqualUnmodifiableListView(_chatRooms);
|
||||
}
|
||||
final ChatRooms chatRooms;
|
||||
@override
|
||||
@JsonKey(name: "number_of_unread_chat_rooms")
|
||||
final int unreadChatsCount;
|
||||
|
||||
@override
|
||||
String toString() {
|
||||
return 'ChatRoomPreviewModel(chatRooms: $chatRooms)';
|
||||
return 'ChatRoomPaginationModel(chatRooms: $chatRooms, unreadChatsCount: $unreadChatsCount)';
|
||||
}
|
||||
|
||||
@override
|
||||
@@ -133,16 +165,17 @@ class _$ChatRoomPreviewModelImpl implements _ChatRoomPreviewModel {
|
||||
return identical(this, other) ||
|
||||
(other.runtimeType == runtimeType &&
|
||||
other is _$ChatRoomPreviewModelImpl &&
|
||||
const DeepCollectionEquality()
|
||||
.equals(other._chatRooms, _chatRooms));
|
||||
(identical(other.chatRooms, chatRooms) ||
|
||||
other.chatRooms == chatRooms) &&
|
||||
(identical(other.unreadChatsCount, unreadChatsCount) ||
|
||||
other.unreadChatsCount == unreadChatsCount));
|
||||
}
|
||||
|
||||
@JsonKey(includeFromJson: false, includeToJson: false)
|
||||
@override
|
||||
int get hashCode =>
|
||||
Object.hash(runtimeType, const DeepCollectionEquality().hash(_chatRooms));
|
||||
int get hashCode => Object.hash(runtimeType, chatRooms, unreadChatsCount);
|
||||
|
||||
/// Create a copy of ChatRoomPreviewModel
|
||||
/// Create a copy of ChatRoomPaginationModel
|
||||
/// with the given fields replaced by the non-null parameter values.
|
||||
@JsonKey(includeFromJson: false, includeToJson: false)
|
||||
@override
|
||||
@@ -160,19 +193,23 @@ class _$ChatRoomPreviewModelImpl implements _ChatRoomPreviewModel {
|
||||
}
|
||||
}
|
||||
|
||||
abstract class _ChatRoomPreviewModel implements ChatRoomPreviewModel {
|
||||
abstract class _ChatRoomPreviewModel implements ChatRoomPaginationModel {
|
||||
const factory _ChatRoomPreviewModel(
|
||||
{@JsonKey(name: "chatRooms")
|
||||
required final List<ChatRoom> chatRooms}) = _$ChatRoomPreviewModelImpl;
|
||||
{@JsonKey(name: "chatRooms") required final ChatRooms chatRooms,
|
||||
@JsonKey(name: "number_of_unread_chat_rooms")
|
||||
required final int unreadChatsCount}) = _$ChatRoomPreviewModelImpl;
|
||||
|
||||
factory _ChatRoomPreviewModel.fromJson(Map<String, dynamic> json) =
|
||||
_$ChatRoomPreviewModelImpl.fromJson;
|
||||
|
||||
@override
|
||||
@JsonKey(name: "chatRooms")
|
||||
List<ChatRoom> get chatRooms;
|
||||
ChatRooms get chatRooms;
|
||||
@override
|
||||
@JsonKey(name: "number_of_unread_chat_rooms")
|
||||
int get unreadChatsCount;
|
||||
|
||||
/// Create a copy of ChatRoomPreviewModel
|
||||
/// Create a copy of ChatRoomPaginationModel
|
||||
/// with the given fields replaced by the non-null parameter values.
|
||||
@override
|
||||
@JsonKey(includeFromJson: false, includeToJson: false)
|
||||
@@ -180,6 +217,218 @@ abstract class _ChatRoomPreviewModel implements ChatRoomPreviewModel {
|
||||
get copyWith => throw _privateConstructorUsedError;
|
||||
}
|
||||
|
||||
ChatRooms _$ChatRoomsFromJson(Map<String, dynamic> json) {
|
||||
return _ChatRooms.fromJson(json);
|
||||
}
|
||||
|
||||
/// @nodoc
|
||||
mixin _$ChatRooms {
|
||||
@JsonKey(name: "data")
|
||||
List<ChatRoom> get data => throw _privateConstructorUsedError;
|
||||
@JsonKey(name: "last_page")
|
||||
int get lastPage => throw _privateConstructorUsedError;
|
||||
@JsonKey(name: "current_page")
|
||||
int get currentPage => throw _privateConstructorUsedError;
|
||||
|
||||
/// Serializes this ChatRooms to a JSON map.
|
||||
Map<String, dynamic> toJson() => throw _privateConstructorUsedError;
|
||||
|
||||
/// Create a copy of ChatRooms
|
||||
/// with the given fields replaced by the non-null parameter values.
|
||||
@JsonKey(includeFromJson: false, includeToJson: false)
|
||||
$ChatRoomsCopyWith<ChatRooms> get copyWith =>
|
||||
throw _privateConstructorUsedError;
|
||||
}
|
||||
|
||||
/// @nodoc
|
||||
abstract class $ChatRoomsCopyWith<$Res> {
|
||||
factory $ChatRoomsCopyWith(ChatRooms value, $Res Function(ChatRooms) then) =
|
||||
_$ChatRoomsCopyWithImpl<$Res, ChatRooms>;
|
||||
@useResult
|
||||
$Res call(
|
||||
{@JsonKey(name: "data") List<ChatRoom> data,
|
||||
@JsonKey(name: "last_page") int lastPage,
|
||||
@JsonKey(name: "current_page") int currentPage});
|
||||
}
|
||||
|
||||
/// @nodoc
|
||||
class _$ChatRoomsCopyWithImpl<$Res, $Val extends ChatRooms>
|
||||
implements $ChatRoomsCopyWith<$Res> {
|
||||
_$ChatRoomsCopyWithImpl(this._value, this._then);
|
||||
|
||||
// ignore: unused_field
|
||||
final $Val _value;
|
||||
// ignore: unused_field
|
||||
final $Res Function($Val) _then;
|
||||
|
||||
/// Create a copy of ChatRooms
|
||||
/// with the given fields replaced by the non-null parameter values.
|
||||
@pragma('vm:prefer-inline')
|
||||
@override
|
||||
$Res call({
|
||||
Object? data = null,
|
||||
Object? lastPage = null,
|
||||
Object? currentPage = null,
|
||||
}) {
|
||||
return _then(_value.copyWith(
|
||||
data: null == data
|
||||
? _value.data
|
||||
: data // ignore: cast_nullable_to_non_nullable
|
||||
as List<ChatRoom>,
|
||||
lastPage: null == lastPage
|
||||
? _value.lastPage
|
||||
: lastPage // ignore: cast_nullable_to_non_nullable
|
||||
as int,
|
||||
currentPage: null == currentPage
|
||||
? _value.currentPage
|
||||
: currentPage // ignore: cast_nullable_to_non_nullable
|
||||
as int,
|
||||
) as $Val);
|
||||
}
|
||||
}
|
||||
|
||||
/// @nodoc
|
||||
abstract class _$$ChatRoomsImplCopyWith<$Res>
|
||||
implements $ChatRoomsCopyWith<$Res> {
|
||||
factory _$$ChatRoomsImplCopyWith(
|
||||
_$ChatRoomsImpl value, $Res Function(_$ChatRoomsImpl) then) =
|
||||
__$$ChatRoomsImplCopyWithImpl<$Res>;
|
||||
@override
|
||||
@useResult
|
||||
$Res call(
|
||||
{@JsonKey(name: "data") List<ChatRoom> data,
|
||||
@JsonKey(name: "last_page") int lastPage,
|
||||
@JsonKey(name: "current_page") int currentPage});
|
||||
}
|
||||
|
||||
/// @nodoc
|
||||
class __$$ChatRoomsImplCopyWithImpl<$Res>
|
||||
extends _$ChatRoomsCopyWithImpl<$Res, _$ChatRoomsImpl>
|
||||
implements _$$ChatRoomsImplCopyWith<$Res> {
|
||||
__$$ChatRoomsImplCopyWithImpl(
|
||||
_$ChatRoomsImpl _value, $Res Function(_$ChatRoomsImpl) _then)
|
||||
: super(_value, _then);
|
||||
|
||||
/// Create a copy of ChatRooms
|
||||
/// with the given fields replaced by the non-null parameter values.
|
||||
@pragma('vm:prefer-inline')
|
||||
@override
|
||||
$Res call({
|
||||
Object? data = null,
|
||||
Object? lastPage = null,
|
||||
Object? currentPage = null,
|
||||
}) {
|
||||
return _then(_$ChatRoomsImpl(
|
||||
data: null == data
|
||||
? _value._data
|
||||
: data // ignore: cast_nullable_to_non_nullable
|
||||
as List<ChatRoom>,
|
||||
lastPage: null == lastPage
|
||||
? _value.lastPage
|
||||
: lastPage // ignore: cast_nullable_to_non_nullable
|
||||
as int,
|
||||
currentPage: null == currentPage
|
||||
? _value.currentPage
|
||||
: currentPage // ignore: cast_nullable_to_non_nullable
|
||||
as int,
|
||||
));
|
||||
}
|
||||
}
|
||||
|
||||
/// @nodoc
|
||||
@JsonSerializable()
|
||||
class _$ChatRoomsImpl implements _ChatRooms {
|
||||
const _$ChatRoomsImpl(
|
||||
{@JsonKey(name: "data") required final List<ChatRoom> data,
|
||||
@JsonKey(name: "last_page") required this.lastPage,
|
||||
@JsonKey(name: "current_page") required this.currentPage})
|
||||
: _data = data;
|
||||
|
||||
factory _$ChatRoomsImpl.fromJson(Map<String, dynamic> json) =>
|
||||
_$$ChatRoomsImplFromJson(json);
|
||||
|
||||
final List<ChatRoom> _data;
|
||||
@override
|
||||
@JsonKey(name: "data")
|
||||
List<ChatRoom> get data {
|
||||
if (_data is EqualUnmodifiableListView) return _data;
|
||||
// ignore: implicit_dynamic_type
|
||||
return EqualUnmodifiableListView(_data);
|
||||
}
|
||||
|
||||
@override
|
||||
@JsonKey(name: "last_page")
|
||||
final int lastPage;
|
||||
@override
|
||||
@JsonKey(name: "current_page")
|
||||
final int currentPage;
|
||||
|
||||
@override
|
||||
String toString() {
|
||||
return 'ChatRooms(data: $data, lastPage: $lastPage, currentPage: $currentPage)';
|
||||
}
|
||||
|
||||
@override
|
||||
bool operator ==(Object other) {
|
||||
return identical(this, other) ||
|
||||
(other.runtimeType == runtimeType &&
|
||||
other is _$ChatRoomsImpl &&
|
||||
const DeepCollectionEquality().equals(other._data, _data) &&
|
||||
(identical(other.lastPage, lastPage) ||
|
||||
other.lastPage == lastPage) &&
|
||||
(identical(other.currentPage, currentPage) ||
|
||||
other.currentPage == currentPage));
|
||||
}
|
||||
|
||||
@JsonKey(includeFromJson: false, includeToJson: false)
|
||||
@override
|
||||
int get hashCode => Object.hash(runtimeType,
|
||||
const DeepCollectionEquality().hash(_data), lastPage, currentPage);
|
||||
|
||||
/// Create a copy of ChatRooms
|
||||
/// with the given fields replaced by the non-null parameter values.
|
||||
@JsonKey(includeFromJson: false, includeToJson: false)
|
||||
@override
|
||||
@pragma('vm:prefer-inline')
|
||||
_$$ChatRoomsImplCopyWith<_$ChatRoomsImpl> get copyWith =>
|
||||
__$$ChatRoomsImplCopyWithImpl<_$ChatRoomsImpl>(this, _$identity);
|
||||
|
||||
@override
|
||||
Map<String, dynamic> toJson() {
|
||||
return _$$ChatRoomsImplToJson(
|
||||
this,
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
abstract class _ChatRooms implements ChatRooms {
|
||||
const factory _ChatRooms(
|
||||
{@JsonKey(name: "data") required final List<ChatRoom> data,
|
||||
@JsonKey(name: "last_page") required final int lastPage,
|
||||
@JsonKey(name: "current_page") required final int currentPage}) =
|
||||
_$ChatRoomsImpl;
|
||||
|
||||
factory _ChatRooms.fromJson(Map<String, dynamic> json) =
|
||||
_$ChatRoomsImpl.fromJson;
|
||||
|
||||
@override
|
||||
@JsonKey(name: "data")
|
||||
List<ChatRoom> get data;
|
||||
@override
|
||||
@JsonKey(name: "last_page")
|
||||
int get lastPage;
|
||||
@override
|
||||
@JsonKey(name: "current_page")
|
||||
int get currentPage;
|
||||
|
||||
/// Create a copy of ChatRooms
|
||||
/// with the given fields replaced by the non-null parameter values.
|
||||
@override
|
||||
@JsonKey(includeFromJson: false, includeToJson: false)
|
||||
_$$ChatRoomsImplCopyWith<_$ChatRoomsImpl> get copyWith =>
|
||||
throw _privateConstructorUsedError;
|
||||
}
|
||||
|
||||
ChatRoom _$ChatRoomFromJson(Map<String, dynamic> json) {
|
||||
return _ChatRoom.fromJson(json);
|
||||
}
|
||||
@@ -1,6 +1,6 @@
|
||||
// GENERATED CODE - DO NOT MODIFY BY HAND
|
||||
|
||||
part of 'chat_room_preview_model.dart';
|
||||
part of 'chat_room_pagination_model.dart';
|
||||
|
||||
// **************************************************************************
|
||||
// JsonSerializableGenerator
|
||||
@@ -9,15 +9,31 @@ part of 'chat_room_preview_model.dart';
|
||||
_$ChatRoomPreviewModelImpl _$$ChatRoomPreviewModelImplFromJson(
|
||||
Map<String, dynamic> json) =>
|
||||
_$ChatRoomPreviewModelImpl(
|
||||
chatRooms: (json['chatRooms'] as List<dynamic>)
|
||||
.map((e) => ChatRoom.fromJson(e as Map<String, dynamic>))
|
||||
.toList(),
|
||||
chatRooms: ChatRooms.fromJson(json['chatRooms'] as Map<String, dynamic>),
|
||||
unreadChatsCount: (json['number_of_unread_chat_rooms'] as num).toInt(),
|
||||
);
|
||||
|
||||
Map<String, dynamic> _$$ChatRoomPreviewModelImplToJson(
|
||||
_$ChatRoomPreviewModelImpl instance) =>
|
||||
<String, dynamic>{
|
||||
'chatRooms': instance.chatRooms,
|
||||
'number_of_unread_chat_rooms': instance.unreadChatsCount,
|
||||
};
|
||||
|
||||
_$ChatRoomsImpl _$$ChatRoomsImplFromJson(Map<String, dynamic> json) =>
|
||||
_$ChatRoomsImpl(
|
||||
data: (json['data'] as List<dynamic>)
|
||||
.map((e) => ChatRoom.fromJson(e as Map<String, dynamic>))
|
||||
.toList(),
|
||||
lastPage: (json['last_page'] as num).toInt(),
|
||||
currentPage: (json['current_page'] as num).toInt(),
|
||||
);
|
||||
|
||||
Map<String, dynamic> _$$ChatRoomsImplToJson(_$ChatRoomsImpl instance) =>
|
||||
<String, dynamic>{
|
||||
'data': instance.data,
|
||||
'last_page': instance.lastPage,
|
||||
'current_page': instance.currentPage,
|
||||
};
|
||||
|
||||
_$ChatRoomImpl _$$ChatRoomImplFromJson(Map<String, dynamic> json) =>
|
||||
@@ -86,6 +86,17 @@ class ChatRoomCubit extends Cubit<ChatRoomState> {
|
||||
}
|
||||
}
|
||||
|
||||
Future<void> updateChatRoom(String chatId) async{
|
||||
try {
|
||||
final chatRoom = await chatRepository.getChatRoom(chatId);
|
||||
emit(
|
||||
(state as ChatRoomStateLoaded).copyWith(chatRoom: chatRoom),
|
||||
);
|
||||
} catch (e) {
|
||||
emit(ChatRoomState.error(errorMessage: 'Ошибка получеия данных'));
|
||||
}
|
||||
}
|
||||
|
||||
Future<void> _subscribeToChatChannel({
|
||||
required String chatId,
|
||||
}) async {
|
||||
|
||||
@@ -1,5 +1,6 @@
|
||||
import 'dart:async';
|
||||
import 'dart:convert';
|
||||
import 'dart:developer';
|
||||
|
||||
import 'package:eatvio_app/core/enums/base_state.dart';
|
||||
import 'package:eatvio_app/core/websockets/ws_manager.dart';
|
||||
@@ -30,21 +31,24 @@ class ChatsCubit extends Cubit<ChatsState> {
|
||||
});
|
||||
}
|
||||
String? _query;
|
||||
int page = 1;
|
||||
late int lastPage;
|
||||
Future<void> getChatRoomsWithLoading({String? query}) async {
|
||||
page = 1;
|
||||
_query = query;
|
||||
emit(state.copyWith(state: BaseState.loading));
|
||||
try {
|
||||
final chatRooms = await chatRepository.getChatRoomPreviews(query: query);
|
||||
final unreadChats = chatRooms.where(
|
||||
(element) => element.unreadMessagesCount > 0,
|
||||
);
|
||||
final chatRoomsPaginationModel = await chatRepository.getChatRooms(query: query);
|
||||
final unreadChats = chatRoomsPaginationModel.unreadChatsCount;
|
||||
lastPage = chatRoomsPaginationModel.chatRooms.lastPage + 1;
|
||||
emit(
|
||||
state.copyWith(
|
||||
chatRooms: chatRooms,
|
||||
chatsWithUnreadMessagesCount: unreadChats.length,
|
||||
chatRooms: chatRoomsPaginationModel.chatRooms.data,
|
||||
chatsWithUnreadMessagesCount: unreadChats,
|
||||
state: BaseState.success,
|
||||
),
|
||||
);
|
||||
page++;
|
||||
} catch (e) {
|
||||
emit(
|
||||
state.copyWith(errorMessage: e.toString(), state: BaseState.error),
|
||||
@@ -53,26 +57,55 @@ class ChatsCubit extends Cubit<ChatsState> {
|
||||
}
|
||||
|
||||
Future<void> getChatRooms({String? query}) async {
|
||||
page = 1;
|
||||
_query = query;
|
||||
try {
|
||||
final chatRooms = await chatRepository.getChatRoomPreviews(query: query);
|
||||
final unreadChats = chatRooms.where(
|
||||
(element) => element.unreadMessagesCount > 0,
|
||||
);
|
||||
final chatRoomsPaginationModel = await chatRepository.getChatRooms(query: query);
|
||||
final unreadChats = chatRoomsPaginationModel.unreadChatsCount;
|
||||
lastPage = chatRoomsPaginationModel.chatRooms.lastPage + 1;
|
||||
emit(
|
||||
state.copyWith(
|
||||
chatRooms: chatRooms,
|
||||
chatsWithUnreadMessagesCount: unreadChats.length,
|
||||
chatRooms: chatRoomsPaginationModel.chatRooms.data,
|
||||
chatsWithUnreadMessagesCount: unreadChats,
|
||||
state: BaseState.success,
|
||||
),
|
||||
);
|
||||
} catch (e) {
|
||||
page++;
|
||||
} catch (e, st) {
|
||||
log(e.toString(), stackTrace: st);
|
||||
emit(
|
||||
state.copyWith(errorMessage: e.toString(), state: BaseState.error),
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
Future<void> loadMoreChatRooms() async {
|
||||
try {
|
||||
if (state.isLoadingMoreChats || lastPage == page) return;
|
||||
emit(state.copyWith(isLoadingMoreChats: true));
|
||||
final chatRoomsPaginationModel = await chatRepository.getChatRooms(query: _query, page: page);
|
||||
final unreadChats = chatRoomsPaginationModel.unreadChatsCount;
|
||||
emit(
|
||||
state.copyWith(
|
||||
chatRooms: [...state.chatRooms, ...chatRoomsPaginationModel.chatRooms.data],
|
||||
chatsWithUnreadMessagesCount: unreadChats,
|
||||
state: BaseState.success,
|
||||
isLoadingMoreChats: false,
|
||||
),
|
||||
);
|
||||
page++;
|
||||
} catch (e, st) {
|
||||
log(e.toString(), stackTrace: st);
|
||||
emit(
|
||||
state.copyWith(
|
||||
errorMessage: e.toString(),
|
||||
state: BaseState.error,
|
||||
isLoadingMoreChats: false,
|
||||
),
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
void reduceUnreadMessagesCount({required String chatId, required int count}) {
|
||||
bool isChatRead = false;
|
||||
final updatedChatRooms = state.chatRooms.map((room) {
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
import 'package:eatvio_app/core/enums/base_state.dart';
|
||||
import 'package:eatvio_app/features/chat/models/chat_room_preview_model.dart';
|
||||
import 'package:eatvio_app/features/chat/models/chat_room_pagination_model.dart';
|
||||
import 'package:freezed_annotation/freezed_annotation.dart';
|
||||
|
||||
part 'chats_state.freezed.dart';
|
||||
@@ -11,6 +11,7 @@ class ChatsState with _$ChatsState {
|
||||
@Default(BaseState.initial) BaseState state,
|
||||
@Default(0) int chatsWithUnreadMessagesCount,
|
||||
@Default([]) List<ChatRoom> chatRooms,
|
||||
@Default(false) bool isLoadingMoreChats,
|
||||
@Default(null) String? errorMessage,
|
||||
}) = _ChatsState;
|
||||
|
||||
|
||||
@@ -19,6 +19,7 @@ mixin _$ChatsState {
|
||||
BaseState get state => throw _privateConstructorUsedError;
|
||||
int get chatsWithUnreadMessagesCount => throw _privateConstructorUsedError;
|
||||
List<ChatRoom> get chatRooms => throw _privateConstructorUsedError;
|
||||
bool get isLoadingMoreChats => throw _privateConstructorUsedError;
|
||||
String? get errorMessage => throw _privateConstructorUsedError;
|
||||
|
||||
/// Create a copy of ChatsState
|
||||
@@ -38,6 +39,7 @@ abstract class $ChatsStateCopyWith<$Res> {
|
||||
{BaseState state,
|
||||
int chatsWithUnreadMessagesCount,
|
||||
List<ChatRoom> chatRooms,
|
||||
bool isLoadingMoreChats,
|
||||
String? errorMessage});
|
||||
}
|
||||
|
||||
@@ -59,6 +61,7 @@ class _$ChatsStateCopyWithImpl<$Res, $Val extends ChatsState>
|
||||
Object? state = null,
|
||||
Object? chatsWithUnreadMessagesCount = null,
|
||||
Object? chatRooms = null,
|
||||
Object? isLoadingMoreChats = null,
|
||||
Object? errorMessage = freezed,
|
||||
}) {
|
||||
return _then(_value.copyWith(
|
||||
@@ -74,6 +77,10 @@ class _$ChatsStateCopyWithImpl<$Res, $Val extends ChatsState>
|
||||
? _value.chatRooms
|
||||
: chatRooms // ignore: cast_nullable_to_non_nullable
|
||||
as List<ChatRoom>,
|
||||
isLoadingMoreChats: null == isLoadingMoreChats
|
||||
? _value.isLoadingMoreChats
|
||||
: isLoadingMoreChats // ignore: cast_nullable_to_non_nullable
|
||||
as bool,
|
||||
errorMessage: freezed == errorMessage
|
||||
? _value.errorMessage
|
||||
: errorMessage // ignore: cast_nullable_to_non_nullable
|
||||
@@ -94,6 +101,7 @@ abstract class _$$ChatsStateImplCopyWith<$Res>
|
||||
{BaseState state,
|
||||
int chatsWithUnreadMessagesCount,
|
||||
List<ChatRoom> chatRooms,
|
||||
bool isLoadingMoreChats,
|
||||
String? errorMessage});
|
||||
}
|
||||
|
||||
@@ -113,6 +121,7 @@ class __$$ChatsStateImplCopyWithImpl<$Res>
|
||||
Object? state = null,
|
||||
Object? chatsWithUnreadMessagesCount = null,
|
||||
Object? chatRooms = null,
|
||||
Object? isLoadingMoreChats = null,
|
||||
Object? errorMessage = freezed,
|
||||
}) {
|
||||
return _then(_$ChatsStateImpl(
|
||||
@@ -128,6 +137,10 @@ class __$$ChatsStateImplCopyWithImpl<$Res>
|
||||
? _value._chatRooms
|
||||
: chatRooms // ignore: cast_nullable_to_non_nullable
|
||||
as List<ChatRoom>,
|
||||
isLoadingMoreChats: null == isLoadingMoreChats
|
||||
? _value.isLoadingMoreChats
|
||||
: isLoadingMoreChats // ignore: cast_nullable_to_non_nullable
|
||||
as bool,
|
||||
errorMessage: freezed == errorMessage
|
||||
? _value.errorMessage
|
||||
: errorMessage // ignore: cast_nullable_to_non_nullable
|
||||
@@ -143,6 +156,7 @@ class _$ChatsStateImpl implements _ChatsState {
|
||||
{this.state = BaseState.initial,
|
||||
this.chatsWithUnreadMessagesCount = 0,
|
||||
final List<ChatRoom> chatRooms = const [],
|
||||
this.isLoadingMoreChats = false,
|
||||
this.errorMessage = null})
|
||||
: _chatRooms = chatRooms;
|
||||
|
||||
@@ -161,13 +175,16 @@ class _$ChatsStateImpl implements _ChatsState {
|
||||
return EqualUnmodifiableListView(_chatRooms);
|
||||
}
|
||||
|
||||
@override
|
||||
@JsonKey()
|
||||
final bool isLoadingMoreChats;
|
||||
@override
|
||||
@JsonKey()
|
||||
final String? errorMessage;
|
||||
|
||||
@override
|
||||
String toString() {
|
||||
return 'ChatsState(state: $state, chatsWithUnreadMessagesCount: $chatsWithUnreadMessagesCount, chatRooms: $chatRooms, errorMessage: $errorMessage)';
|
||||
return 'ChatsState(state: $state, chatsWithUnreadMessagesCount: $chatsWithUnreadMessagesCount, chatRooms: $chatRooms, isLoadingMoreChats: $isLoadingMoreChats, errorMessage: $errorMessage)';
|
||||
}
|
||||
|
||||
@override
|
||||
@@ -182,6 +199,8 @@ class _$ChatsStateImpl implements _ChatsState {
|
||||
chatsWithUnreadMessagesCount) &&
|
||||
const DeepCollectionEquality()
|
||||
.equals(other._chatRooms, _chatRooms) &&
|
||||
(identical(other.isLoadingMoreChats, isLoadingMoreChats) ||
|
||||
other.isLoadingMoreChats == isLoadingMoreChats) &&
|
||||
(identical(other.errorMessage, errorMessage) ||
|
||||
other.errorMessage == errorMessage));
|
||||
}
|
||||
@@ -192,6 +211,7 @@ class _$ChatsStateImpl implements _ChatsState {
|
||||
state,
|
||||
chatsWithUnreadMessagesCount,
|
||||
const DeepCollectionEquality().hash(_chatRooms),
|
||||
isLoadingMoreChats,
|
||||
errorMessage);
|
||||
|
||||
/// Create a copy of ChatsState
|
||||
@@ -208,6 +228,7 @@ abstract class _ChatsState implements ChatsState {
|
||||
{final BaseState state,
|
||||
final int chatsWithUnreadMessagesCount,
|
||||
final List<ChatRoom> chatRooms,
|
||||
final bool isLoadingMoreChats,
|
||||
final String? errorMessage}) = _$ChatsStateImpl;
|
||||
|
||||
@override
|
||||
@@ -217,6 +238,8 @@ abstract class _ChatsState implements ChatsState {
|
||||
@override
|
||||
List<ChatRoom> get chatRooms;
|
||||
@override
|
||||
bool get isLoadingMoreChats;
|
||||
@override
|
||||
String? get errorMessage;
|
||||
|
||||
/// Create a copy of ChatsState
|
||||
|
||||
@@ -11,7 +11,6 @@ import 'package:eatvio_app/features/chat/presentation/widgets/chat_bubble_widget
|
||||
import 'package:eatvio_app/core/locator_service.dart';
|
||||
import 'package:eatvio_app/core/theme/custom_text_style.dart';
|
||||
import 'package:eatvio_app/core/theme/theme_helper.dart';
|
||||
import 'package:eatvio_app/features/chat/presentation/widgets/notification_banner.dart';
|
||||
import 'package:file_picker/file_picker.dart';
|
||||
import 'package:flutter/material.dart';
|
||||
import 'package:flutter_bloc/flutter_bloc.dart';
|
||||
|
||||
@@ -1,5 +1,6 @@
|
||||
import 'package:easy_debounce/easy_debounce.dart';
|
||||
import 'package:eatvio_app/core/enums/base_state.dart';
|
||||
import 'package:eatvio_app/core/utils/pagination_utils.dart';
|
||||
import 'package:eatvio_app/core/widgets/data_error_widget.dart';
|
||||
import 'package:eatvio_app/core/widgets/loader.dart';
|
||||
import 'package:eatvio_app/features/chat/presentation/bloc/chats_cubit/chats_cubit.dart';
|
||||
@@ -16,7 +17,7 @@ class ChatsScreen extends StatefulWidget {
|
||||
State<ChatsScreen> createState() => _ChatsScreenState();
|
||||
}
|
||||
|
||||
class _ChatsScreenState extends State<ChatsScreen> {
|
||||
class _ChatsScreenState extends State<ChatsScreen> {
|
||||
final searchController = TextEditingController();
|
||||
|
||||
Widget build(BuildContext context) {
|
||||
@@ -65,45 +66,40 @@ class _ChatsScreenState extends State<ChatsScreen> {
|
||||
),
|
||||
];
|
||||
},
|
||||
body: stateBuilder(state),
|
||||
body: switch (state.state) {
|
||||
BaseState.error => DataErrorWidget(onReload: () => context.read<ChatsCubit>().getChatRooms()),
|
||||
BaseState.success => _buildChatList(context, state),
|
||||
_ => const Loader(),
|
||||
},
|
||||
),
|
||||
);
|
||||
},
|
||||
);
|
||||
}
|
||||
|
||||
stateBuilder(ChatsState state) {
|
||||
if (state.state == BaseState.loading) {
|
||||
return Scaffold(
|
||||
body: const Loader(),
|
||||
);
|
||||
} else if (state.state == BaseState.success) {
|
||||
return _buildChatList(context, state);
|
||||
} else if (state.state == BaseState.error) {
|
||||
return Scaffold(
|
||||
body: DataErrorWidget(onReload: () => context.read<ChatsCubit>().getChatRooms()),
|
||||
);
|
||||
} else {
|
||||
return Scaffold(
|
||||
body: const Loader(),
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
_buildChatList(BuildContext context, ChatsState state) {
|
||||
return ListView.separated(
|
||||
padding: EdgeInsets.all(16),
|
||||
shrinkWrap: true,
|
||||
physics: NeverScrollableScrollPhysics(),
|
||||
separatorBuilder: (context, index) {
|
||||
return SizedBox(
|
||||
height: 8,
|
||||
);
|
||||
},
|
||||
itemCount: state.chatRooms.length,
|
||||
itemBuilder: (context, index) {
|
||||
return ChatEntryWidget(chatRoom: state.chatRooms[index]);
|
||||
return NotificationListener<ScrollNotification>(
|
||||
onNotification: (notification) {
|
||||
loadNewContent(notification, context.read<ChatsCubit>().loadMoreChatRooms);
|
||||
return false;
|
||||
},
|
||||
child: ListView.separated(
|
||||
padding: EdgeInsets.all(16),
|
||||
shrinkWrap: true,
|
||||
physics: NeverScrollableScrollPhysics(),
|
||||
separatorBuilder: (context, index) {
|
||||
return SizedBox(
|
||||
height: 8,
|
||||
);
|
||||
},
|
||||
itemCount: state.isLoadingMoreChats ? state.chatRooms.length + 1 : state.chatRooms.length,
|
||||
itemBuilder: (context, index) {
|
||||
if (index == state.chatRooms.length) {
|
||||
return Center(child: Loader());
|
||||
}
|
||||
return ChatEntryWidget(chatRoom: state.chatRooms[index]);
|
||||
},
|
||||
),
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,10 +1,8 @@
|
||||
import 'package:eatvio_app/core/utils/date_time_utils.dart';
|
||||
import 'package:eatvio_app/features/chat/models/chat_room_preview_model.dart';
|
||||
import 'package:eatvio_app/features/chat/models/chat_room_pagination_model.dart';
|
||||
import 'package:eatvio_app/core/theme/custom_text_style.dart';
|
||||
import 'package:eatvio_app/core/theme/theme_helper.dart';
|
||||
import 'package:eatvio_app/features/chat/presentation/bloc/chats_cubit/chats_cubit.dart';
|
||||
import 'package:flutter/material.dart';
|
||||
import 'package:flutter_bloc/flutter_bloc.dart';
|
||||
import 'package:go_router/go_router.dart';
|
||||
|
||||
class ChatEntryWidget extends StatefulWidget {
|
||||
|
||||
20
lib/features/chat/presentation/widgets/order_card.dart
Normal file
20
lib/features/chat/presentation/widgets/order_card.dart
Normal file
@@ -0,0 +1,20 @@
|
||||
import 'package:eatvio_app/features/feed/models/plan_pagination_model.dart';
|
||||
import 'package:flutter/material.dart';
|
||||
|
||||
class OrderCard extends StatelessWidget {
|
||||
final PlanModel plan;
|
||||
final bool isUserView;
|
||||
const OrderCard({super.key, required this.plan, required this.isUserView});
|
||||
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
return Container(
|
||||
padding: EdgeInsets.only(top: 8, bottom: 12, left: 8, right: 8),
|
||||
child: Column(
|
||||
children: [
|
||||
|
||||
],
|
||||
),
|
||||
);
|
||||
}
|
||||
}
|
||||
@@ -5,7 +5,7 @@ import 'package:dio/dio.dart';
|
||||
import 'package:eatvio_app/features/chat/models/chat_message_model.dart';
|
||||
import 'package:eatvio_app/features/chat/models/chat_messages_model.dart';
|
||||
import 'package:eatvio_app/features/chat/models/chat_room_model.dart';
|
||||
import 'package:eatvio_app/features/chat/models/chat_room_preview_model.dart';
|
||||
import 'package:eatvio_app/features/chat/models/chat_room_pagination_model.dart';
|
||||
import 'package:eatvio_app/features/chat/services/chat_service.dart';
|
||||
import 'package:http_parser/http_parser.dart';
|
||||
|
||||
@@ -62,9 +62,9 @@ class ChatRepository {
|
||||
}
|
||||
}
|
||||
|
||||
Future<List<ChatRoom>> getChatRoomPreviews({String? query}) async {
|
||||
Future<ChatRoomPaginationModel> getChatRooms({String? query, int page = 1}) async {
|
||||
try {
|
||||
return (await chatService.getChatRoomPreviews(query: query)).chatRooms;
|
||||
return (await chatService.getChatRooms(query: query, page: page));
|
||||
} catch (e) {
|
||||
rethrow;
|
||||
}
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
import 'package:dio/dio.dart';
|
||||
import 'package:eatvio_app/features/chat/models/chat_messages_model.dart';
|
||||
import 'package:eatvio_app/features/chat/models/chat_room_model.dart';
|
||||
import 'package:eatvio_app/features/chat/models/chat_room_preview_model.dart';
|
||||
import 'package:eatvio_app/features/chat/models/chat_room_pagination_model.dart';
|
||||
import 'package:retrofit/retrofit.dart';
|
||||
|
||||
part 'chat_service.g.dart';
|
||||
@@ -11,7 +11,8 @@ abstract class ChatService {
|
||||
factory ChatService(Dio dio, {String baseUrl}) = _ChatService;
|
||||
|
||||
@GET('/api/chat/index')
|
||||
Future<ChatRoomPreviewModel> getChatRoomPreviews({
|
||||
Future<ChatRoomPaginationModel> getChatRooms({
|
||||
@Query('page') required int page,
|
||||
@Query('find') String? query,
|
||||
});
|
||||
|
||||
|
||||
@@ -18,13 +18,16 @@ class _ChatService implements ChatService {
|
||||
final ParseErrorLogger? errorLogger;
|
||||
|
||||
@override
|
||||
Future<ChatRoomPreviewModel> getChatRoomPreviews({String? query}) async {
|
||||
Future<ChatRoomPaginationModel> getChatRooms({
|
||||
required int page,
|
||||
String? query,
|
||||
}) async {
|
||||
final _extra = <String, dynamic>{};
|
||||
final queryParameters = <String, dynamic>{r'find': query};
|
||||
final queryParameters = <String, dynamic>{r'page': page, r'find': query};
|
||||
queryParameters.removeWhere((k, v) => v == null);
|
||||
final _headers = <String, dynamic>{};
|
||||
const Map<String, dynamic>? _data = null;
|
||||
final _options = _setStreamType<ChatRoomPreviewModel>(
|
||||
final _options = _setStreamType<ChatRoomPaginationModel>(
|
||||
Options(method: 'GET', headers: _headers, extra: _extra)
|
||||
.compose(
|
||||
_dio.options,
|
||||
@@ -35,9 +38,9 @@ class _ChatService implements ChatService {
|
||||
.copyWith(baseUrl: _combineBaseUrls(_dio.options.baseUrl, baseUrl)),
|
||||
);
|
||||
final _result = await _dio.fetch<Map<String, dynamic>>(_options);
|
||||
late ChatRoomPreviewModel _value;
|
||||
late ChatRoomPaginationModel _value;
|
||||
try {
|
||||
_value = ChatRoomPreviewModel.fromJson(_result.data!);
|
||||
_value = ChatRoomPaginationModel.fromJson(_result.data!);
|
||||
} on Object catch (e, s) {
|
||||
errorLogger?.logError(e, s, _options);
|
||||
rethrow;
|
||||
|
||||
Reference in New Issue
Block a user