course-work/lib/ui/orderspage.dart

93 lines
2.9 KiB
Dart
Raw Normal View History

import 'package:cubit_form/cubit_form.dart';
import 'package:flutter/material.dart';
2022-12-27 06:11:02 +00:00
import 'package:selfprivacy/logic/courierscubit.dart';
2022-12-27 09:09:00 +00:00
import 'package:selfprivacy/logic/orderformcubit.dart';
2022-12-27 05:29:50 +00:00
import 'package:selfprivacy/logic/orderscubit.dart';
2022-12-27 06:11:02 +00:00
import 'package:selfprivacy/models/courier.dart';
import 'package:selfprivacy/models/item.dart';
import 'package:selfprivacy/models/order.dart';
2022-12-27 09:09:00 +00:00
import 'package:selfprivacy/ui/bottomsheet.dart';
import 'package:selfprivacy/ui/button.dart';
part 'order.dart';
2022-12-27 09:09:00 +00:00
part 'ordersdetails.dart';
class OrdersPage extends StatelessWidget {
const OrdersPage({super.key});
@override
Widget build(final BuildContext context) {
final Widget child = BlocBuilder<OrdersCubit, OrdersState>(
builder: (final BuildContext context, final OrdersState state) {
final List<Order> orders = state.orders;
if (orders.isEmpty) {
if (state.isLoading) {
return const Center(
child: CircularProgressIndicator(),
);
}
return RefreshIndicator(
onRefresh: () async {
context.read<OrdersCubit>().refresh();
},
child: Container(
padding: const EdgeInsets.symmetric(horizontal: 15),
child: Center(
child: Column(
mainAxisAlignment: MainAxisAlignment.center,
children: [
ConstrainedBox(
constraints: const BoxConstraints(
minHeight: 40,
minWidth: double.infinity,
),
child: OutlinedButton(
onPressed: () {
context.read<OrdersCubit>().refresh();
},
child: Text(
'Обновить',
style: Theme.of(context).textTheme.button?.copyWith(
color: Theme.of(context).colorScheme.primary,
),
),
),
),
],
),
),
),
);
}
return RefreshIndicator(
onRefresh: () async {
context.read<OrdersCubit>().refresh();
},
child: ListView.builder(
itemCount: orders.length,
itemBuilder: (final BuildContext context, final int index) =>
_Order(
order: orders[index],
),
),
);
},
);
return Scaffold(
appBar: PreferredSize(
preferredSize: const Size.fromHeight(52),
child: AppBar(
title: const Padding(
padding: EdgeInsets.only(top: 4.0),
2022-12-27 05:47:58 +00:00
child: Text('Заказы'),
),
),
),
body: child,
);
}
}