From 5d5add81792ee2d9ca4c615d7418361bcdabfa05 Mon Sep 17 00:00:00 2001 From: Matheus Augusto Date: Tue, 13 Jun 2023 21:48:50 -0300 Subject: [PATCH] stream order admin --- lib/src/shared/controllers/order_controller.dart | 6 ++++++ lib/src/views/admin/screen/home/home_screen.dart | 4 ++-- 2 files changed, 8 insertions(+), 2 deletions(-) diff --git a/lib/src/shared/controllers/order_controller.dart b/lib/src/shared/controllers/order_controller.dart index a5ee230..e283f05 100644 --- a/lib/src/shared/controllers/order_controller.dart +++ b/lib/src/shared/controllers/order_controller.dart @@ -7,6 +7,12 @@ class OrderController { return await orderRepository.get(); } + Stream getLikeStream() async* { + yield* Stream.periodic( + const Duration(seconds: 3), (_) => orderRepository.get()) + .asyncMap((event) async => await event); + } + Future post(List idItem) async { await orderRepository.post(idItem); } diff --git a/lib/src/views/admin/screen/home/home_screen.dart b/lib/src/views/admin/screen/home/home_screen.dart index 5797511..2ac8699 100644 --- a/lib/src/views/admin/screen/home/home_screen.dart +++ b/lib/src/views/admin/screen/home/home_screen.dart @@ -98,8 +98,8 @@ class HomeAdminScreen extends StatelessWidget { ), ), Expanded( - child: FutureBuilder( - future: orderController.get(), + child: StreamBuilder( + stream: orderController.getLikeStream(), builder: (context, snapshot) { if (!snapshot.hasData) { return const Center(