fix: order info page

This commit is contained in:
2024-06-17 16:59:10 +03:00
parent 0a22b5c051
commit fb5538ab79
2 changed files with 172 additions and 43 deletions

View File

@@ -186,7 +186,7 @@ class GymHistoryItemDetail {
final String id; final String id;
final String date; final String date;
final String sum; final String sum;
final String payUrl; String? payUrl;
final String receiver; final String receiver;
final String email; final String email;
final String address; final String address;
@@ -196,7 +196,7 @@ class GymHistoryItemDetail {
required this.id, required this.id,
required this.date, required this.date,
required this.sum, required this.sum,
required this.payUrl, this.payUrl,
required this.providers, required this.providers,
required this.receiver, required this.receiver,
required this.email, required this.email,

View File

@@ -1,15 +1,19 @@
import 'dart:async';
import 'package:flutter/foundation.dart';
import 'package:flutter/material.dart'; import 'package:flutter/material.dart';
import 'package:flutter_markdown/flutter_markdown.dart'; import 'package:flutter_markdown/flutter_markdown.dart';
import 'package:gymlink_module_web/components/app_bar.dart'; import 'package:gymlink_module_web/components/app_bar.dart';
import 'package:gymlink_module_web/components/heading.dart'; import 'package:gymlink_module_web/components/heading.dart';
import 'package:gymlink_module_web/components/order_detail_item_card.dart';
import 'package:gymlink_module_web/interfaces/items.dart'; import 'package:gymlink_module_web/interfaces/items.dart';
import 'package:lazy_load_scrollview/lazy_load_scrollview.dart'; import 'package:url_launcher/url_launcher.dart';
final GymHistoryItemDetail item = GymHistoryItemDetail.fromJson({ final GymHistoryItemDetail item = GymHistoryItemDetail.fromJson({
"id": "12345", "id": "12345",
"date": "01.01.1970", "date": "01.01.1970",
"sum": "45000", "sum": "45000",
"pay_url": "url", "pay_url": "https://example.org",
"receiver": "Иванов Иван Иванович", "receiver": "Иванов Иван Иванович",
"email": "a@a.ru", "email": "a@a.ru",
"address": "г. Москва, ул. Пушкина, д. 17", "address": "г. Москва, ул. Пушкина, д. 17",
@@ -46,17 +50,37 @@ class OrderInfoPage extends StatefulWidget {
class _OrderInfoPageState extends State<OrderInfoPage> { class _OrderInfoPageState extends State<OrderInfoPage> {
GymHistoryItemDetail? detail; GymHistoryItemDetail? detail;
final _scrollController = ScrollController(); final _scrollController = ScrollController();
late Timer _updateTimer;
@override @override
void initState() { void initState() {
super.initState(); super.initState();
setState(() { _updateTimer = Timer.periodic(const Duration(minutes: 1), _onRefresh);
detail = item; _onRefresh(_updateTimer);
});
debugPrint("AAAAAAAAAAAA${detail?.toRawJson()}");
} }
Future<void> _onRefresh() { @override
return Future.delayed(const Duration(milliseconds: 1000)); void dispose() {
_updateTimer.cancel();
super.dispose();
}
Future<void> _onRefresh(Timer timer) async {
return Future.delayed(const Duration(milliseconds: 1000), () {
setState(() {
detail = item;
});
});
}
Future<void> _goToPage() async {
if (detail?.payUrl != null) {
final Uri url = Uri.parse(detail?.payUrl ?? 'example.org');
detail!.payUrl = null;
if (!await launchUrl(url, webOnlyWindowName: '_blank')) {
throw 'Could not launch $url';
}
_onRefresh(_updateTimer);
}
} }
Widget _buildContent() { Widget _buildContent() {
@@ -64,47 +88,152 @@ class _OrderInfoPageState extends State<OrderInfoPage> {
children: [ children: [
GymLinkHeader(title: "Заказ #${detail?.id} от ${detail?.date}"), GymLinkHeader(title: "Заказ #${detail?.id} от ${detail?.date}"),
Expanded( Expanded(
child: LazyLoadScrollView( child: RefreshIndicator(
onEndOfPage: _onRefresh, onRefresh: () => _onRefresh(_updateTimer),
child: Scrollbar( edgeOffset: 55,
controller: _scrollController, child: Scrollbar(
child: ListView( controller: _scrollController,
controller: _scrollController, child: ListView(
children: [ controller: _scrollController,
ListView.builder( children: [
itemCount: 3, const SizedBox(height: 10),
physics: const NeverScrollableScrollPhysics(), kIsWeb
shrinkWrap: true, ? Center(
itemBuilder: (context, index) { child: ElevatedButton(
final provider = detail!.providers[0]; onPressed: () => _onRefresh(_updateTimer),
return const Card( style: ElevatedButton.styleFrom(
child: Text('test'), backgroundColor: Theme.of(context).primaryColor,
); shape: const RoundedRectangleBorder(
}, borderRadius:
), BorderRadius.all(Radius.circular(50)),
Expanded( ),
child: Card( foregroundColor: Colors.white,
elevation: 4, fixedSize: const Size(180, 40),
child: Padding( ),
padding: const EdgeInsetsDirectional.symmetric( child: const Row(
horizontal: 10, vertical: 20),
child: Column(
mainAxisSize: MainAxisSize.min, mainAxisSize: MainAxisSize.min,
children: [ children: [
MarkdownBody( Text('Обновить'),
data: Spacer(),
"### Адрес получателя: _${detail!.address}_"), Icon(Icons.refresh),
Markdown(data: '### Почта: _${detail!.email}_'), Spacer()
// Markdown(
// data: '### ФИО: _${detail!.receiver}_'),
], ],
), ),
), ),
)
: const SizedBox.shrink(),
const SizedBox(height: 10),
ListView.builder(
itemCount: 3,
physics: const NeverScrollableScrollPhysics(),
shrinkWrap: true,
itemBuilder: (context, index) {
final provider = detail!.providers[0];
return Padding(
padding: const EdgeInsetsDirectional.symmetric(
vertical: 10,
horizontal: 5,
),
child: Card(
elevation: 3,
child: Column(
children: [
MarkdownBody(data: '# ${provider.name}'),
MarkdownBody(
data: '## Статус: ${provider.status}'),
const MarkdownBody(data: '### Состав:'),
for (final item in provider.items)
OrderDetailCardItemCard(
image: FutureBuilder(
future: precacheImage(
const AssetImage('assets/product.png'),
context),
builder: (context, snapshot) {
if (snapshot.connectionState ==
ConnectionState.done) {
return const Image(
image:
AssetImage('assets/product.png'),
width: 50,
);
} else {
return const CircularProgressIndicator();
}
},
),
name: 'Протеин',
count: item.count,
price: double.parse(item.price),
),
],
),
),
);
},
),
const SizedBox(
height: 10,
),
SizedBox(
height: 200,
child: Padding(
padding: const EdgeInsetsDirectional.symmetric(
horizontal: 5,
),
child: Card(
elevation: 4,
child: Padding(
padding: const EdgeInsetsDirectional.symmetric(
horizontal: 10, vertical: 20),
child: Column(
// mainAxisSize: MainAxisSize.min,
mainAxisAlignment: MainAxisAlignment.spaceBetween,
// crossAxisAlignment: CrossAxisAlignment.start,
children: [
Column(
crossAxisAlignment: CrossAxisAlignment.start,
children: [
MarkdownBody(
data:
"### Адрес получателя: __${detail!.address}__"),
MarkdownBody(
data: '### Почта: __${detail!.email}__'),
MarkdownBody(
data: '### ФИО: _${detail!.receiver}_'),
],
),
detail?.payUrl == null
? const SizedBox.shrink()
: Center(
child: ElevatedButton(
onPressed: () async {
await _goToPage();
debugPrint('clicked');
},
style: ElevatedButton.styleFrom(
backgroundColor:
Theme.of(context).primaryColor,
shape: const RoundedRectangleBorder(
borderRadius: BorderRadius.all(
Radius.circular(50)),
),
foregroundColor: Colors.white,
fixedSize: const Size(180, 40),
),
child: const Text('Оплатить заказ'),
),
),
],
),
), ),
), ),
], ),
), ),
))), ],
),
),
),
),
], ],
); );
} }