Untitled
unknown
plain_text
3 years ago
18 kB
10
Indexable
import 'package:flutter/material.dart';
import 'cart.dart';
import 'package:fluttertoast/fluttertoast.dart';
import 'package:flutter/services.dart';
class PaymentPage extends StatefulWidget {
@override
_PaymentPageState createState() => _PaymentPageState();
}
class PaymentSuccessPage extends StatelessWidget {
@override
Widget build(BuildContext context) {
return Scaffold(
appBar: AppBar(
title: Text('Pembayaran Berhasil'),
),
body: SingleChildScrollView(
child: Center(
child: Column(
mainAxisAlignment: MainAxisAlignment.center,
children: [
Text('Pembayaran telah berhasil.'),
SizedBox(height: 20.0),
ElevatedButton(
onPressed: () {
Navigator.popUntil(context, ModalRoute.withName('/'));
},
child: Text('Kembali'),
),
],
),
),
),
);
}
}
class _PaymentPageState extends State<PaymentPage> {
String selectedPaymentMethod = '';
TextEditingController phoneNumberController = TextEditingController();
TextEditingController accountNumberController = TextEditingController();
void selectPaymentMethod(String paymentMethod) {
setState(() {
selectedPaymentMethod = paymentMethod;
});
}
void pay() {
showDialog(
context: context,
builder: (BuildContext context) {
return AlertDialog(
title: Text('Pembayaran Berhasil'),
content: Text('Pembayaran telah berhasil.'),
actions: [
TextButton(
child: Text('OK'),
onPressed: () {
Navigator.pushAndRemoveUntil(
context,
MaterialPageRoute(builder: (context) => CartPage()),
(Route<dynamic> route) => false,
);
},
),
],
);
},
);
}
bool confirmed = false;
bool isNumeric(String? value) {
if (value == null || value.isEmpty) {
return false;
}
final numericRegex = RegExp(r'^[0-9]+$');
return numericRegex.hasMatch(value);
}
showEWalletDialog() {
showDialog(
context: context,
builder: (BuildContext context) {
return AlertDialog(
title: Text('Pembayaran Menggunakan E-Wallet'),
content: Column(
mainAxisSize: MainAxisSize.min,
children: [
TextFormField(
controller: phoneNumberController,
keyboardType: TextInputType.phone,
decoration: InputDecoration(
labelText: 'Nomor Telepon',
hintText: 'Masukkan nomor telepon yang terdaftar di E-Wallet',
),
onChanged: (value) {
// Tambahkan logika atau perubahan yang ingin Anda lakukan saat input berubah
},
validator: (value) {
if (value == null || value.isEmpty) {
return 'Nomor telepon tidak boleh kosong';
} else if (!isNumeric(value)) {
return 'Nomor telepon harus berupa angka';
}
return null;
},
inputFormatters: [FilteringTextInputFormatter.digitsOnly],
),
],
),
actions: [
TextButton(
child: Text('Batal'),
onPressed: () {
Navigator.pop(context);
},
style: ButtonStyle(
backgroundColor: MaterialStateProperty.all<Color>(Colors.green),
),
),
TextButton(
child: Text('Bayar'),
onPressed: () {
if (phoneNumberController.text == null ||
phoneNumberController.text.isEmpty) {
showDialog(
context: context,
builder: (BuildContext context) {
return AlertDialog(
title: Text('Error'),
content: Text('Nomor telepon tidak boleh kosong'),
actions: [
TextButton(
child: Text('OK'),
onPressed: () {
Navigator.pop(context);
},
),
],
);
},
);
} else if (!isNumeric(phoneNumberController.text)) {
showDialog(
context: context,
builder: (BuildContext context) {
return AlertDialog(
title: Text('Error'),
content: Text('Nomor telepon harus berupa angka'),
actions: [
TextButton(
child: Text('OK'),
onPressed: () {
Navigator.pop(context);
},
),
],
);
},
);
} else {
// Set confirmed to true when the user confirms the payment
confirmed = true;
Navigator.pop(context);
}
},
style: ButtonStyle(
backgroundColor: MaterialStateProperty.all<Color>(Colors.green),
),
),
],
);
},
);
}
void showBankDialog() {
showDialog(
context: context,
builder: (BuildContext context) {
return AlertDialog(
title: Text('Pembayaran Menggunakan Bank'),
content: Column(
mainAxisSize: MainAxisSize.min,
children: [
DropdownButtonFormField(
value: null,
decoration: InputDecoration(
labelText: 'Bank',
hintText: 'Pilih Bank',
),
items: [
DropdownMenuItem(
value: 'Mandiri',
child: Text('Mandiri'),
),
DropdownMenuItem(
value: 'BRI',
child: Text('BRI'),
),
// Tambahkan opsi untuk bank lainnya
],
onChanged: (value) {},
),
TextFormField(
controller: accountNumberController,
keyboardType: TextInputType.number,
decoration: InputDecoration(
labelText: 'Nomor Rekening',
hintText: 'Masukkan nomor rekening Anda',
),
),
],
),
actions: [
TextButton(
child: Text('Batal'),
onPressed: () {
Navigator.pop(context);
},
style: ButtonStyle(
backgroundColor: MaterialStateProperty.all<Color>(Colors.green),
),
),
TextButton(
child: Text('Bayar'),
onPressed: () {
// Lakukan pembayaran menggunakan Bank
pay();
Navigator.pop(context);
},
),
],
);
},
);
}
@override
Widget build(BuildContext context) {
return Scaffold(
appBar: AppBar(
title: Text('Pembayaran'),
backgroundColor: Colors.green,
),
body: Column(
mainAxisAlignment: MainAxisAlignment.center,
children: [
Text(
'Pilih Metode Pembayaran',
style: TextStyle(
fontSize: 24.0,
fontWeight: FontWeight.bold,
),
),
SizedBox(height: 20.0),
Row(
mainAxisAlignment: MainAxisAlignment.center,
children: [
InkWell(
onTap: () {
selectPaymentMethod('E-Wallet');
Navigator.push(
context,
MaterialPageRoute(builder: (context) => EWalletPage()),
);
},
child: Container(
width: 150.0,
height: 150.0,
color: selectedPaymentMethod == 'E-Wallet'
? Colors.green
: Colors.grey[300],
child: Column(
mainAxisAlignment: MainAxisAlignment.center,
children: [
Icon(
Icons.account_balance_wallet,
size: 64.0,
),
SizedBox(height: 10.0),
Text(
'E-Wallet',
style: TextStyle(
fontSize: 20.0,
fontWeight: FontWeight.bold,
),
),
],
),
),
),
SizedBox(width: 20.0),
InkWell(
onTap: () {
selectPaymentMethod('Bank');
Navigator.push(
context,
MaterialPageRoute(builder: (context) => BankPage()),
);
},
child: Container(
width: 150.0,
height: 150.0,
color: selectedPaymentMethod == 'Bank'
? Colors.green
: Colors.grey[300],
child: Column(
mainAxisAlignment: MainAxisAlignment.center,
children: [
Icon(
Icons.account_balance,
size: 64.0,
),
SizedBox(height: 10.0),
Text(
'Bank',
style: TextStyle(
fontSize: 20.0,
fontWeight: FontWeight.bold,
),
),
],
),
),
),
],
),
SizedBox(height: 20.0),
ElevatedButton(
child: Text('Bayar'),
onPressed: selectedPaymentMethod != ''
? () {
pay();
}
: null,
),
],
),
);
}
}
class EWalletPage extends StatefulWidget {
@override
_EWalletPageState createState() => _EWalletPageState();
}
class _EWalletPageState extends State<EWalletPage> {
TextEditingController phoneController = TextEditingController();
bool isPaymentConfirmed = false;
void confirmPayment() {
setState(() {
isPaymentConfirmed = true;
});
void _processPayment() {
// lakukan proses pembayaran
bool isSuccess = true; // hasil pembayaran berhasil atau tidak
if (isSuccess) {
Navigator.pushAndRemoveUntil(
context,
MaterialPageRoute(builder: (context) => PaymentSuccessPage()),
(Route<dynamic> route) => false,
);
}
}
}
@override
Widget build(BuildContext context) {
return Scaffold(
appBar: AppBar(
title: Text('Pembayaran E-Wallet'),
),
body: isPaymentConfirmed
? Container(
alignment: Alignment.center,
child: Column(
mainAxisAlignment: MainAxisAlignment.center,
children: [
Icon(
Icons.check_circle,
color: Colors.green,
size: 64.0,
),
SizedBox(height: 10.0),
Text(
'Pembayaran Berhasil',
style: TextStyle(
fontSize: 20.0,
fontWeight: FontWeight.bold,
),
),
],
),
)
: Padding(
padding: const EdgeInsets.all(20.0),
child: Column(
children: [
TextFormField(
controller: phoneController,
keyboardType: TextInputType.phone,
decoration: InputDecoration(
hintText: 'Masukkan Nomor Telepon',
),
),
SizedBox(height: 20.0),
ElevatedButton(
child: Text('Konfirmasi Pembayaran'),
onPressed: () {
confirmPayment();
},
style: ButtonStyle(
backgroundColor:
MaterialStateProperty.all<Color>(Colors.green),
),
),
],
),
),
);
}
}
class BankPage extends StatefulWidget {
const BankPage({Key? key}) : super(key: key);
@override
_BankPageState createState() => _BankPageState();
}
class _BankPageState extends State<BankPage> {
String _selectedBank = '';
String bankAccountNumber = '';
void selectBank(String bank) {
setState(() {
_selectedBank = bank;
});
}
void payWithBank() {
Fluttertoast.showToast(
msg: 'Pembayaran dengan $_selectedBank sukses!',
toastLength: Toast.LENGTH_SHORT,
gravity: ToastGravity.BOTTOM,
timeInSecForIosWeb: 1,
backgroundColor: Colors.green,
textColor: Colors.white,
fontSize: 16.0,
);
Navigator.pushAndRemoveUntil(
context,
MaterialPageRoute(builder: (context) => PaymentSuccessPage()),
(Route<dynamic> route) => false,
);
}
@override
Widget build(BuildContext context) {
return Scaffold(
appBar: AppBar(
title: Text('Pilih Bank'),
backgroundColor: Colors.green,
),
body: SingleChildScrollView(
child: Column(
mainAxisAlignment: MainAxisAlignment.center,
children: [
Text(
'Pilih Bank',
style: TextStyle(
fontSize: 24.0,
fontWeight: FontWeight.bold,
),
),
SizedBox(height: 20.0),
Row(
mainAxisAlignment: MainAxisAlignment.center,
children: [
InkWell(
onTap: () {
selectBank('Mandiri');
},
child: Container(
width: 150.0,
height: 150.0,
color: _selectedBank == 'Bank Mandiri' ? Colors.green : Colors.grey[300],
child: Column(
mainAxisAlignment: MainAxisAlignment.center,
children: [
Image.asset(
'assets/mandiri.png',
width: 70.0,
height: 70.0,
),
SizedBox(height: 10.0),
Text(
'Mandiri',
style: TextStyle(
fontSize: 20.0,
fontWeight: FontWeight.bold,
),
),
],
),
),
),
SizedBox(width: 20.0),
InkWell(
onTap: () {
selectBank('BNI');
},
child: Container(
width: 150.0,
height: 150.0,
color: _selectedBank == 'Bank BNI' ? Colors.green : Colors.grey[300],
child: Column(
mainAxisAlignment: MainAxisAlignment.center,
children: [
Image.asset(
'assets/bni.png',
width: 70.0,
height: 70.0,
),
SizedBox(height: 10.0),
Text(
'BNI',
style: TextStyle(
fontSize: 20.0,
fontWeight: FontWeight.bold,
),
),
],
),
),
),
SizedBox(width: 20.0),
InkWell(
onTap: () {
selectBank('BRI');
},
child: Container(
width: 150.0,
height: 150.0,
color: _selectedBank == 'Bank BRI' ? Colors.green : Colors.grey[300],
child: Column(
mainAxisAlignment: MainAxisAlignment.center,
children: [
Image.asset(
'assets/bri.png',
width: 70.0,
height: 70.0,
),
SizedBox(height: 10.0),
Text(
'BRI',
style: TextStyle(
fontSize: 20.0,
fontWeight: FontWeight.bold,
),
),
],
),
),
),
],
),
],
),
),
);
}
}Editor is loading...