progress on home page
This commit is contained in:
58
lib/screens/pay/pay_controller.dart
Normal file
58
lib/screens/pay/pay_controller.dart
Normal file
@@ -0,0 +1,58 @@
|
||||
import 'package:flutter/material.dart';
|
||||
import 'package:freezed_annotation/freezed_annotation.dart';
|
||||
import 'package:qpay/http/http.dart';
|
||||
import 'package:qpay/screens/home/home_controller.dart' as hc;
|
||||
|
||||
part 'pay_controller.freezed.dart';
|
||||
part 'pay_controller.g.dart';
|
||||
|
||||
class PayScreenModel {
|
||||
List<BillProduct> products = [];
|
||||
late BillProduct selectedProduct;
|
||||
dynamic formData = {};
|
||||
bool isLoading = false;
|
||||
String? errorMessage;
|
||||
}
|
||||
|
||||
@freezed
|
||||
abstract class BillProduct with _$BillProduct {
|
||||
const factory BillProduct({
|
||||
required String uid,
|
||||
required String name,
|
||||
required String description,
|
||||
required String displayName,
|
||||
required double defaultAmount,
|
||||
required bool requiresAmount,
|
||||
}) = _BillProduct;
|
||||
|
||||
factory BillProduct.fromJson(Map<String, dynamic> json) =>
|
||||
_$BillProductFromJson(json);
|
||||
}
|
||||
|
||||
class PayController extends ChangeNotifier {
|
||||
final PayScreenModel model = PayScreenModel();
|
||||
final Http http = Http();
|
||||
|
||||
void updateSelectedProduct(BillProduct product) {
|
||||
model.selectedProduct = product;
|
||||
notifyListeners();
|
||||
}
|
||||
|
||||
Future<void> getProducts(String providerId) async {
|
||||
try {
|
||||
model.isLoading = true;
|
||||
|
||||
List<dynamic> response = await http.get(
|
||||
'/providers/$providerId/products',
|
||||
);
|
||||
model.products = response.map((e) => BillProduct.fromJson(e)).toList();
|
||||
} catch (e) {
|
||||
logger.e(e);
|
||||
model.errorMessage = e.toString();
|
||||
}
|
||||
|
||||
model.isLoading = false;
|
||||
notifyListeners();
|
||||
}
|
||||
|
||||
}
|
||||
163
lib/screens/pay/pay_controller.freezed.dart
Normal file
163
lib/screens/pay/pay_controller.freezed.dart
Normal file
@@ -0,0 +1,163 @@
|
||||
// dart format width=80
|
||||
// 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 'pay_controller.dart';
|
||||
|
||||
// **************************************************************************
|
||||
// FreezedGenerator
|
||||
// **************************************************************************
|
||||
|
||||
// dart format off
|
||||
T _$identity<T>(T value) => value;
|
||||
|
||||
/// @nodoc
|
||||
mixin _$BillProduct {
|
||||
|
||||
String get uid; String get name; String get description; String get displayName; double get defaultAmount; bool get requiresAmount;
|
||||
/// Create a copy of BillProduct
|
||||
/// with the given fields replaced by the non-null parameter values.
|
||||
@JsonKey(includeFromJson: false, includeToJson: false)
|
||||
@pragma('vm:prefer-inline')
|
||||
$BillProductCopyWith<BillProduct> get copyWith => _$BillProductCopyWithImpl<BillProduct>(this as BillProduct, _$identity);
|
||||
|
||||
/// Serializes this BillProduct to a JSON map.
|
||||
Map<String, dynamic> toJson();
|
||||
|
||||
|
||||
@override
|
||||
bool operator ==(Object other) {
|
||||
return identical(this, other) || (other.runtimeType == runtimeType&&other is BillProduct&&(identical(other.uid, uid) || other.uid == uid)&&(identical(other.name, name) || other.name == name)&&(identical(other.description, description) || other.description == description)&&(identical(other.displayName, displayName) || other.displayName == displayName)&&(identical(other.defaultAmount, defaultAmount) || other.defaultAmount == defaultAmount)&&(identical(other.requiresAmount, requiresAmount) || other.requiresAmount == requiresAmount));
|
||||
}
|
||||
|
||||
@JsonKey(includeFromJson: false, includeToJson: false)
|
||||
@override
|
||||
int get hashCode => Object.hash(runtimeType,uid,name,description,displayName,defaultAmount,requiresAmount);
|
||||
|
||||
@override
|
||||
String toString() {
|
||||
return 'BillProduct(uid: $uid, name: $name, description: $description, displayName: $displayName, defaultAmount: $defaultAmount, requiresAmount: $requiresAmount)';
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
||||
/// @nodoc
|
||||
abstract mixin class $BillProductCopyWith<$Res> {
|
||||
factory $BillProductCopyWith(BillProduct value, $Res Function(BillProduct) _then) = _$BillProductCopyWithImpl;
|
||||
@useResult
|
||||
$Res call({
|
||||
String uid, String name, String description, String displayName, double defaultAmount, bool requiresAmount
|
||||
});
|
||||
|
||||
|
||||
|
||||
|
||||
}
|
||||
/// @nodoc
|
||||
class _$BillProductCopyWithImpl<$Res>
|
||||
implements $BillProductCopyWith<$Res> {
|
||||
_$BillProductCopyWithImpl(this._self, this._then);
|
||||
|
||||
final BillProduct _self;
|
||||
final $Res Function(BillProduct) _then;
|
||||
|
||||
/// Create a copy of BillProduct
|
||||
/// with the given fields replaced by the non-null parameter values.
|
||||
@pragma('vm:prefer-inline') @override $Res call({Object? uid = null,Object? name = null,Object? description = null,Object? displayName = null,Object? defaultAmount = null,Object? requiresAmount = null,}) {
|
||||
return _then(_self.copyWith(
|
||||
uid: null == uid ? _self.uid : uid // ignore: cast_nullable_to_non_nullable
|
||||
as String,name: null == name ? _self.name : name // ignore: cast_nullable_to_non_nullable
|
||||
as String,description: null == description ? _self.description : description // ignore: cast_nullable_to_non_nullable
|
||||
as String,displayName: null == displayName ? _self.displayName : displayName // ignore: cast_nullable_to_non_nullable
|
||||
as String,defaultAmount: null == defaultAmount ? _self.defaultAmount : defaultAmount // ignore: cast_nullable_to_non_nullable
|
||||
as double,requiresAmount: null == requiresAmount ? _self.requiresAmount : requiresAmount // ignore: cast_nullable_to_non_nullable
|
||||
as bool,
|
||||
));
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
|
||||
/// @nodoc
|
||||
@JsonSerializable()
|
||||
|
||||
class _BillProduct implements BillProduct {
|
||||
const _BillProduct({required this.uid, required this.name, required this.description, required this.displayName, required this.defaultAmount, required this.requiresAmount});
|
||||
factory _BillProduct.fromJson(Map<String, dynamic> json) => _$BillProductFromJson(json);
|
||||
|
||||
@override final String uid;
|
||||
@override final String name;
|
||||
@override final String description;
|
||||
@override final String displayName;
|
||||
@override final double defaultAmount;
|
||||
@override final bool requiresAmount;
|
||||
|
||||
/// Create a copy of BillProduct
|
||||
/// with the given fields replaced by the non-null parameter values.
|
||||
@override @JsonKey(includeFromJson: false, includeToJson: false)
|
||||
@pragma('vm:prefer-inline')
|
||||
_$BillProductCopyWith<_BillProduct> get copyWith => __$BillProductCopyWithImpl<_BillProduct>(this, _$identity);
|
||||
|
||||
@override
|
||||
Map<String, dynamic> toJson() {
|
||||
return _$BillProductToJson(this, );
|
||||
}
|
||||
|
||||
@override
|
||||
bool operator ==(Object other) {
|
||||
return identical(this, other) || (other.runtimeType == runtimeType&&other is _BillProduct&&(identical(other.uid, uid) || other.uid == uid)&&(identical(other.name, name) || other.name == name)&&(identical(other.description, description) || other.description == description)&&(identical(other.displayName, displayName) || other.displayName == displayName)&&(identical(other.defaultAmount, defaultAmount) || other.defaultAmount == defaultAmount)&&(identical(other.requiresAmount, requiresAmount) || other.requiresAmount == requiresAmount));
|
||||
}
|
||||
|
||||
@JsonKey(includeFromJson: false, includeToJson: false)
|
||||
@override
|
||||
int get hashCode => Object.hash(runtimeType,uid,name,description,displayName,defaultAmount,requiresAmount);
|
||||
|
||||
@override
|
||||
String toString() {
|
||||
return 'BillProduct(uid: $uid, name: $name, description: $description, displayName: $displayName, defaultAmount: $defaultAmount, requiresAmount: $requiresAmount)';
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
||||
/// @nodoc
|
||||
abstract mixin class _$BillProductCopyWith<$Res> implements $BillProductCopyWith<$Res> {
|
||||
factory _$BillProductCopyWith(_BillProduct value, $Res Function(_BillProduct) _then) = __$BillProductCopyWithImpl;
|
||||
@override @useResult
|
||||
$Res call({
|
||||
String uid, String name, String description, String displayName, double defaultAmount, bool requiresAmount
|
||||
});
|
||||
|
||||
|
||||
|
||||
|
||||
}
|
||||
/// @nodoc
|
||||
class __$BillProductCopyWithImpl<$Res>
|
||||
implements _$BillProductCopyWith<$Res> {
|
||||
__$BillProductCopyWithImpl(this._self, this._then);
|
||||
|
||||
final _BillProduct _self;
|
||||
final $Res Function(_BillProduct) _then;
|
||||
|
||||
/// Create a copy of BillProduct
|
||||
/// with the given fields replaced by the non-null parameter values.
|
||||
@override @pragma('vm:prefer-inline') $Res call({Object? uid = null,Object? name = null,Object? description = null,Object? displayName = null,Object? defaultAmount = null,Object? requiresAmount = null,}) {
|
||||
return _then(_BillProduct(
|
||||
uid: null == uid ? _self.uid : uid // ignore: cast_nullable_to_non_nullable
|
||||
as String,name: null == name ? _self.name : name // ignore: cast_nullable_to_non_nullable
|
||||
as String,description: null == description ? _self.description : description // ignore: cast_nullable_to_non_nullable
|
||||
as String,displayName: null == displayName ? _self.displayName : displayName // ignore: cast_nullable_to_non_nullable
|
||||
as String,defaultAmount: null == defaultAmount ? _self.defaultAmount : defaultAmount // ignore: cast_nullable_to_non_nullable
|
||||
as double,requiresAmount: null == requiresAmount ? _self.requiresAmount : requiresAmount // ignore: cast_nullable_to_non_nullable
|
||||
as bool,
|
||||
));
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
||||
// dart format on
|
||||
26
lib/screens/pay/pay_controller.g.dart
Normal file
26
lib/screens/pay/pay_controller.g.dart
Normal file
@@ -0,0 +1,26 @@
|
||||
// GENERATED CODE - DO NOT MODIFY BY HAND
|
||||
|
||||
part of 'pay_controller.dart';
|
||||
|
||||
// **************************************************************************
|
||||
// JsonSerializableGenerator
|
||||
// **************************************************************************
|
||||
|
||||
_BillProduct _$BillProductFromJson(Map<String, dynamic> json) => _BillProduct(
|
||||
uid: json['uid'] as String,
|
||||
name: json['name'] as String,
|
||||
description: json['description'] as String,
|
||||
displayName: json['displayName'] as String,
|
||||
defaultAmount: (json['defaultAmount'] as num).toDouble(),
|
||||
requiresAmount: json['requiresAmount'] as bool,
|
||||
);
|
||||
|
||||
Map<String, dynamic> _$BillProductToJson(_BillProduct instance) =>
|
||||
<String, dynamic>{
|
||||
'uid': instance.uid,
|
||||
'name': instance.name,
|
||||
'description': instance.description,
|
||||
'displayName': instance.displayName,
|
||||
'defaultAmount': instance.defaultAmount,
|
||||
'requiresAmount': instance.requiresAmount,
|
||||
};
|
||||
237
lib/screens/pay/pay_screen.dart
Normal file
237
lib/screens/pay/pay_screen.dart
Normal file
@@ -0,0 +1,237 @@
|
||||
import 'package:flutter/material.dart';
|
||||
import 'package:provider/provider.dart';
|
||||
import 'package:qpay/screens/pay/pay_controller.dart';
|
||||
import 'package:skeletonizer/skeletonizer.dart';
|
||||
|
||||
class PayScreen extends StatefulWidget {
|
||||
const PayScreen({super.key});
|
||||
|
||||
@override
|
||||
State<PayScreen> createState() => _PayScreenState();
|
||||
}
|
||||
|
||||
class _PayScreenState extends State<PayScreen> with TickerProviderStateMixin {
|
||||
late AnimationController _controller;
|
||||
late Animation<double> _fadeAnimation;
|
||||
late Animation<Offset> _slideAnimation;
|
||||
|
||||
final _formKey = GlobalKey<FormState>();
|
||||
final _amountController = TextEditingController();
|
||||
final _descriptionController = TextEditingController();
|
||||
String _selectedBillType = '';
|
||||
|
||||
@override
|
||||
void initState() {
|
||||
super.initState();
|
||||
|
||||
_controller = AnimationController(
|
||||
vsync: this,
|
||||
duration: const Duration(milliseconds: 800),
|
||||
);
|
||||
|
||||
_fadeAnimation = Tween<double>(begin: 0.0, end: 1.0).animate(
|
||||
CurvedAnimation(
|
||||
parent: _controller,
|
||||
curve: const Interval(0.0, 0.5, curve: Curves.easeOut),
|
||||
),
|
||||
);
|
||||
|
||||
_slideAnimation = Tween<Offset>(
|
||||
begin: const Offset(0, 0.1),
|
||||
end: Offset.zero,
|
||||
).animate(
|
||||
CurvedAnimation(
|
||||
parent: _controller,
|
||||
curve: const Interval(0.0, 0.5, curve: Curves.easeOut),
|
||||
),
|
||||
);
|
||||
|
||||
_controller.forward();
|
||||
}
|
||||
|
||||
@override
|
||||
void dispose() {
|
||||
_controller.dispose();
|
||||
_amountController.dispose();
|
||||
_descriptionController.dispose();
|
||||
super.dispose();
|
||||
}
|
||||
|
||||
void _showErrorSnackBar(String? message) {
|
||||
ScaffoldMessenger.of(context).showSnackBar(
|
||||
SnackBar(
|
||||
content: Text(message.toString()),
|
||||
behavior: SnackBarBehavior.floating,
|
||||
),
|
||||
);
|
||||
}
|
||||
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
return Scaffold(
|
||||
appBar: AppBar(
|
||||
title: const Text(
|
||||
'Make Payment',
|
||||
style: TextStyle(color: Colors.black87),
|
||||
),
|
||||
),
|
||||
body: Consumer<PayController>(
|
||||
builder: (context, controller, child) {
|
||||
if (controller.model.errorMessage != null) {
|
||||
WidgetsBinding.instance.addPostFrameCallback((_) {
|
||||
_showErrorSnackBar(controller.model.errorMessage);
|
||||
});
|
||||
}
|
||||
return SingleChildScrollView(
|
||||
child: Padding(
|
||||
padding: const EdgeInsets.all(16.0),
|
||||
child: FadeTransition(
|
||||
opacity: _fadeAnimation,
|
||||
child: SlideTransition(
|
||||
position: _slideAnimation,
|
||||
child: Form(
|
||||
key: _formKey,
|
||||
child: Column(
|
||||
crossAxisAlignment: CrossAxisAlignment.start,
|
||||
children: [
|
||||
SizedBox(height: 20),
|
||||
_buildBillProductSelector(controller),
|
||||
const SizedBox(height: 24),
|
||||
_buildAmountField(),
|
||||
const SizedBox(height: 24),
|
||||
_buildDescriptionField(),
|
||||
const SizedBox(height: 32),
|
||||
_buildPayButton(),
|
||||
],
|
||||
),
|
||||
),
|
||||
),
|
||||
),
|
||||
),
|
||||
);
|
||||
},
|
||||
),
|
||||
);
|
||||
}
|
||||
|
||||
Widget _buildBillProductSelector(PayController controller) {
|
||||
return Column(
|
||||
crossAxisAlignment: CrossAxisAlignment.start,
|
||||
children: [
|
||||
const Text(
|
||||
'Select Provider Product',
|
||||
style: TextStyle(fontSize: 16, fontWeight: FontWeight.w500),
|
||||
),
|
||||
const SizedBox(height: 12),
|
||||
Container(
|
||||
padding: const EdgeInsets.symmetric(horizontal: 16, vertical: 4),
|
||||
decoration: BoxDecoration(
|
||||
color: Theme.of(context).colorScheme.surface,
|
||||
borderRadius: BorderRadius.circular(12),
|
||||
border: Border.all(
|
||||
color: Theme.of(context).colorScheme.primary.withOpacity(0.2),
|
||||
),
|
||||
),
|
||||
child: DropdownButtonHideUnderline(
|
||||
child: DropdownButton<String>(
|
||||
isExpanded: true,
|
||||
icon: const Icon(Icons.arrow_drop_down),
|
||||
items: [
|
||||
...controller.model.products.map(
|
||||
(e) => DropdownMenuItem<String>(
|
||||
value: e.uid,
|
||||
child: Text(e.displayName),
|
||||
),
|
||||
),
|
||||
],
|
||||
onChanged: (String? newValue) {
|
||||
if (newValue != null) {
|
||||
setState(() {
|
||||
_selectedBillType = newValue;
|
||||
});
|
||||
}
|
||||
},
|
||||
),
|
||||
),
|
||||
),
|
||||
],
|
||||
);
|
||||
}
|
||||
|
||||
Widget _buildAmountField() {
|
||||
return Column(
|
||||
crossAxisAlignment: CrossAxisAlignment.start,
|
||||
children: [
|
||||
const Text(
|
||||
'Amount',
|
||||
style: TextStyle(fontSize: 16, fontWeight: FontWeight.w500),
|
||||
),
|
||||
const SizedBox(height: 12),
|
||||
TextFormField(
|
||||
controller: _amountController,
|
||||
keyboardType: TextInputType.number,
|
||||
decoration: const InputDecoration(
|
||||
prefixIcon: Icon(Icons.attach_money),
|
||||
hintText: 'Enter amount',
|
||||
),
|
||||
validator: (value) {
|
||||
if (value == null || value.isEmpty) {
|
||||
return 'Please enter an amount';
|
||||
}
|
||||
if (double.tryParse(value) == null) {
|
||||
return 'Please enter a valid amount';
|
||||
}
|
||||
return null;
|
||||
},
|
||||
),
|
||||
],
|
||||
);
|
||||
}
|
||||
|
||||
Widget _buildDescriptionField() {
|
||||
return Column(
|
||||
crossAxisAlignment: CrossAxisAlignment.start,
|
||||
children: [
|
||||
const Text(
|
||||
'Description',
|
||||
style: TextStyle(fontSize: 16, fontWeight: FontWeight.w500),
|
||||
),
|
||||
const SizedBox(height: 12),
|
||||
TextFormField(
|
||||
controller: _descriptionController,
|
||||
maxLines: 3,
|
||||
decoration: const InputDecoration(
|
||||
hintText: 'Enter description (optional)',
|
||||
alignLabelWithHint: true,
|
||||
),
|
||||
),
|
||||
],
|
||||
);
|
||||
}
|
||||
|
||||
Widget _buildPayButton() {
|
||||
return SizedBox(
|
||||
width: double.infinity,
|
||||
child: ElevatedButton(
|
||||
onPressed: () {
|
||||
if (_formKey.currentState!.validate()) {
|
||||
// TODO: Implement payment logic
|
||||
ScaffoldMessenger.of(context).showSnackBar(
|
||||
const SnackBar(
|
||||
content: Text('Payment processed successfully!'),
|
||||
backgroundColor: Colors.green,
|
||||
),
|
||||
);
|
||||
}
|
||||
},
|
||||
style: ElevatedButton.styleFrom(
|
||||
padding: const EdgeInsets.symmetric(vertical: 16),
|
||||
),
|
||||
child: const Text(
|
||||
'Pay Now',
|
||||
style: TextStyle(fontSize: 16, fontWeight: FontWeight.bold),
|
||||
),
|
||||
),
|
||||
);
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user