2024-08-19 11:31:03 +00:00
|
|
|
import 'package:easy_localization/easy_localization.dart';
|
2024-07-23 10:55:48 +00:00
|
|
|
import 'package:flutter/material.dart';
|
2024-08-29 08:48:59 +00:00
|
|
|
import 'package:flutter/widgets.dart';
|
2024-08-08 18:34:30 +00:00
|
|
|
import 'package:flutter_bloc/flutter_bloc.dart';
|
2024-07-23 10:55:48 +00:00
|
|
|
|
2024-08-08 18:34:30 +00:00
|
|
|
import '../../application/order_bloc/order_bloc.dart';
|
2024-07-23 10:55:48 +00:00
|
|
|
import '../../configs/configs.dart';
|
|
|
|
|
import '../../core/core.dart';
|
2024-08-28 13:05:14 +00:00
|
|
|
import '../../domain/entities/order/filter_params_model.dart';
|
2024-08-03 07:58:07 +00:00
|
|
|
import '../widgets/widgets.dart';
|
2024-07-23 10:55:48 +00:00
|
|
|
|
2024-08-08 18:34:30 +00:00
|
|
|
class OrdersScreen extends StatefulWidget {
|
2024-07-23 10:55:48 +00:00
|
|
|
const OrdersScreen({super.key});
|
|
|
|
|
|
2024-08-08 18:34:30 +00:00
|
|
|
@override
|
|
|
|
|
State<OrdersScreen> createState() => _OrdersScreenState();
|
|
|
|
|
}
|
|
|
|
|
|
2024-08-15 05:49:01 +00:00
|
|
|
class _OrdersScreenState extends State<OrdersScreen> with AutomaticKeepAliveClientMixin<OrdersScreen> {
|
2024-08-28 13:05:14 +00:00
|
|
|
@override
|
|
|
|
|
void initState() {
|
|
|
|
|
super.initState();
|
|
|
|
|
context.read<OrderBloc>().add(const GetOrders(FilterProductParams(filter: OrderFilter.Home)));
|
|
|
|
|
}
|
|
|
|
|
|
2024-07-23 10:55:48 +00:00
|
|
|
@override
|
|
|
|
|
Widget build(BuildContext context) {
|
2024-08-15 05:49:01 +00:00
|
|
|
super.build(context);
|
2024-07-23 10:55:48 +00:00
|
|
|
App.init(context);
|
2024-08-08 18:34:30 +00:00
|
|
|
|
2024-07-23 10:55:48 +00:00
|
|
|
return Scaffold(
|
|
|
|
|
backgroundColor: AppColors.surface,
|
2024-08-13 14:09:44 +00:00
|
|
|
body: NotificationListener<ScrollNotification>(
|
|
|
|
|
onNotification: (ScrollNotification scrollInfo) {
|
|
|
|
|
if (scrollInfo.metrics.pixels == scrollInfo.metrics.maxScrollExtent) {
|
|
|
|
|
context.read<OrderBloc>().add(const GetMoreOrders());
|
|
|
|
|
}
|
|
|
|
|
return false;
|
|
|
|
|
},
|
|
|
|
|
child: CustomScrollView(
|
|
|
|
|
slivers: [
|
|
|
|
|
const SliverToBoxAdapter(
|
|
|
|
|
child: OrderHeader(),
|
|
|
|
|
),
|
|
|
|
|
SliverToBoxAdapter(
|
|
|
|
|
child: Padding(
|
|
|
|
|
padding: Space.all(1, 1),
|
2024-08-19 11:31:03 +00:00
|
|
|
child: Column(
|
2024-08-13 14:09:44 +00:00
|
|
|
crossAxisAlignment: CrossAxisAlignment.start,
|
|
|
|
|
children: [
|
|
|
|
|
Text(
|
2024-08-19 11:31:03 +00:00
|
|
|
'my_orders'.tr(),
|
|
|
|
|
style: const TextStyle(
|
2024-08-28 13:05:14 +00:00
|
|
|
fontSize: 22,
|
2024-08-13 14:09:44 +00:00
|
|
|
fontWeight: FontWeight.bold,
|
|
|
|
|
),
|
2024-07-23 10:55:48 +00:00
|
|
|
),
|
2024-08-29 08:48:59 +00:00
|
|
|
Space.yf(0.40),
|
2024-08-13 14:09:44 +00:00
|
|
|
Text(
|
2024-08-19 11:31:03 +00:00
|
|
|
'follow_orders'.tr(),
|
|
|
|
|
style: const TextStyle(
|
2024-08-13 14:09:44 +00:00
|
|
|
color: Colors.grey,
|
2024-08-28 13:05:14 +00:00
|
|
|
fontSize: 16,
|
2024-08-13 14:09:44 +00:00
|
|
|
),
|
2024-07-23 10:55:48 +00:00
|
|
|
),
|
2024-08-13 14:09:44 +00:00
|
|
|
],
|
|
|
|
|
),
|
2024-07-23 10:55:48 +00:00
|
|
|
),
|
|
|
|
|
),
|
2024-08-13 14:09:44 +00:00
|
|
|
BlocBuilder<OrderBloc, OrderState>(
|
|
|
|
|
builder: (context, state) {
|
|
|
|
|
if (state is OrderLoading && state.orders.isEmpty) {
|
|
|
|
|
return const SliverToBoxAdapter(
|
|
|
|
|
child: Center(
|
|
|
|
|
child: CircularProgressIndicator(),
|
|
|
|
|
),
|
|
|
|
|
);
|
|
|
|
|
} else if (state is OrderError && state.orders.isEmpty) {
|
|
|
|
|
return SliverToBoxAdapter(
|
|
|
|
|
child: Center(
|
|
|
|
|
child: RetryWidget(onRetry: () {
|
|
|
|
|
context.read<OrderBloc>().add(GetOrders(state.params));
|
|
|
|
|
}),
|
2024-08-08 18:34:30 +00:00
|
|
|
),
|
2024-08-13 14:09:44 +00:00
|
|
|
);
|
|
|
|
|
} else if (state is OrderLoaded) {
|
2024-08-29 08:48:59 +00:00
|
|
|
if (state.orders.isEmpty) {
|
|
|
|
|
return SliverToBoxAdapter(
|
|
|
|
|
child: SizedBox(
|
|
|
|
|
height: MediaQuery.of(context).size.height / 2.5,
|
|
|
|
|
child: const EmptyOrder(),
|
|
|
|
|
),
|
|
|
|
|
);
|
|
|
|
|
}
|
2024-08-13 14:09:44 +00:00
|
|
|
return SliverList(
|
|
|
|
|
delegate: SliverChildBuilderDelegate(
|
|
|
|
|
(BuildContext context, int index) {
|
|
|
|
|
final order = state.orders[index];
|
|
|
|
|
|
|
|
|
|
if (index == state.orders.length - 1) {
|
|
|
|
|
// Trigger loading more orders when reaching the bottom
|
|
|
|
|
context.read<OrderBloc>().add(const GetMoreOrders());
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return OrderCard(order: order);
|
|
|
|
|
},
|
|
|
|
|
childCount: state.orders.length,
|
|
|
|
|
),
|
|
|
|
|
);
|
|
|
|
|
} else {
|
2024-08-29 08:48:59 +00:00
|
|
|
return const SizedBox.shrink();
|
2024-08-13 14:09:44 +00:00
|
|
|
}
|
|
|
|
|
},
|
|
|
|
|
),
|
|
|
|
|
],
|
|
|
|
|
),
|
2024-07-23 10:55:48 +00:00
|
|
|
),
|
|
|
|
|
);
|
|
|
|
|
}
|
2024-08-15 05:49:01 +00:00
|
|
|
|
|
|
|
|
@override
|
|
|
|
|
bool get wantKeepAlive => true;
|
2024-07-23 10:55:48 +00:00
|
|
|
}
|