forked from eatvio/eatvio_app
card adding and selecting default one
This commit is contained in:
@@ -63,7 +63,7 @@ class RecipesCubit extends Cubit<RecipesState> {
|
||||
lastPage = currentPage;
|
||||
} catch (e, st) {
|
||||
log(e.toString(), stackTrace: st);
|
||||
emit(state.copyWith(errorMessage: e.toString()));
|
||||
emit(state.copyWith(errorMessage: e.toString(), isLoading: false));
|
||||
}
|
||||
}
|
||||
|
||||
@@ -94,7 +94,7 @@ class RecipesCubit extends Cubit<RecipesState> {
|
||||
}
|
||||
lastPage = currentPage;
|
||||
} catch (e) {
|
||||
emit(state.copyWith(errorMessage: e.toString()));
|
||||
emit(state.copyWith(errorMessage: e.toString(), isLoading: false));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -16,54 +16,32 @@ import 'package:go_router/go_router.dart';
|
||||
class MenuScreen extends StatelessWidget {
|
||||
final ProfileModel profileModel;
|
||||
|
||||
const MenuScreen({
|
||||
super.key,
|
||||
required this.profileModel,
|
||||
});
|
||||
const MenuScreen({super.key, required this.profileModel});
|
||||
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
return Scaffold(
|
||||
appBar: AppBar(
|
||||
centerTitle: false,
|
||||
title: Text('Меню'),
|
||||
),
|
||||
appBar: AppBar(centerTitle: false, title: Text('Меню')),
|
||||
body: SingleChildScrollView(
|
||||
child: Column(
|
||||
children: [
|
||||
_tile(
|
||||
title: 'Настройки профиля',
|
||||
leading: ImageConstant.icnProfileSettings,
|
||||
onTap: () => GoRouter.of(context).push('/settings-screen'),
|
||||
),
|
||||
_tile(title: 'Настройки профиля', leading: ImageConstant.icnProfileSettings, onTap: () => GoRouter.of(context).push('/settings-screen')),
|
||||
if (profileModel.roles.contains('consultant')) _divider(context),
|
||||
if (profileModel.roles.contains('consultant'))
|
||||
_tile(
|
||||
leading: ImageConstant.icnRecipes,
|
||||
title: 'Мои рецепты',
|
||||
onTap: () => GoRouter.of(context).push('/recipe-select-screen'),
|
||||
),
|
||||
_tile(leading: ImageConstant.icnRecipes, title: 'Мои рецепты', onTap: () => GoRouter.of(context).push('/recipe-select-screen')),
|
||||
if (profileModel.roles.contains('consultant')) _divider(context),
|
||||
if (profileModel.roles.contains('consultant'))
|
||||
_tile(
|
||||
leading: 'assets/icons/diets.svg',
|
||||
title: 'Мои диеты',
|
||||
onTap: () => GoRouter.of(context).push(MyDietsScreen.path),
|
||||
),
|
||||
_tile(leading: 'assets/icons/diets.svg', title: 'Мои диеты', onTap: () => GoRouter.of(context).push(MyDietsScreen.path)),
|
||||
if (profileModel.roles.contains('consultant')) _divider(context),
|
||||
if (profileModel.roles.contains('consultant'))
|
||||
_tile(
|
||||
leading: ImageConstant.icnPlans,
|
||||
title: 'Мои планы',
|
||||
onTap: () => GoRouter.of(context).push(MyPlansScreen.path),
|
||||
),
|
||||
_tile(leading: ImageConstant.icnPlans, title: 'Мои планы', onTap: () => GoRouter.of(context).push(MyPlansScreen.path)),
|
||||
_divider(context),
|
||||
_tile(
|
||||
leading: 'assets/icons/finance.svg',
|
||||
title: 'Мои финансы',
|
||||
onTap: () {
|
||||
if (profileModel.roles.contains('consultant')) {
|
||||
GoRouter.of(context).pushNamed('consultantFinanceScreen');
|
||||
GoRouter.of(context).pushNamed('userFinanceScreen');
|
||||
} else {
|
||||
GoRouter.of(context).pushNamed('userFinanceScreen');
|
||||
}
|
||||
@@ -76,17 +54,9 @@ class MenuScreen extends StatelessWidget {
|
||||
// onTap: () => GoRouter.of(context).push('/calendar-screen'),
|
||||
// ),
|
||||
_divider(context),
|
||||
_tile(
|
||||
leading: ImageConstant.icnGlossary,
|
||||
title: 'Глоссарий',
|
||||
onTap: () => GoRouter.of(context).push('/glossary-screen'),
|
||||
),
|
||||
_tile(leading: ImageConstant.icnGlossary, title: 'Глоссарий', onTap: () => GoRouter.of(context).push('/glossary-screen')),
|
||||
_divider(context),
|
||||
_tile(
|
||||
leading: ImageConstant.icnSupport,
|
||||
title: 'Поддержка',
|
||||
onTap: () => GoRouter.of(context).push('/support-screen'),
|
||||
),
|
||||
_tile(leading: ImageConstant.icnSupport, title: 'Поддержка', onTap: () => GoRouter.of(context).push('/support-screen')),
|
||||
_divider(context),
|
||||
_tile(
|
||||
leading: ImageConstant.icnDevTools,
|
||||
@@ -96,36 +66,19 @@ class MenuScreen extends StatelessWidget {
|
||||
},
|
||||
),
|
||||
_divider(context),
|
||||
_tile(
|
||||
leading: ImageConstant.icnExit,
|
||||
title: 'Выход',
|
||||
onTap: _onTapLogout(context),
|
||||
),
|
||||
_tile(leading: ImageConstant.icnExit, title: 'Выход', onTap: _onTapLogout(context)),
|
||||
],
|
||||
),
|
||||
),
|
||||
);
|
||||
}
|
||||
|
||||
_tile({
|
||||
required String title,
|
||||
required String leading,
|
||||
required Function() onTap,
|
||||
}) {
|
||||
_tile({required String title, required String leading, required Function() onTap}) {
|
||||
return ListTile(
|
||||
onTap: onTap,
|
||||
leading: SvgPicture.asset(
|
||||
leading,
|
||||
height: 24,
|
||||
width: 24,
|
||||
colorFilter: ColorFilter.mode(appTheme.blueA400, BlendMode.srcIn),
|
||||
),
|
||||
leading: SvgPicture.asset(leading, height: 24, width: 24, colorFilter: ColorFilter.mode(appTheme.blueA400, BlendMode.srcIn)),
|
||||
title: Text(title),
|
||||
trailing: Icon(
|
||||
Icons.arrow_forward_ios_rounded,
|
||||
size: 12,
|
||||
color: Colors.black38,
|
||||
),
|
||||
trailing: Icon(Icons.arrow_forward_ios_rounded, size: 12, color: Colors.black38),
|
||||
);
|
||||
}
|
||||
|
||||
@@ -133,10 +86,7 @@ class MenuScreen extends StatelessWidget {
|
||||
return Container(
|
||||
height: 0.4,
|
||||
width: MediaQuery.of(context).size.width - 32,
|
||||
decoration: BoxDecoration(
|
||||
color: Colors.black26,
|
||||
borderRadius: BorderRadius.circular(16),
|
||||
),
|
||||
decoration: BoxDecoration(color: Colors.black26, borderRadius: BorderRadius.circular(16)),
|
||||
);
|
||||
}
|
||||
|
||||
@@ -144,33 +94,32 @@ class MenuScreen extends StatelessWidget {
|
||||
return () async {
|
||||
showDialog(
|
||||
context: context,
|
||||
builder: (context) => CupertinoAlertDialog(
|
||||
title: Text("Выход"),
|
||||
actions: [
|
||||
CupertinoDialogAction(
|
||||
onPressed: () async {
|
||||
try {
|
||||
await sl<Dio>().post(
|
||||
baseUrl + '/api/profile/logout',
|
||||
);
|
||||
} catch (e) {
|
||||
} finally {
|
||||
await TokenStorage.removeTokenInStorage();
|
||||
GoRouter.of(context).go('/auth-screen', extra: true);
|
||||
}
|
||||
},
|
||||
child: Text("Выйти"),
|
||||
isDestructiveAction: true,
|
||||
builder:
|
||||
(context) => CupertinoAlertDialog(
|
||||
title: Text("Выход"),
|
||||
actions: [
|
||||
CupertinoDialogAction(
|
||||
onPressed: () async {
|
||||
try {
|
||||
await sl<Dio>().post(baseUrl + '/api/profile/logout');
|
||||
} catch (e) {
|
||||
} finally {
|
||||
await TokenStorage.removeTokenInStorage();
|
||||
GoRouter.of(context).go('/auth-screen', extra: true);
|
||||
}
|
||||
},
|
||||
child: Text("Выйти"),
|
||||
isDestructiveAction: true,
|
||||
),
|
||||
CupertinoDialogAction(
|
||||
onPressed: () {
|
||||
Navigator.of(context).pop();
|
||||
},
|
||||
child: Text("Отмена"),
|
||||
),
|
||||
],
|
||||
content: Text("Вы уверены что хотите выйти из аккаунта?"),
|
||||
),
|
||||
CupertinoDialogAction(
|
||||
onPressed: () {
|
||||
Navigator.of(context).pop();
|
||||
},
|
||||
child: Text("Отмена"),
|
||||
),
|
||||
],
|
||||
content: Text("Вы уверены что хотите выйти из аккаунта?"),
|
||||
),
|
||||
);
|
||||
};
|
||||
}
|
||||
|
||||
23
lib/features/my_finance/models/card_model.dart
Normal file
23
lib/features/my_finance/models/card_model.dart
Normal file
@@ -0,0 +1,23 @@
|
||||
import 'package:freezed_annotation/freezed_annotation.dart';
|
||||
|
||||
part 'card_model.freezed.dart';
|
||||
part 'card_model.g.dart';
|
||||
|
||||
@freezed
|
||||
class CardModel with _$CardModel {
|
||||
|
||||
factory CardModel({
|
||||
required int id,
|
||||
@JsonKey(name: 'bank_pan') required String cardNumber,
|
||||
@JsonKey(name: 'is_default', fromJson: parseBool) required bool isDefault,
|
||||
}) = _CardModel;
|
||||
|
||||
factory CardModel.fromJson(Map<String, dynamic> json) => _$CardModelFromJson(json);
|
||||
}
|
||||
|
||||
bool parseBool(json) {
|
||||
if (json == 1 || json == true) {
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
232
lib/features/my_finance/models/card_model.freezed.dart
Normal file
232
lib/features/my_finance/models/card_model.freezed.dart
Normal file
@@ -0,0 +1,232 @@
|
||||
// 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 'card_model.dart';
|
||||
|
||||
// **************************************************************************
|
||||
// FreezedGenerator
|
||||
// **************************************************************************
|
||||
|
||||
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',
|
||||
);
|
||||
|
||||
CardModel _$CardModelFromJson(Map<String, dynamic> json) {
|
||||
return _CardModel.fromJson(json);
|
||||
}
|
||||
|
||||
/// @nodoc
|
||||
mixin _$CardModel {
|
||||
int get id => throw _privateConstructorUsedError;
|
||||
@JsonKey(name: 'bank_pan')
|
||||
String get cardNumber => throw _privateConstructorUsedError;
|
||||
@JsonKey(name: 'is_default', fromJson: parseBool)
|
||||
bool get isDefault => throw _privateConstructorUsedError;
|
||||
|
||||
/// Serializes this CardModel to a JSON map.
|
||||
Map<String, dynamic> toJson() => throw _privateConstructorUsedError;
|
||||
|
||||
/// Create a copy of CardModel
|
||||
/// with the given fields replaced by the non-null parameter values.
|
||||
@JsonKey(includeFromJson: false, includeToJson: false)
|
||||
$CardModelCopyWith<CardModel> get copyWith =>
|
||||
throw _privateConstructorUsedError;
|
||||
}
|
||||
|
||||
/// @nodoc
|
||||
abstract class $CardModelCopyWith<$Res> {
|
||||
factory $CardModelCopyWith(CardModel value, $Res Function(CardModel) then) =
|
||||
_$CardModelCopyWithImpl<$Res, CardModel>;
|
||||
@useResult
|
||||
$Res call({
|
||||
int id,
|
||||
@JsonKey(name: 'bank_pan') String cardNumber,
|
||||
@JsonKey(name: 'is_default', fromJson: parseBool) bool isDefault,
|
||||
});
|
||||
}
|
||||
|
||||
/// @nodoc
|
||||
class _$CardModelCopyWithImpl<$Res, $Val extends CardModel>
|
||||
implements $CardModelCopyWith<$Res> {
|
||||
_$CardModelCopyWithImpl(this._value, this._then);
|
||||
|
||||
// ignore: unused_field
|
||||
final $Val _value;
|
||||
// ignore: unused_field
|
||||
final $Res Function($Val) _then;
|
||||
|
||||
/// Create a copy of CardModel
|
||||
/// with the given fields replaced by the non-null parameter values.
|
||||
@pragma('vm:prefer-inline')
|
||||
@override
|
||||
$Res call({
|
||||
Object? id = null,
|
||||
Object? cardNumber = null,
|
||||
Object? isDefault = null,
|
||||
}) {
|
||||
return _then(
|
||||
_value.copyWith(
|
||||
id:
|
||||
null == id
|
||||
? _value.id
|
||||
: id // ignore: cast_nullable_to_non_nullable
|
||||
as int,
|
||||
cardNumber:
|
||||
null == cardNumber
|
||||
? _value.cardNumber
|
||||
: cardNumber // ignore: cast_nullable_to_non_nullable
|
||||
as String,
|
||||
isDefault:
|
||||
null == isDefault
|
||||
? _value.isDefault
|
||||
: isDefault // ignore: cast_nullable_to_non_nullable
|
||||
as bool,
|
||||
)
|
||||
as $Val,
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
/// @nodoc
|
||||
abstract class _$$CardModelImplCopyWith<$Res>
|
||||
implements $CardModelCopyWith<$Res> {
|
||||
factory _$$CardModelImplCopyWith(
|
||||
_$CardModelImpl value,
|
||||
$Res Function(_$CardModelImpl) then,
|
||||
) = __$$CardModelImplCopyWithImpl<$Res>;
|
||||
@override
|
||||
@useResult
|
||||
$Res call({
|
||||
int id,
|
||||
@JsonKey(name: 'bank_pan') String cardNumber,
|
||||
@JsonKey(name: 'is_default', fromJson: parseBool) bool isDefault,
|
||||
});
|
||||
}
|
||||
|
||||
/// @nodoc
|
||||
class __$$CardModelImplCopyWithImpl<$Res>
|
||||
extends _$CardModelCopyWithImpl<$Res, _$CardModelImpl>
|
||||
implements _$$CardModelImplCopyWith<$Res> {
|
||||
__$$CardModelImplCopyWithImpl(
|
||||
_$CardModelImpl _value,
|
||||
$Res Function(_$CardModelImpl) _then,
|
||||
) : super(_value, _then);
|
||||
|
||||
/// Create a copy of CardModel
|
||||
/// with the given fields replaced by the non-null parameter values.
|
||||
@pragma('vm:prefer-inline')
|
||||
@override
|
||||
$Res call({
|
||||
Object? id = null,
|
||||
Object? cardNumber = null,
|
||||
Object? isDefault = null,
|
||||
}) {
|
||||
return _then(
|
||||
_$CardModelImpl(
|
||||
id:
|
||||
null == id
|
||||
? _value.id
|
||||
: id // ignore: cast_nullable_to_non_nullable
|
||||
as int,
|
||||
cardNumber:
|
||||
null == cardNumber
|
||||
? _value.cardNumber
|
||||
: cardNumber // ignore: cast_nullable_to_non_nullable
|
||||
as String,
|
||||
isDefault:
|
||||
null == isDefault
|
||||
? _value.isDefault
|
||||
: isDefault // ignore: cast_nullable_to_non_nullable
|
||||
as bool,
|
||||
),
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
/// @nodoc
|
||||
@JsonSerializable()
|
||||
class _$CardModelImpl implements _CardModel {
|
||||
_$CardModelImpl({
|
||||
required this.id,
|
||||
@JsonKey(name: 'bank_pan') required this.cardNumber,
|
||||
@JsonKey(name: 'is_default', fromJson: parseBool) required this.isDefault,
|
||||
});
|
||||
|
||||
factory _$CardModelImpl.fromJson(Map<String, dynamic> json) =>
|
||||
_$$CardModelImplFromJson(json);
|
||||
|
||||
@override
|
||||
final int id;
|
||||
@override
|
||||
@JsonKey(name: 'bank_pan')
|
||||
final String cardNumber;
|
||||
@override
|
||||
@JsonKey(name: 'is_default', fromJson: parseBool)
|
||||
final bool isDefault;
|
||||
|
||||
@override
|
||||
String toString() {
|
||||
return 'CardModel(id: $id, cardNumber: $cardNumber, isDefault: $isDefault)';
|
||||
}
|
||||
|
||||
@override
|
||||
bool operator ==(Object other) {
|
||||
return identical(this, other) ||
|
||||
(other.runtimeType == runtimeType &&
|
||||
other is _$CardModelImpl &&
|
||||
(identical(other.id, id) || other.id == id) &&
|
||||
(identical(other.cardNumber, cardNumber) ||
|
||||
other.cardNumber == cardNumber) &&
|
||||
(identical(other.isDefault, isDefault) ||
|
||||
other.isDefault == isDefault));
|
||||
}
|
||||
|
||||
@JsonKey(includeFromJson: false, includeToJson: false)
|
||||
@override
|
||||
int get hashCode => Object.hash(runtimeType, id, cardNumber, isDefault);
|
||||
|
||||
/// Create a copy of CardModel
|
||||
/// with the given fields replaced by the non-null parameter values.
|
||||
@JsonKey(includeFromJson: false, includeToJson: false)
|
||||
@override
|
||||
@pragma('vm:prefer-inline')
|
||||
_$$CardModelImplCopyWith<_$CardModelImpl> get copyWith =>
|
||||
__$$CardModelImplCopyWithImpl<_$CardModelImpl>(this, _$identity);
|
||||
|
||||
@override
|
||||
Map<String, dynamic> toJson() {
|
||||
return _$$CardModelImplToJson(this);
|
||||
}
|
||||
}
|
||||
|
||||
abstract class _CardModel implements CardModel {
|
||||
factory _CardModel({
|
||||
required final int id,
|
||||
@JsonKey(name: 'bank_pan') required final String cardNumber,
|
||||
@JsonKey(name: 'is_default', fromJson: parseBool)
|
||||
required final bool isDefault,
|
||||
}) = _$CardModelImpl;
|
||||
|
||||
factory _CardModel.fromJson(Map<String, dynamic> json) =
|
||||
_$CardModelImpl.fromJson;
|
||||
|
||||
@override
|
||||
int get id;
|
||||
@override
|
||||
@JsonKey(name: 'bank_pan')
|
||||
String get cardNumber;
|
||||
@override
|
||||
@JsonKey(name: 'is_default', fromJson: parseBool)
|
||||
bool get isDefault;
|
||||
|
||||
/// Create a copy of CardModel
|
||||
/// with the given fields replaced by the non-null parameter values.
|
||||
@override
|
||||
@JsonKey(includeFromJson: false, includeToJson: false)
|
||||
_$$CardModelImplCopyWith<_$CardModelImpl> get copyWith =>
|
||||
throw _privateConstructorUsedError;
|
||||
}
|
||||
21
lib/features/my_finance/models/card_model.g.dart
Normal file
21
lib/features/my_finance/models/card_model.g.dart
Normal file
@@ -0,0 +1,21 @@
|
||||
// GENERATED CODE - DO NOT MODIFY BY HAND
|
||||
|
||||
part of 'card_model.dart';
|
||||
|
||||
// **************************************************************************
|
||||
// JsonSerializableGenerator
|
||||
// **************************************************************************
|
||||
|
||||
_$CardModelImpl _$$CardModelImplFromJson(Map<String, dynamic> json) =>
|
||||
_$CardModelImpl(
|
||||
id: (json['id'] as num).toInt(),
|
||||
cardNumber: json['bank_pan'] as String,
|
||||
isDefault: parseBool(json['is_default']),
|
||||
);
|
||||
|
||||
Map<String, dynamic> _$$CardModelImplToJson(_$CardModelImpl instance) =>
|
||||
<String, dynamic>{
|
||||
'id': instance.id,
|
||||
'bank_pan': instance.cardNumber,
|
||||
'is_default': instance.isDefault,
|
||||
};
|
||||
14
lib/features/my_finance/models/payment_url_model.dart
Normal file
14
lib/features/my_finance/models/payment_url_model.dart
Normal file
@@ -0,0 +1,14 @@
|
||||
import 'package:freezed_annotation/freezed_annotation.dart';
|
||||
|
||||
part 'payment_url_model.freezed.dart';
|
||||
part 'payment_url_model.g.dart';
|
||||
|
||||
@freezed
|
||||
class PaymentUrlModel with _$PaymentUrlModel {
|
||||
|
||||
factory PaymentUrlModel({
|
||||
required String paymentUrl,
|
||||
}) = _PaymentUrlModel;
|
||||
|
||||
factory PaymentUrlModel.fromJson(Map<String, dynamic> json) => _$PaymentUrlModelFromJson(json);
|
||||
}
|
||||
174
lib/features/my_finance/models/payment_url_model.freezed.dart
Normal file
174
lib/features/my_finance/models/payment_url_model.freezed.dart
Normal file
@@ -0,0 +1,174 @@
|
||||
// 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 'payment_url_model.dart';
|
||||
|
||||
// **************************************************************************
|
||||
// FreezedGenerator
|
||||
// **************************************************************************
|
||||
|
||||
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',
|
||||
);
|
||||
|
||||
PaymentUrlModel _$PaymentUrlModelFromJson(Map<String, dynamic> json) {
|
||||
return _PaymentUrlModel.fromJson(json);
|
||||
}
|
||||
|
||||
/// @nodoc
|
||||
mixin _$PaymentUrlModel {
|
||||
String get paymentUrl => throw _privateConstructorUsedError;
|
||||
|
||||
/// Serializes this PaymentUrlModel to a JSON map.
|
||||
Map<String, dynamic> toJson() => throw _privateConstructorUsedError;
|
||||
|
||||
/// Create a copy of PaymentUrlModel
|
||||
/// with the given fields replaced by the non-null parameter values.
|
||||
@JsonKey(includeFromJson: false, includeToJson: false)
|
||||
$PaymentUrlModelCopyWith<PaymentUrlModel> get copyWith =>
|
||||
throw _privateConstructorUsedError;
|
||||
}
|
||||
|
||||
/// @nodoc
|
||||
abstract class $PaymentUrlModelCopyWith<$Res> {
|
||||
factory $PaymentUrlModelCopyWith(
|
||||
PaymentUrlModel value,
|
||||
$Res Function(PaymentUrlModel) then,
|
||||
) = _$PaymentUrlModelCopyWithImpl<$Res, PaymentUrlModel>;
|
||||
@useResult
|
||||
$Res call({String paymentUrl});
|
||||
}
|
||||
|
||||
/// @nodoc
|
||||
class _$PaymentUrlModelCopyWithImpl<$Res, $Val extends PaymentUrlModel>
|
||||
implements $PaymentUrlModelCopyWith<$Res> {
|
||||
_$PaymentUrlModelCopyWithImpl(this._value, this._then);
|
||||
|
||||
// ignore: unused_field
|
||||
final $Val _value;
|
||||
// ignore: unused_field
|
||||
final $Res Function($Val) _then;
|
||||
|
||||
/// Create a copy of PaymentUrlModel
|
||||
/// with the given fields replaced by the non-null parameter values.
|
||||
@pragma('vm:prefer-inline')
|
||||
@override
|
||||
$Res call({Object? paymentUrl = null}) {
|
||||
return _then(
|
||||
_value.copyWith(
|
||||
paymentUrl:
|
||||
null == paymentUrl
|
||||
? _value.paymentUrl
|
||||
: paymentUrl // ignore: cast_nullable_to_non_nullable
|
||||
as String,
|
||||
)
|
||||
as $Val,
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
/// @nodoc
|
||||
abstract class _$$PaymentUrlModelImplCopyWith<$Res>
|
||||
implements $PaymentUrlModelCopyWith<$Res> {
|
||||
factory _$$PaymentUrlModelImplCopyWith(
|
||||
_$PaymentUrlModelImpl value,
|
||||
$Res Function(_$PaymentUrlModelImpl) then,
|
||||
) = __$$PaymentUrlModelImplCopyWithImpl<$Res>;
|
||||
@override
|
||||
@useResult
|
||||
$Res call({String paymentUrl});
|
||||
}
|
||||
|
||||
/// @nodoc
|
||||
class __$$PaymentUrlModelImplCopyWithImpl<$Res>
|
||||
extends _$PaymentUrlModelCopyWithImpl<$Res, _$PaymentUrlModelImpl>
|
||||
implements _$$PaymentUrlModelImplCopyWith<$Res> {
|
||||
__$$PaymentUrlModelImplCopyWithImpl(
|
||||
_$PaymentUrlModelImpl _value,
|
||||
$Res Function(_$PaymentUrlModelImpl) _then,
|
||||
) : super(_value, _then);
|
||||
|
||||
/// Create a copy of PaymentUrlModel
|
||||
/// with the given fields replaced by the non-null parameter values.
|
||||
@pragma('vm:prefer-inline')
|
||||
@override
|
||||
$Res call({Object? paymentUrl = null}) {
|
||||
return _then(
|
||||
_$PaymentUrlModelImpl(
|
||||
paymentUrl:
|
||||
null == paymentUrl
|
||||
? _value.paymentUrl
|
||||
: paymentUrl // ignore: cast_nullable_to_non_nullable
|
||||
as String,
|
||||
),
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
/// @nodoc
|
||||
@JsonSerializable()
|
||||
class _$PaymentUrlModelImpl implements _PaymentUrlModel {
|
||||
_$PaymentUrlModelImpl({required this.paymentUrl});
|
||||
|
||||
factory _$PaymentUrlModelImpl.fromJson(Map<String, dynamic> json) =>
|
||||
_$$PaymentUrlModelImplFromJson(json);
|
||||
|
||||
@override
|
||||
final String paymentUrl;
|
||||
|
||||
@override
|
||||
String toString() {
|
||||
return 'PaymentUrlModel(paymentUrl: $paymentUrl)';
|
||||
}
|
||||
|
||||
@override
|
||||
bool operator ==(Object other) {
|
||||
return identical(this, other) ||
|
||||
(other.runtimeType == runtimeType &&
|
||||
other is _$PaymentUrlModelImpl &&
|
||||
(identical(other.paymentUrl, paymentUrl) ||
|
||||
other.paymentUrl == paymentUrl));
|
||||
}
|
||||
|
||||
@JsonKey(includeFromJson: false, includeToJson: false)
|
||||
@override
|
||||
int get hashCode => Object.hash(runtimeType, paymentUrl);
|
||||
|
||||
/// Create a copy of PaymentUrlModel
|
||||
/// with the given fields replaced by the non-null parameter values.
|
||||
@JsonKey(includeFromJson: false, includeToJson: false)
|
||||
@override
|
||||
@pragma('vm:prefer-inline')
|
||||
_$$PaymentUrlModelImplCopyWith<_$PaymentUrlModelImpl> get copyWith =>
|
||||
__$$PaymentUrlModelImplCopyWithImpl<_$PaymentUrlModelImpl>(
|
||||
this,
|
||||
_$identity,
|
||||
);
|
||||
|
||||
@override
|
||||
Map<String, dynamic> toJson() {
|
||||
return _$$PaymentUrlModelImplToJson(this);
|
||||
}
|
||||
}
|
||||
|
||||
abstract class _PaymentUrlModel implements PaymentUrlModel {
|
||||
factory _PaymentUrlModel({required final String paymentUrl}) =
|
||||
_$PaymentUrlModelImpl;
|
||||
|
||||
factory _PaymentUrlModel.fromJson(Map<String, dynamic> json) =
|
||||
_$PaymentUrlModelImpl.fromJson;
|
||||
|
||||
@override
|
||||
String get paymentUrl;
|
||||
|
||||
/// Create a copy of PaymentUrlModel
|
||||
/// with the given fields replaced by the non-null parameter values.
|
||||
@override
|
||||
@JsonKey(includeFromJson: false, includeToJson: false)
|
||||
_$$PaymentUrlModelImplCopyWith<_$PaymentUrlModelImpl> get copyWith =>
|
||||
throw _privateConstructorUsedError;
|
||||
}
|
||||
15
lib/features/my_finance/models/payment_url_model.g.dart
Normal file
15
lib/features/my_finance/models/payment_url_model.g.dart
Normal file
@@ -0,0 +1,15 @@
|
||||
// GENERATED CODE - DO NOT MODIFY BY HAND
|
||||
|
||||
part of 'payment_url_model.dart';
|
||||
|
||||
// **************************************************************************
|
||||
// JsonSerializableGenerator
|
||||
// **************************************************************************
|
||||
|
||||
_$PaymentUrlModelImpl _$$PaymentUrlModelImplFromJson(
|
||||
Map<String, dynamic> json,
|
||||
) => _$PaymentUrlModelImpl(paymentUrl: json['paymentUrl'] as String);
|
||||
|
||||
Map<String, dynamic> _$$PaymentUrlModelImplToJson(
|
||||
_$PaymentUrlModelImpl instance,
|
||||
) => <String, dynamic>{'paymentUrl': instance.paymentUrl};
|
||||
@@ -0,0 +1,66 @@
|
||||
import 'dart:developer';
|
||||
|
||||
import 'package:easy_debounce/easy_debounce.dart';
|
||||
import 'package:eatvio_app/features/my_finance/models/payment_url_model.dart';
|
||||
import 'package:eatvio_app/features/my_finance/presentation/cubit/user_cards_cubit/user_cards_state.dart';
|
||||
import 'package:eatvio_app/features/my_finance/repositories/cards_repository.dart';
|
||||
import 'package:flutter_bloc/flutter_bloc.dart';
|
||||
|
||||
class UserCardsCubit extends Cubit<UserCardsState> {
|
||||
final CardsRepository cardsRepository;
|
||||
UserCardsCubit({required this.cardsRepository}) : super(UserCardsState());
|
||||
|
||||
Future<PaymentUrlModel?> addCard() async {
|
||||
try {
|
||||
return await cardsRepository.addCard();
|
||||
} catch (e, st) {
|
||||
log(e.toString(), stackTrace: st);
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
Future<void> getCards() async {
|
||||
try {
|
||||
if (isClosed) return;
|
||||
final cards = await cardsRepository.getCards();
|
||||
emit(state.copyWith(cards: cards));
|
||||
} catch (e, st) {
|
||||
log(e.toString(), stackTrace: st);
|
||||
}
|
||||
}
|
||||
|
||||
Future<void> markAsDefault({required int id}) async {
|
||||
final oldCards = [...state.cards];
|
||||
if (isClosed) return;
|
||||
final cards =
|
||||
oldCards.map((card) {
|
||||
if (card.id == id) {
|
||||
return card.copyWith(isDefault: true);
|
||||
}
|
||||
return card.copyWith(isDefault: false);
|
||||
}).toList();
|
||||
emit(state.copyWith(cards: cards));
|
||||
|
||||
EasyDebounce.debounce('markAsDefault', Duration(milliseconds: id), () async {
|
||||
try {
|
||||
await cardsRepository.markAsDefault(id: id);
|
||||
} catch (e, st) {
|
||||
emit(state.copyWith(cards: oldCards));
|
||||
log(e.toString(), stackTrace: st);
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
Future<void> deleteCard({required int id}) async {
|
||||
final oldCards = [...state.cards];
|
||||
try {
|
||||
if (isClosed) return;
|
||||
final cards = oldCards.where((card) => card.id != id).toList();
|
||||
emit(state.copyWith(cards: cards));
|
||||
await cardsRepository.deleteCard(id: id);
|
||||
} catch (e, st) {
|
||||
emit(state.copyWith(cards: oldCards));
|
||||
log(e.toString(), stackTrace: st);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,14 @@
|
||||
import 'package:eatvio_app/features/my_finance/models/card_model.dart';
|
||||
import 'package:freezed_annotation/freezed_annotation.dart';
|
||||
|
||||
part 'user_cards_state.freezed.dart';
|
||||
|
||||
@freezed
|
||||
class UserCardsState with _$UserCardsState {
|
||||
|
||||
factory UserCardsState({
|
||||
@Default([]) List<CardModel> cards,
|
||||
@Default(false) bool isLoading,
|
||||
}) = _UserCardsState;
|
||||
|
||||
}
|
||||
@@ -0,0 +1,186 @@
|
||||
// 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 'user_cards_state.dart';
|
||||
|
||||
// **************************************************************************
|
||||
// FreezedGenerator
|
||||
// **************************************************************************
|
||||
|
||||
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',
|
||||
);
|
||||
|
||||
/// @nodoc
|
||||
mixin _$UserCardsState {
|
||||
List<CardModel> get cards => throw _privateConstructorUsedError;
|
||||
bool get isLoading => throw _privateConstructorUsedError;
|
||||
|
||||
/// Create a copy of UserCardsState
|
||||
/// with the given fields replaced by the non-null parameter values.
|
||||
@JsonKey(includeFromJson: false, includeToJson: false)
|
||||
$UserCardsStateCopyWith<UserCardsState> get copyWith =>
|
||||
throw _privateConstructorUsedError;
|
||||
}
|
||||
|
||||
/// @nodoc
|
||||
abstract class $UserCardsStateCopyWith<$Res> {
|
||||
factory $UserCardsStateCopyWith(
|
||||
UserCardsState value,
|
||||
$Res Function(UserCardsState) then,
|
||||
) = _$UserCardsStateCopyWithImpl<$Res, UserCardsState>;
|
||||
@useResult
|
||||
$Res call({List<CardModel> cards, bool isLoading});
|
||||
}
|
||||
|
||||
/// @nodoc
|
||||
class _$UserCardsStateCopyWithImpl<$Res, $Val extends UserCardsState>
|
||||
implements $UserCardsStateCopyWith<$Res> {
|
||||
_$UserCardsStateCopyWithImpl(this._value, this._then);
|
||||
|
||||
// ignore: unused_field
|
||||
final $Val _value;
|
||||
// ignore: unused_field
|
||||
final $Res Function($Val) _then;
|
||||
|
||||
/// Create a copy of UserCardsState
|
||||
/// with the given fields replaced by the non-null parameter values.
|
||||
@pragma('vm:prefer-inline')
|
||||
@override
|
||||
$Res call({Object? cards = null, Object? isLoading = null}) {
|
||||
return _then(
|
||||
_value.copyWith(
|
||||
cards:
|
||||
null == cards
|
||||
? _value.cards
|
||||
: cards // ignore: cast_nullable_to_non_nullable
|
||||
as List<CardModel>,
|
||||
isLoading:
|
||||
null == isLoading
|
||||
? _value.isLoading
|
||||
: isLoading // ignore: cast_nullable_to_non_nullable
|
||||
as bool,
|
||||
)
|
||||
as $Val,
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
/// @nodoc
|
||||
abstract class _$$UserCardsStateImplCopyWith<$Res>
|
||||
implements $UserCardsStateCopyWith<$Res> {
|
||||
factory _$$UserCardsStateImplCopyWith(
|
||||
_$UserCardsStateImpl value,
|
||||
$Res Function(_$UserCardsStateImpl) then,
|
||||
) = __$$UserCardsStateImplCopyWithImpl<$Res>;
|
||||
@override
|
||||
@useResult
|
||||
$Res call({List<CardModel> cards, bool isLoading});
|
||||
}
|
||||
|
||||
/// @nodoc
|
||||
class __$$UserCardsStateImplCopyWithImpl<$Res>
|
||||
extends _$UserCardsStateCopyWithImpl<$Res, _$UserCardsStateImpl>
|
||||
implements _$$UserCardsStateImplCopyWith<$Res> {
|
||||
__$$UserCardsStateImplCopyWithImpl(
|
||||
_$UserCardsStateImpl _value,
|
||||
$Res Function(_$UserCardsStateImpl) _then,
|
||||
) : super(_value, _then);
|
||||
|
||||
/// Create a copy of UserCardsState
|
||||
/// with the given fields replaced by the non-null parameter values.
|
||||
@pragma('vm:prefer-inline')
|
||||
@override
|
||||
$Res call({Object? cards = null, Object? isLoading = null}) {
|
||||
return _then(
|
||||
_$UserCardsStateImpl(
|
||||
cards:
|
||||
null == cards
|
||||
? _value._cards
|
||||
: cards // ignore: cast_nullable_to_non_nullable
|
||||
as List<CardModel>,
|
||||
isLoading:
|
||||
null == isLoading
|
||||
? _value.isLoading
|
||||
: isLoading // ignore: cast_nullable_to_non_nullable
|
||||
as bool,
|
||||
),
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
/// @nodoc
|
||||
|
||||
class _$UserCardsStateImpl implements _UserCardsState {
|
||||
_$UserCardsStateImpl({
|
||||
final List<CardModel> cards = const [],
|
||||
this.isLoading = false,
|
||||
}) : _cards = cards;
|
||||
|
||||
final List<CardModel> _cards;
|
||||
@override
|
||||
@JsonKey()
|
||||
List<CardModel> get cards {
|
||||
if (_cards is EqualUnmodifiableListView) return _cards;
|
||||
// ignore: implicit_dynamic_type
|
||||
return EqualUnmodifiableListView(_cards);
|
||||
}
|
||||
|
||||
@override
|
||||
@JsonKey()
|
||||
final bool isLoading;
|
||||
|
||||
@override
|
||||
String toString() {
|
||||
return 'UserCardsState(cards: $cards, isLoading: $isLoading)';
|
||||
}
|
||||
|
||||
@override
|
||||
bool operator ==(Object other) {
|
||||
return identical(this, other) ||
|
||||
(other.runtimeType == runtimeType &&
|
||||
other is _$UserCardsStateImpl &&
|
||||
const DeepCollectionEquality().equals(other._cards, _cards) &&
|
||||
(identical(other.isLoading, isLoading) ||
|
||||
other.isLoading == isLoading));
|
||||
}
|
||||
|
||||
@override
|
||||
int get hashCode => Object.hash(
|
||||
runtimeType,
|
||||
const DeepCollectionEquality().hash(_cards),
|
||||
isLoading,
|
||||
);
|
||||
|
||||
/// Create a copy of UserCardsState
|
||||
/// with the given fields replaced by the non-null parameter values.
|
||||
@JsonKey(includeFromJson: false, includeToJson: false)
|
||||
@override
|
||||
@pragma('vm:prefer-inline')
|
||||
_$$UserCardsStateImplCopyWith<_$UserCardsStateImpl> get copyWith =>
|
||||
__$$UserCardsStateImplCopyWithImpl<_$UserCardsStateImpl>(
|
||||
this,
|
||||
_$identity,
|
||||
);
|
||||
}
|
||||
|
||||
abstract class _UserCardsState implements UserCardsState {
|
||||
factory _UserCardsState({final List<CardModel> cards, final bool isLoading}) =
|
||||
_$UserCardsStateImpl;
|
||||
|
||||
@override
|
||||
List<CardModel> get cards;
|
||||
@override
|
||||
bool get isLoading;
|
||||
|
||||
/// Create a copy of UserCardsState
|
||||
/// with the given fields replaced by the non-null parameter values.
|
||||
@override
|
||||
@JsonKey(includeFromJson: false, includeToJson: false)
|
||||
_$$UserCardsStateImplCopyWith<_$UserCardsStateImpl> get copyWith =>
|
||||
throw _privateConstructorUsedError;
|
||||
}
|
||||
@@ -1,21 +1,35 @@
|
||||
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/my_finance/presentation/cubit/user_cards_cubit/user_cards_cubit.dart';
|
||||
import 'package:eatvio_app/features/my_finance/presentation/cubit/user_cards_cubit/user_cards_state.dart';
|
||||
import 'package:eatvio_app/features/my_finance/presentation/widgets/card_widget.dart';
|
||||
import 'package:eatvio_app/generated/l10n.dart';
|
||||
import 'package:flutter/material.dart';
|
||||
import 'package:flutter_svg/flutter_svg.dart';
|
||||
import 'package:flutter_bloc/flutter_bloc.dart';
|
||||
import 'package:collection/collection.dart';
|
||||
|
||||
class CardSettingsScreen extends StatelessWidget {
|
||||
static const path = '/card-settings-screen';
|
||||
static const name = 'cardSettingsScreen';
|
||||
const CardSettingsScreen({super.key});
|
||||
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
return BlocProvider(create: (context) => sl<UserCardsCubit>()..getCards(), child: CardsSettingsContent());
|
||||
}
|
||||
}
|
||||
|
||||
class CardsSettingsContent extends StatelessWidget {
|
||||
CardsSettingsContent({super.key});
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
final s = S.of(context);
|
||||
return Scaffold(
|
||||
backgroundColor: Color(0xFFF0F2F5),
|
||||
appBar: AppBar(
|
||||
shape: RoundedRectangleBorder(
|
||||
borderRadius: BorderRadius.vertical(
|
||||
bottom: Radius.circular(12),
|
||||
),
|
||||
),
|
||||
title: Text('Мои карты'),
|
||||
shape: RoundedRectangleBorder(borderRadius: BorderRadius.vertical(bottom: Radius.circular(12))),
|
||||
title: Text(s.my_cards),
|
||||
centerTitle: true,
|
||||
),
|
||||
body: Column(
|
||||
@@ -30,41 +44,42 @@ class CardSettingsScreen extends StatelessWidget {
|
||||
const SizedBox(height: 16),
|
||||
Padding(
|
||||
padding: const EdgeInsets.symmetric(horizontal: 16),
|
||||
child: Text(
|
||||
'Привязанные карты',
|
||||
style: TextStyle(
|
||||
color: Color(0xFF323F4B),
|
||||
fontSize: 18,
|
||||
fontWeight: FontWeight.w600,
|
||||
height: 1,
|
||||
),
|
||||
),
|
||||
child: Text('Привязанные карты', style: TextStyle(color: Color(0xFF323F4B), fontSize: 18, fontWeight: FontWeight.w600, height: 1)),
|
||||
),
|
||||
const SizedBox(height: 8),
|
||||
Padding(
|
||||
padding: const EdgeInsets.symmetric(horizontal: 16),
|
||||
child: Text(
|
||||
'Выплату будут производиться\nна карту ** 0278',
|
||||
style: TextStyle(
|
||||
color: Color(0xFF323F4B),
|
||||
fontSize: 16,
|
||||
fontWeight: FontWeight.w500,
|
||||
height: 1,
|
||||
),
|
||||
child: BlocBuilder<UserCardsCubit, UserCardsState>(
|
||||
builder: (context, state) {
|
||||
final defaultCardNumber = state.cards.firstWhereOrNull((element) => element.isDefault)?.cardNumber;
|
||||
if (defaultCardNumber != null) {
|
||||
return Text(
|
||||
'Выплату будут производиться\nна карту ${defaultCardNumber.substring(defaultCardNumber.length - 7)}',
|
||||
style: TextStyle(color: Color(0xFF323F4B), fontSize: 16, fontWeight: FontWeight.w500, height: 1),
|
||||
);
|
||||
}
|
||||
return Text(s.no_default_cards, style: TextStyles.textMMedium.copyWith(color: appTheme.black));
|
||||
},
|
||||
),
|
||||
),
|
||||
const SizedBox(height: 16),
|
||||
SingleChildScrollView(
|
||||
padding: EdgeInsets.symmetric(horizontal: 16),
|
||||
scrollDirection: Axis.horizontal,
|
||||
child: Row(
|
||||
children: [
|
||||
_card(true),
|
||||
const SizedBox(width: 8),
|
||||
_card(),
|
||||
const SizedBox(width: 8),
|
||||
_card(),
|
||||
],
|
||||
child: BlocBuilder<UserCardsCubit, UserCardsState>(
|
||||
builder: (context, state) {
|
||||
if (state.isLoading) {}
|
||||
return Row(
|
||||
spacing: 12,
|
||||
children: List.generate(state.cards.length + 1, (index) {
|
||||
if (index < state.cards.length) {
|
||||
final cardsNumber = state.cards[index].cardNumber.substring(state.cards[index].cardNumber.length - 7);
|
||||
return CardWidget(isSelected: state.cards[index].isDefault, cardId: state.cards[index].id, cardNumber: cardsNumber);
|
||||
}
|
||||
return CardWidget(enabledAddCard: true);
|
||||
}),
|
||||
);
|
||||
},
|
||||
),
|
||||
),
|
||||
const SizedBox(height: 16),
|
||||
@@ -75,40 +90,4 @@ class CardSettingsScreen extends StatelessWidget {
|
||||
),
|
||||
);
|
||||
}
|
||||
|
||||
_card([bool isSelected = false]) {
|
||||
return Container(
|
||||
padding: EdgeInsets.all(4),
|
||||
decoration: BoxDecoration(
|
||||
borderRadius: BorderRadius.circular(8),
|
||||
border: Border.all(
|
||||
color: isSelected ? appTheme.blueA400 : Color(0xFFF1F2F6),
|
||||
width: 2,
|
||||
),
|
||||
),
|
||||
child: Container(
|
||||
width: 148,
|
||||
padding: EdgeInsets.all(10),
|
||||
decoration: BoxDecoration(
|
||||
color: Color(0xFFF1F2F6),
|
||||
borderRadius: BorderRadius.circular(4),
|
||||
),
|
||||
child: Column(
|
||||
children: [
|
||||
SvgPicture.asset('assets/icons/mir.svg'),
|
||||
const SizedBox(height: 24),
|
||||
Text(
|
||||
'** 0278',
|
||||
style: TextStyle(
|
||||
color: Color(0xFF323F4B),
|
||||
fontSize: 14,
|
||||
height: 1,
|
||||
fontWeight: FontWeight.w600,
|
||||
),
|
||||
),
|
||||
],
|
||||
),
|
||||
),
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -2,6 +2,7 @@ import 'package:eatvio_app/core/theme/theme_helper.dart';
|
||||
import 'package:eatvio_app/core/utils/date_time_utils.dart';
|
||||
import 'package:eatvio_app/core/widgets/custom_drop_down_button.dart';
|
||||
import 'package:eatvio_app/features/my_finance/entities/consultant_finance_entity.dart';
|
||||
import 'package:eatvio_app/features/my_finance/presentation/pages/card_settings.dart';
|
||||
import 'package:flutter/material.dart';
|
||||
import 'package:go_router/go_router.dart';
|
||||
|
||||
@@ -13,11 +14,7 @@ class UserFinanceScreen extends StatelessWidget {
|
||||
return Scaffold(
|
||||
backgroundColor: Color(0xFFF0F2F5),
|
||||
appBar: AppBar(
|
||||
shape: RoundedRectangleBorder(
|
||||
borderRadius: BorderRadiusDirectional.vertical(
|
||||
bottom: Radius.circular(12),
|
||||
),
|
||||
),
|
||||
shape: RoundedRectangleBorder(borderRadius: BorderRadiusDirectional.vertical(bottom: Radius.circular(12))),
|
||||
title: Text('История операций'),
|
||||
centerTitle: true,
|
||||
),
|
||||
@@ -28,26 +25,16 @@ class UserFinanceScreen extends StatelessWidget {
|
||||
const SizedBox(height: 8),
|
||||
InkWell(
|
||||
onTap: () {
|
||||
GoRouter.of(context).pushNamed('cardSettingsScreen');
|
||||
GoRouter.of(context).pushNamed(CardSettingsScreen.name);
|
||||
},
|
||||
borderRadius: BorderRadius.circular(20),
|
||||
child: Ink(
|
||||
decoration: BoxDecoration(
|
||||
borderRadius: BorderRadius.circular(20),
|
||||
color: appTheme.blueA400,
|
||||
),
|
||||
decoration: BoxDecoration(borderRadius: BorderRadius.circular(20), color: appTheme.blueA400),
|
||||
width: MediaQuery.of(context).size.width - 32,
|
||||
child: Center(
|
||||
child: Padding(
|
||||
padding: const EdgeInsets.all(16),
|
||||
child: Text(
|
||||
'Управление картами',
|
||||
style: TextStyle(
|
||||
color: Colors.white,
|
||||
fontSize: 16,
|
||||
fontWeight: FontWeight.w600,
|
||||
),
|
||||
),
|
||||
child: Text('Управление картами', style: TextStyle(color: Colors.white, fontSize: 16, fontWeight: FontWeight.w600)),
|
||||
),
|
||||
),
|
||||
),
|
||||
@@ -62,108 +49,73 @@ class UserFinanceScreen extends StatelessWidget {
|
||||
physics: const NeverScrollableScrollPhysics(),
|
||||
child: Column(
|
||||
children: [
|
||||
CustomDropDownButton(
|
||||
items: [],
|
||||
onChanged: (value) {},
|
||||
),
|
||||
CustomDropDownButton(items: [], onChanged: (value) {}),
|
||||
const SizedBox(height: 12),
|
||||
ListView.separated(
|
||||
shrinkWrap: true,
|
||||
physics: const NeverScrollableScrollPhysics(),
|
||||
itemBuilder: (context, index) => Material(
|
||||
color: Color(0xFFF6F6F6),
|
||||
borderRadius: BorderRadius.circular(20),
|
||||
child: Padding(
|
||||
padding: const EdgeInsets.all(12),
|
||||
child: Column(
|
||||
crossAxisAlignment: CrossAxisAlignment.start,
|
||||
children: [
|
||||
Row(
|
||||
mainAxisAlignment: MainAxisAlignment.spaceBetween,
|
||||
itemBuilder:
|
||||
(context, index) => Material(
|
||||
color: Color(0xFFF6F6F6),
|
||||
borderRadius: BorderRadius.circular(20),
|
||||
child: Padding(
|
||||
padding: const EdgeInsets.all(12),
|
||||
child: Column(
|
||||
crossAxisAlignment: CrossAxisAlignment.start,
|
||||
children: [
|
||||
Text(
|
||||
testFinanceEntity.consultationsList[index].id,
|
||||
style: TextStyle(
|
||||
color: Color(0xFF323F4B),
|
||||
height: 1,
|
||||
fontWeight: FontWeight.w500,
|
||||
),
|
||||
Row(
|
||||
mainAxisAlignment: MainAxisAlignment.spaceBetween,
|
||||
children: [
|
||||
Text(
|
||||
testFinanceEntity.consultationsList[index].id,
|
||||
style: TextStyle(color: Color(0xFF323F4B), height: 1, fontWeight: FontWeight.w500),
|
||||
),
|
||||
Text(
|
||||
testFinanceEntity.consultationsList[index].date.format('dd.MM.yyy', 'RU'),
|
||||
style: TextStyle(color: Color(0xFF6D6F71), height: 1, fontWeight: FontWeight.w500),
|
||||
),
|
||||
],
|
||||
),
|
||||
const SizedBox(height: 8),
|
||||
Text(
|
||||
testFinanceEntity.consultationsList[index].date.format('dd.MM.yyy', 'RU'),
|
||||
style: TextStyle(
|
||||
color: Color(0xFF6D6F71),
|
||||
height: 1,
|
||||
fontWeight: FontWeight.w500,
|
||||
),
|
||||
testFinanceEntity.consultationsList[index].title,
|
||||
style: TextStyle(color: appTheme.blueA400, height: 1, fontSize: 18, fontWeight: FontWeight.w600),
|
||||
),
|
||||
],
|
||||
),
|
||||
const SizedBox(height: 8),
|
||||
Text(
|
||||
testFinanceEntity.consultationsList[index].title,
|
||||
style: TextStyle(
|
||||
color: appTheme.blueA400,
|
||||
height: 1,
|
||||
fontSize: 18,
|
||||
fontWeight: FontWeight.w600,
|
||||
),
|
||||
),
|
||||
const SizedBox(height: 8),
|
||||
Text(
|
||||
'Покупатель: ' + testFinanceEntity.consultationsList[index].clientName,
|
||||
style: TextStyle(
|
||||
color: Color(0xFF323F4B),
|
||||
height: 1,
|
||||
fontSize: 14,
|
||||
fontWeight: FontWeight.w500,
|
||||
),
|
||||
),
|
||||
const SizedBox(height: 8),
|
||||
Text(
|
||||
testFinanceEntity.consultationsList[index].planDuration.toString() + ' дней',
|
||||
style: TextStyle(
|
||||
color: Color(0xFF323F4B),
|
||||
height: 1,
|
||||
fontSize: 14,
|
||||
fontWeight: FontWeight.w500,
|
||||
),
|
||||
),
|
||||
const SizedBox(height: 8),
|
||||
Row(
|
||||
mainAxisAlignment: MainAxisAlignment.spaceBetween,
|
||||
children: [
|
||||
const SizedBox(height: 8),
|
||||
Text(
|
||||
testFinanceEntity.consultationsList[index].price.toString() + ' ₽',
|
||||
style: TextStyle(
|
||||
color: Color(0xFF323F4B),
|
||||
height: 1,
|
||||
fontSize: 18,
|
||||
fontWeight: FontWeight.w600,
|
||||
),
|
||||
'Покупатель: ' + testFinanceEntity.consultationsList[index].clientName,
|
||||
style: TextStyle(color: Color(0xFF323F4B), height: 1, fontSize: 14, fontWeight: FontWeight.w500),
|
||||
),
|
||||
Material(
|
||||
color: Color(0xFF0BB450).withAlpha(11),
|
||||
borderRadius: BorderRadius.circular(8),
|
||||
child: Padding(
|
||||
padding: const EdgeInsets.symmetric(horizontal: 16, vertical: 4),
|
||||
child: Text(
|
||||
testFinanceEntity.consultationsList[index].status.name,
|
||||
style: TextStyle(
|
||||
fontSize: 14,
|
||||
fontWeight: FontWeight.w400,
|
||||
color: Color(0xFF0BB450),
|
||||
height: 1,
|
||||
const SizedBox(height: 8),
|
||||
Text(
|
||||
testFinanceEntity.consultationsList[index].planDuration.toString() + ' дней',
|
||||
style: TextStyle(color: Color(0xFF323F4B), height: 1, fontSize: 14, fontWeight: FontWeight.w500),
|
||||
),
|
||||
const SizedBox(height: 8),
|
||||
Row(
|
||||
mainAxisAlignment: MainAxisAlignment.spaceBetween,
|
||||
children: [
|
||||
Text(
|
||||
testFinanceEntity.consultationsList[index].price.toString() + ' ₽',
|
||||
style: TextStyle(color: Color(0xFF323F4B), height: 1, fontSize: 18, fontWeight: FontWeight.w600),
|
||||
),
|
||||
Material(
|
||||
color: Color(0xFF0BB450).withAlpha(11),
|
||||
borderRadius: BorderRadius.circular(8),
|
||||
child: Padding(
|
||||
padding: const EdgeInsets.symmetric(horizontal: 16, vertical: 4),
|
||||
child: Text(
|
||||
testFinanceEntity.consultationsList[index].status.name,
|
||||
style: TextStyle(fontSize: 14, fontWeight: FontWeight.w400, color: Color(0xFF0BB450), height: 1),
|
||||
),
|
||||
),
|
||||
),
|
||||
),
|
||||
],
|
||||
),
|
||||
],
|
||||
),
|
||||
],
|
||||
),
|
||||
),
|
||||
),
|
||||
),
|
||||
separatorBuilder: (context, index) => const SizedBox(height: 12),
|
||||
itemCount: testFinanceEntity.consultationsList.length,
|
||||
),
|
||||
|
||||
@@ -0,0 +1,68 @@
|
||||
import 'package:eatvio_app/core/theme/custom_text_style.dart';
|
||||
import 'package:eatvio_app/core/theme/theme_helper.dart';
|
||||
import 'package:eatvio_app/features/my_finance/presentation/cubit/user_cards_cubit/user_cards_cubit.dart';
|
||||
import 'package:eatvio_app/generated/l10n.dart';
|
||||
import 'package:flutter/material.dart';
|
||||
import 'package:flutter_bloc/flutter_bloc.dart';
|
||||
import 'package:flutter_svg/svg.dart';
|
||||
import 'package:url_launcher/url_launcher.dart';
|
||||
|
||||
class CardWidget extends StatelessWidget {
|
||||
const CardWidget({super.key, this.isSelected = false, this.enabledAddCard = false, this.cardId = 0, this.cardNumber = ''});
|
||||
final int cardId;
|
||||
final bool isSelected;
|
||||
final bool enabledAddCard;
|
||||
final String cardNumber;
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
final s = S.of(context);
|
||||
return GestureDetector(
|
||||
onTap: enabledAddCard
|
||||
? () async {
|
||||
final addCardUrl = await context.read<UserCardsCubit>().addCard();
|
||||
|
||||
if (addCardUrl != null) {
|
||||
final uri = Uri.parse(addCardUrl.paymentUrl);
|
||||
if (await canLaunchUrl(uri)) {
|
||||
await launchUrl(uri, mode: LaunchMode.externalApplication);
|
||||
}
|
||||
}
|
||||
}
|
||||
: () {
|
||||
context.read<UserCardsCubit>().markAsDefault(id: cardId);
|
||||
},
|
||||
child: Container(
|
||||
padding: EdgeInsets.all(4),
|
||||
decoration: BoxDecoration(
|
||||
borderRadius: BorderRadius.circular(8),
|
||||
border: Border.all(color: isSelected ? appTheme.blueA400 : Color(0xFFF1F2F6), width: 2),
|
||||
),
|
||||
child: enabledAddCard
|
||||
? Container(
|
||||
width: 148,
|
||||
padding: EdgeInsets.all(10),
|
||||
decoration: BoxDecoration(color: Color(0xFFF1F2F6), borderRadius: BorderRadius.circular(4)),
|
||||
child: Column(
|
||||
children: [
|
||||
SvgPicture.asset('assets/icons/add_card.svg'),
|
||||
const SizedBox(height: 24),
|
||||
Text(s.new_card, style: TextStyles.textSSemibold.copyWith(color: appTheme.black)),
|
||||
],
|
||||
),
|
||||
)
|
||||
: Container(
|
||||
width: 148,
|
||||
padding: EdgeInsets.all(10),
|
||||
decoration: BoxDecoration(color: Color(0xFFF1F2F6), borderRadius: BorderRadius.circular(4)),
|
||||
child: Column(
|
||||
children: [
|
||||
SvgPicture.asset('assets/icons/card.svg'),
|
||||
const SizedBox(height: 24),
|
||||
Text(cardNumber, style: TextStyles.textSSemibold.copyWith(color: appTheme.black)),
|
||||
],
|
||||
),
|
||||
),
|
||||
),
|
||||
);
|
||||
}
|
||||
}
|
||||
39
lib/features/my_finance/repositories/cards_repository.dart
Normal file
39
lib/features/my_finance/repositories/cards_repository.dart
Normal file
@@ -0,0 +1,39 @@
|
||||
import 'package:eatvio_app/features/my_finance/models/card_model.dart';
|
||||
import 'package:eatvio_app/features/my_finance/models/payment_url_model.dart';
|
||||
import 'package:eatvio_app/features/my_finance/services/cards_service.dart';
|
||||
|
||||
class CardsRepository {
|
||||
final CardsService cardsService;
|
||||
CardsRepository({required this.cardsService});
|
||||
Future<PaymentUrlModel> addCard() async {
|
||||
try {
|
||||
return await cardsService.addCard();
|
||||
} catch (e) {
|
||||
rethrow;
|
||||
}
|
||||
}
|
||||
|
||||
Future<List<CardModel>> getCards() async {
|
||||
try {
|
||||
return await cardsService.getCards();
|
||||
} catch (e) {
|
||||
rethrow;
|
||||
}
|
||||
}
|
||||
|
||||
Future<void> markAsDefault({required int id}) async {
|
||||
try {
|
||||
await cardsService.markAsDefault(id: id);
|
||||
} catch (e) {
|
||||
rethrow;
|
||||
}
|
||||
}
|
||||
|
||||
Future<void> deleteCard({required int id}) async {
|
||||
try {
|
||||
await cardsService.deleteCard(id: id);
|
||||
} catch (e) {
|
||||
rethrow;
|
||||
}
|
||||
}
|
||||
}
|
||||
28
lib/features/my_finance/services/cards_service.dart
Normal file
28
lib/features/my_finance/services/cards_service.dart
Normal file
@@ -0,0 +1,28 @@
|
||||
import 'package:dio/dio.dart';
|
||||
import 'package:eatvio_app/features/my_finance/models/card_model.dart';
|
||||
import 'package:eatvio_app/features/my_finance/models/payment_url_model.dart';
|
||||
import 'package:retrofit/retrofit.dart';
|
||||
|
||||
part 'cards_service.g.dart';
|
||||
|
||||
@RestApi()
|
||||
abstract class CardsService {
|
||||
factory CardsService(Dio dio, {String baseUrl}) = _CardsService;
|
||||
|
||||
@GET('/api/finances/cards')
|
||||
Future<List<CardModel>> getCards();
|
||||
|
||||
@POST('/api/finances/cards/add')
|
||||
Future<PaymentUrlModel> addCard();
|
||||
|
||||
@POST('/api/finances/cards/{id}/default')
|
||||
Future<void> markAsDefault({
|
||||
@Path('id') required int id,
|
||||
});
|
||||
|
||||
@POST('/api/finances/cards/{id}/remove')
|
||||
Future<void> deleteCard({
|
||||
@Path('id') required int id,
|
||||
});
|
||||
}
|
||||
|
||||
141
lib/features/my_finance/services/cards_service.g.dart
Normal file
141
lib/features/my_finance/services/cards_service.g.dart
Normal file
@@ -0,0 +1,141 @@
|
||||
// GENERATED CODE - DO NOT MODIFY BY HAND
|
||||
|
||||
part of 'cards_service.dart';
|
||||
|
||||
// **************************************************************************
|
||||
// RetrofitGenerator
|
||||
// **************************************************************************
|
||||
|
||||
// ignore_for_file: unnecessary_brace_in_string_interps,no_leading_underscores_for_local_identifiers,unused_element,unnecessary_string_interpolations
|
||||
|
||||
class _CardsService implements CardsService {
|
||||
_CardsService(this._dio, {this.baseUrl, this.errorLogger});
|
||||
|
||||
final Dio _dio;
|
||||
|
||||
String? baseUrl;
|
||||
|
||||
final ParseErrorLogger? errorLogger;
|
||||
|
||||
@override
|
||||
Future<List<CardModel>> getCards() async {
|
||||
final _extra = <String, dynamic>{};
|
||||
final queryParameters = <String, dynamic>{};
|
||||
final _headers = <String, dynamic>{};
|
||||
const Map<String, dynamic>? _data = null;
|
||||
final _options = _setStreamType<List<CardModel>>(
|
||||
Options(method: 'GET', headers: _headers, extra: _extra)
|
||||
.compose(
|
||||
_dio.options,
|
||||
'/api/finances/cards',
|
||||
queryParameters: queryParameters,
|
||||
data: _data,
|
||||
)
|
||||
.copyWith(baseUrl: _combineBaseUrls(_dio.options.baseUrl, baseUrl)),
|
||||
);
|
||||
final _result = await _dio.fetch<List<dynamic>>(_options);
|
||||
late List<CardModel> _value;
|
||||
try {
|
||||
_value =
|
||||
_result.data!
|
||||
.map((dynamic i) => CardModel.fromJson(i as Map<String, dynamic>))
|
||||
.toList();
|
||||
} on Object catch (e, s) {
|
||||
errorLogger?.logError(e, s, _options);
|
||||
rethrow;
|
||||
}
|
||||
return _value;
|
||||
}
|
||||
|
||||
@override
|
||||
Future<PaymentUrlModel> addCard() async {
|
||||
final _extra = <String, dynamic>{};
|
||||
final queryParameters = <String, dynamic>{};
|
||||
final _headers = <String, dynamic>{};
|
||||
const Map<String, dynamic>? _data = null;
|
||||
final _options = _setStreamType<PaymentUrlModel>(
|
||||
Options(method: 'POST', headers: _headers, extra: _extra)
|
||||
.compose(
|
||||
_dio.options,
|
||||
'/api/finances/cards/add',
|
||||
queryParameters: queryParameters,
|
||||
data: _data,
|
||||
)
|
||||
.copyWith(baseUrl: _combineBaseUrls(_dio.options.baseUrl, baseUrl)),
|
||||
);
|
||||
final _result = await _dio.fetch<Map<String, dynamic>>(_options);
|
||||
late PaymentUrlModel _value;
|
||||
try {
|
||||
_value = PaymentUrlModel.fromJson(_result.data!);
|
||||
} on Object catch (e, s) {
|
||||
errorLogger?.logError(e, s, _options);
|
||||
rethrow;
|
||||
}
|
||||
return _value;
|
||||
}
|
||||
|
||||
@override
|
||||
Future<void> markAsDefault({required int id}) async {
|
||||
final _extra = <String, dynamic>{};
|
||||
final queryParameters = <String, dynamic>{};
|
||||
final _headers = <String, dynamic>{};
|
||||
const Map<String, dynamic>? _data = null;
|
||||
final _options = _setStreamType<void>(
|
||||
Options(method: 'POST', headers: _headers, extra: _extra)
|
||||
.compose(
|
||||
_dio.options,
|
||||
'/api/finances/cards/${id}/default',
|
||||
queryParameters: queryParameters,
|
||||
data: _data,
|
||||
)
|
||||
.copyWith(baseUrl: _combineBaseUrls(_dio.options.baseUrl, baseUrl)),
|
||||
);
|
||||
await _dio.fetch<void>(_options);
|
||||
}
|
||||
|
||||
@override
|
||||
Future<void> deleteCard({required int id}) async {
|
||||
final _extra = <String, dynamic>{};
|
||||
final queryParameters = <String, dynamic>{};
|
||||
final _headers = <String, dynamic>{};
|
||||
const Map<String, dynamic>? _data = null;
|
||||
final _options = _setStreamType<void>(
|
||||
Options(method: 'POST', headers: _headers, extra: _extra)
|
||||
.compose(
|
||||
_dio.options,
|
||||
'/api/finances/cards/${id}/remove',
|
||||
queryParameters: queryParameters,
|
||||
data: _data,
|
||||
)
|
||||
.copyWith(baseUrl: _combineBaseUrls(_dio.options.baseUrl, baseUrl)),
|
||||
);
|
||||
await _dio.fetch<void>(_options);
|
||||
}
|
||||
|
||||
RequestOptions _setStreamType<T>(RequestOptions requestOptions) {
|
||||
if (T != dynamic &&
|
||||
!(requestOptions.responseType == ResponseType.bytes ||
|
||||
requestOptions.responseType == ResponseType.stream)) {
|
||||
if (T == String) {
|
||||
requestOptions.responseType = ResponseType.plain;
|
||||
} else {
|
||||
requestOptions.responseType = ResponseType.json;
|
||||
}
|
||||
}
|
||||
return requestOptions;
|
||||
}
|
||||
|
||||
String _combineBaseUrls(String dioBaseUrl, String? baseUrl) {
|
||||
if (baseUrl == null || baseUrl.trim().isEmpty) {
|
||||
return dioBaseUrl;
|
||||
}
|
||||
|
||||
final url = Uri.parse(baseUrl);
|
||||
|
||||
if (url.isAbsolute) {
|
||||
return url.toString();
|
||||
}
|
||||
|
||||
return Uri.parse(dioBaseUrl).resolveUri(url).toString();
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user