feat: fake orders
This commit is contained in:
@@ -6,6 +6,7 @@ import 'package:gymlink_module_web/components/order_confirm_item_card.dart';
|
||||
import 'package:gymlink_module_web/interfaces/items.dart';
|
||||
import 'package:gymlink_module_web/pages/order_history.dart';
|
||||
import 'package:gymlink_module_web/providers/cart.dart';
|
||||
import 'package:gymlink_module_web/tools/history.dart';
|
||||
import 'package:gymlink_module_web/tools/items.dart';
|
||||
import 'package:gymlink_module_web/tools/prefs.dart';
|
||||
import 'package:gymlink_module_web/tools/routes.dart';
|
||||
@@ -64,6 +65,9 @@ class _OrderConfirmationPageState extends State<OrderConfirmationPage> {
|
||||
List<GymItem> gymCart = [];
|
||||
bool isAgree = false;
|
||||
bool _isLoading = true;
|
||||
final _emailController = TextEditingController();
|
||||
final _addressController = TextEditingController();
|
||||
final _nameController = TextEditingController();
|
||||
|
||||
@override
|
||||
void initState() {
|
||||
@@ -93,6 +97,65 @@ class _OrderConfirmationPageState extends State<OrderConfirmationPage> {
|
||||
}
|
||||
}
|
||||
|
||||
bool _checkInputs() {
|
||||
final email = _emailController.text;
|
||||
final address = _addressController.text;
|
||||
final name = _nameController.text;
|
||||
|
||||
if (!RegExp(r"^((?!\.)[\w\-_.]*[^.])(@\w+)(\.\w+(\.\w+)?[^.\W])$")
|
||||
.hasMatch(email)) {
|
||||
showDialog(
|
||||
context: context,
|
||||
builder: (context) => AlertDialog(
|
||||
title: const Text('Ошибка'),
|
||||
content: const Text('Некорректный email'),
|
||||
actions: [
|
||||
TextButton(
|
||||
onPressed: () => Navigator.pop(context),
|
||||
child: const Text('ОК'),
|
||||
)
|
||||
],
|
||||
),
|
||||
);
|
||||
return false;
|
||||
}
|
||||
|
||||
if (address.isEmpty) {
|
||||
showDialog(
|
||||
context: context,
|
||||
builder: (context) => AlertDialog(
|
||||
title: const Text('Ошибка'),
|
||||
content: const Text('Адрес не может быть пустым'),
|
||||
actions: [
|
||||
TextButton(
|
||||
onPressed: () => Navigator.pop(context),
|
||||
child: const Text('ОК'),
|
||||
)
|
||||
],
|
||||
),
|
||||
);
|
||||
return false;
|
||||
}
|
||||
|
||||
if (name.isEmpty) {
|
||||
showDialog(
|
||||
context: context,
|
||||
builder: (context) => AlertDialog(
|
||||
title: const Text('Ошибка'),
|
||||
content: const Text('ФИО не может быть пустым'),
|
||||
actions: [
|
||||
TextButton(
|
||||
onPressed: () => Navigator.pop(context),
|
||||
child: const Text('ОК'),
|
||||
)
|
||||
],
|
||||
),
|
||||
);
|
||||
return false;
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
return Scaffold(
|
||||
@@ -148,6 +211,7 @@ class _OrderConfirmationPageState extends State<OrderConfirmationPage> {
|
||||
data: '## Итого: ${totalPrice.toStringAsFixed(2)} руб.'),
|
||||
Expanded(
|
||||
child: TextField(
|
||||
controller: _addressController,
|
||||
decoration: InputDecoration(
|
||||
hintText: 'Адрес доставки',
|
||||
border: OutlineInputBorder(
|
||||
@@ -158,6 +222,7 @@ class _OrderConfirmationPageState extends State<OrderConfirmationPage> {
|
||||
),
|
||||
Expanded(
|
||||
child: TextField(
|
||||
controller: _emailController,
|
||||
decoration: InputDecoration(
|
||||
hintText: 'Электронная почта',
|
||||
border: OutlineInputBorder(
|
||||
@@ -169,6 +234,7 @@ class _OrderConfirmationPageState extends State<OrderConfirmationPage> {
|
||||
),
|
||||
Expanded(
|
||||
child: TextField(
|
||||
controller: _nameController,
|
||||
decoration: InputDecoration(
|
||||
hintText: 'Получатель',
|
||||
border: OutlineInputBorder(
|
||||
@@ -179,8 +245,15 @@ class _OrderConfirmationPageState extends State<OrderConfirmationPage> {
|
||||
),
|
||||
ElevatedButton(
|
||||
onPressed: () async {
|
||||
if (!_checkInputs()) return;
|
||||
_goToPage();
|
||||
await clearCart();
|
||||
await addToHistory(GymHistoryItem(
|
||||
id: '123',
|
||||
date: '01.01.1970',
|
||||
sum: '123',
|
||||
photo: 'product.png',
|
||||
));
|
||||
Provider.of<CartProvider>(context, listen: false)
|
||||
.updateCartLength();
|
||||
Navigator.of(context).pushAndRemoveUntil(
|
||||
|
||||
Reference in New Issue
Block a user