Swipe_Button_on_quick_pay

This commit is contained in:
2025-05-27 17:58:56 +05:30
parent 47fcb0e287
commit 3f71a32c04
12 changed files with 187 additions and 157 deletions

View File

@@ -9,8 +9,9 @@ class AccountStatementScreen extends StatefulWidget {
}
class _AccountStatementScreen extends State<AccountStatementScreen>{
DateTimeRange? selectedDateRange;
final _amountRangeController = TextEditingController(text: "100-500");
DateTime? fromDate;
DateTime? toDate;
final _amountRangeController = TextEditingController(text: "");
final transactions = [
{"desc": "Transfer From ICICI Bank subsidy", "amount": "+₹133.98", "type": "Cr", "time": "21-02-2024 13:09:30"},
{"desc": "Mobile recharge", "amount": "-₹299.00", "type": "Dr", "time": "21-02-2024 13:09:30"},
@@ -21,20 +22,32 @@ class _AccountStatementScreen extends State<AccountStatementScreen>{
{"desc": "Transfer From ICICI Bank subsidy", "amount": "+₹100.00", "type": "Cr", "time": "21-02-2024 13:09:30"},
];
Future<void> _selectDateRange(BuildContext context) async {
final DateTime now = DateTime.now();
void _selectDate({required bool isFromDate}) async {
final DateTime initial = isFromDate ? fromDate ?? DateTime.now() : toDate ?? fromDate ?? DateTime.now();
final DateTimeRange? picked = await showDateRangePicker(
final DateTime? picked = await showDatePicker(
context: context,
initialDate: initial,
firstDate: DateTime(2023),
lastDate: now, // disables future dates
initialDateRange: selectedDateRange ??
DateTimeRange(start: now.subtract(const Duration(days: 7)), end: now),
lastDate: DateTime(2030),
);
if (picked != null) {
setState(() {
selectedDateRange = picked;
if (isFromDate) {
fromDate = picked;
if (toDate != null && toDate!.isBefore(fromDate!)) {
toDate = null; // reset invalid toDate
}
} else {
if (fromDate != null && picked.isBefore(fromDate!)) {
ScaffoldMessenger.of(context).showSnackBar(const SnackBar(
content: Text("To Date cannot be before From Date"),
));
} else {
toDate = picked;
}
}
});
}
}
@@ -82,11 +95,13 @@ class _AccountStatementScreen extends State<AccountStatementScreen>{
const SizedBox(height: 15,),
Row(
children: [
Expanded(child: _buildDateRangeSelector()),
Expanded(child: _buildFromDateSelector()),
const SizedBox(width: 10),
Expanded(child: _buildFilterBox("100-500")),
Expanded(child: _buildToDateSelector()),
],
),
const SizedBox(height: 20),
_buildFilterBox(""),
const SizedBox(height: 35),
Expanded(
child: ListView.builder(
@@ -104,16 +119,9 @@ class _AccountStatementScreen extends State<AccountStatementScreen>{
);
}
Widget _buildDateRangeSelector() {
String label = "Select Date";
if (selectedDateRange != null) {
final from = _formatDate(selectedDateRange!.start);
final to = _formatDate(selectedDateRange!.end);
label = "$from - $to";
}
Widget _buildFromDateSelector() {
return GestureDetector(
onTap: () => _selectDateRange(context),
onTap: () => _selectDate(isFromDate: true),
child: Container(
padding: const EdgeInsets.symmetric(horizontal: 12, vertical: 14),
decoration: BoxDecoration(
@@ -122,8 +130,37 @@ class _AccountStatementScreen extends State<AccountStatementScreen>{
),
child: Row(
children: [
Expanded(child: Text(label, style: const TextStyle(fontSize: 16))),
const Icon(Icons.calendar_today),
Expanded(
child: Text(
fromDate != null ? _formatDate(fromDate!) : "From Date",
style: const TextStyle(fontSize: 16),
),
),
const Icon(Icons.arrow_drop_down),
],
),
),
);
}
Widget _buildToDateSelector() {
return GestureDetector(
onTap: () => _selectDate(isFromDate: false),
child: Container(
padding: const EdgeInsets.symmetric(horizontal: 12, vertical: 14),
decoration: BoxDecoration(
border: Border.all(color: Colors.grey),
borderRadius: BorderRadius.circular(8),
),
child: Row(
children: [
Expanded(
child: Text(
toDate != null ? _formatDate(toDate!) : "To Date",
style: const TextStyle(fontSize: 16),
),
),
const Icon(Icons.arrow_drop_down),
],
),
),

View File

@@ -1,4 +1,5 @@
import 'package:flutter/material.dart';
import 'package:flutter_swipe_button/flutter_swipe_button.dart';
import 'package:material_symbols_icons/material_symbols_icons.dart';
class QuickPayOutsideBankScreen extends StatefulWidget {
@@ -300,16 +301,20 @@ class _QuickPayOutsideBankScreen extends State<QuickPayOutsideBankScreen> {
const SizedBox(height: 45),
Align(
alignment: Alignment.center,
child: SizedBox(
width: 250,
child: ElevatedButton(
style: ElevatedButton.styleFrom(
shape: const StadiumBorder(),
padding: const EdgeInsets.symmetric(vertical: 16),
backgroundColor: Colors.blue[900],
foregroundColor: Colors.white,
child: SwipeButton.expand(
thumb: const Icon(
Icons.arrow_forward,
color: Colors.white,
),
onPressed: () {
activeThumbColor: Colors.blue[900],
activeTrackColor: Colors.blue.shade100,
borderRadius: BorderRadius.circular(30),
height: 56,
child: const Text(
"Swipe to Pay",
style: TextStyle(fontSize: 16, fontWeight: FontWeight.bold),
),
onSwipe: () {
if (_formKey.currentState!.validate()) {
// Perform payment logic
final selectedMode = transactionModes[selectedTransactionIndex];
@@ -318,9 +323,8 @@ class _QuickPayOutsideBankScreen extends State<QuickPayOutsideBankScreen> {
);
}
},
child: const Text('Pay'),
),
),
)
),
],
),

View File

@@ -1,4 +1,5 @@
import 'package:flutter/material.dart';
import 'package:flutter_swipe_button/flutter_swipe_button.dart';
import 'package:material_symbols_icons/material_symbols_icons.dart';
class QuickPayWithinBankScreen extends StatefulWidget {
@@ -149,27 +150,28 @@ class _QuickPayWithinBankScreen extends State<QuickPayWithinBankScreen> {
const SizedBox(height: 45),
Align(
alignment: Alignment.center,
child: SizedBox(
width: 250,
height: 50,
child: ElevatedButton(
style: ElevatedButton.styleFrom(
shape: const StadiumBorder(),
padding: const EdgeInsets.symmetric(vertical: 16),
backgroundColor: Colors.blue[900],
foregroundColor: Colors.white,
),
onPressed: () {
if (_formKey.currentState!.validate()) {
// Perform payment logic
ScaffoldMessenger.of(context).showSnackBar(
const SnackBar(
content: Text('Processing Payment...')),
);
}
},
child: const Text('Pay'),
child: SwipeButton.expand(
thumb: const Icon(
Icons.arrow_forward,
color: Colors.white,
),
activeThumbColor: Colors.blue[900],
activeTrackColor: Colors.blue.shade100,
borderRadius: BorderRadius.circular(30),
height: 56,
child: const Text(
"Swipe to Pay",
style: TextStyle(fontSize: 16, fontWeight: FontWeight.bold),
),
onSwipe: () {
if (_formKey.currentState!.validate()) {
// Perform payment logic
ScaffoldMessenger.of(context).showSnackBar(
const SnackBar(
content: Text('Processing Payment...')),
);
}
},
),
),
],