fix: order info page
This commit is contained in:
@@ -186,7 +186,7 @@ class GymHistoryItemDetail {
|
||||
final String id;
|
||||
final String date;
|
||||
final String sum;
|
||||
final String payUrl;
|
||||
String? payUrl;
|
||||
final String receiver;
|
||||
final String email;
|
||||
final String address;
|
||||
@@ -196,7 +196,7 @@ class GymHistoryItemDetail {
|
||||
required this.id,
|
||||
required this.date,
|
||||
required this.sum,
|
||||
required this.payUrl,
|
||||
this.payUrl,
|
||||
required this.providers,
|
||||
required this.receiver,
|
||||
required this.email,
|
||||
|
||||
@@ -1,15 +1,19 @@
|
||||
import 'dart:async';
|
||||
|
||||
import 'package:flutter/foundation.dart';
|
||||
import 'package:flutter/material.dart';
|
||||
import 'package:flutter_markdown/flutter_markdown.dart';
|
||||
import 'package:gymlink_module_web/components/app_bar.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:lazy_load_scrollview/lazy_load_scrollview.dart';
|
||||
import 'package:url_launcher/url_launcher.dart';
|
||||
|
||||
final GymHistoryItemDetail item = GymHistoryItemDetail.fromJson({
|
||||
"id": "12345",
|
||||
"date": "01.01.1970",
|
||||
"sum": "45000",
|
||||
"pay_url": "url",
|
||||
"pay_url": "https://example.org",
|
||||
"receiver": "Иванов Иван Иванович",
|
||||
"email": "a@a.ru",
|
||||
"address": "г. Москва, ул. Пушкина, д. 17",
|
||||
@@ -46,17 +50,37 @@ class OrderInfoPage extends StatefulWidget {
|
||||
class _OrderInfoPageState extends State<OrderInfoPage> {
|
||||
GymHistoryItemDetail? detail;
|
||||
final _scrollController = ScrollController();
|
||||
late Timer _updateTimer;
|
||||
@override
|
||||
void initState() {
|
||||
super.initState();
|
||||
_updateTimer = Timer.periodic(const Duration(minutes: 1), _onRefresh);
|
||||
_onRefresh(_updateTimer);
|
||||
}
|
||||
|
||||
@override
|
||||
void dispose() {
|
||||
_updateTimer.cancel();
|
||||
super.dispose();
|
||||
}
|
||||
|
||||
Future<void> _onRefresh(Timer timer) async {
|
||||
return Future.delayed(const Duration(milliseconds: 1000), () {
|
||||
setState(() {
|
||||
detail = item;
|
||||
});
|
||||
debugPrint("AAAAAAAAAAAA${detail?.toRawJson()}");
|
||||
});
|
||||
}
|
||||
|
||||
Future<void> _onRefresh() {
|
||||
return Future.delayed(const Duration(milliseconds: 1000));
|
||||
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() {
|
||||
@@ -64,47 +88,152 @@ class _OrderInfoPageState extends State<OrderInfoPage> {
|
||||
children: [
|
||||
GymLinkHeader(title: "Заказ #${detail?.id} от ${detail?.date}"),
|
||||
Expanded(
|
||||
child: LazyLoadScrollView(
|
||||
onEndOfPage: _onRefresh,
|
||||
child: RefreshIndicator(
|
||||
onRefresh: () => _onRefresh(_updateTimer),
|
||||
edgeOffset: 55,
|
||||
child: Scrollbar(
|
||||
controller: _scrollController,
|
||||
child: ListView(
|
||||
controller: _scrollController,
|
||||
children: [
|
||||
const SizedBox(height: 10),
|
||||
kIsWeb
|
||||
? Center(
|
||||
child: ElevatedButton(
|
||||
onPressed: () => _onRefresh(_updateTimer),
|
||||
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 Row(
|
||||
mainAxisSize: MainAxisSize.min,
|
||||
children: [
|
||||
Text('Обновить'),
|
||||
Spacer(),
|
||||
Icon(Icons.refresh),
|
||||
Spacer()
|
||||
],
|
||||
),
|
||||
),
|
||||
)
|
||||
: 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 const Card(
|
||||
child: Text('test'),
|
||||
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),
|
||||
),
|
||||
],
|
||||
),
|
||||
),
|
||||
);
|
||||
},
|
||||
),
|
||||
Expanded(
|
||||
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,
|
||||
// mainAxisSize: MainAxisSize.min,
|
||||
mainAxisAlignment: MainAxisAlignment.spaceBetween,
|
||||
// crossAxisAlignment: CrossAxisAlignment.start,
|
||||
children: [
|
||||
Column(
|
||||
crossAxisAlignment: CrossAxisAlignment.start,
|
||||
children: [
|
||||
MarkdownBody(
|
||||
data:
|
||||
"### Адрес получателя: _${detail!.address}_"),
|
||||
Markdown(data: '### Почта: _${detail!.email}_'),
|
||||
// Markdown(
|
||||
// data: '### ФИО: _${detail!.receiver}_'),
|
||||
"### Адрес получателя: __${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('Оплатить заказ'),
|
||||
),
|
||||
),
|
||||
],
|
||||
),
|
||||
),
|
||||
),
|
||||
),
|
||||
),
|
||||
],
|
||||
),
|
||||
))),
|
||||
),
|
||||
),
|
||||
),
|
||||
],
|
||||
);
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user