Browse Source

可用数

周睿 1 year ago
parent
commit
25d82b9e26

+ 1 - 1
app_business/lib/pages.dart

@@ -20,7 +20,7 @@ final getPages = [
       })),
   GetPage(
       name: HomeView.name,
-      page: () => const HomeView(),
+      page: () => const HomeViewImpl(),
       binding: BindingsBuilder(() {
         Get.put<HomeController>(HomeControllerImpl());
       }))

+ 20 - 0
app_business/lib/service/api.dart

@@ -250,6 +250,26 @@ class ApiService extends IService {
     await stub
         .allMatchChackInsDel(pb.IdArrRequest()..idArr.addAll(checkIdList));
   }
+
+  Stream<CooperationInfo> cooperationInfo() async* {
+    while (true) {
+      await 1.seconds.delay();
+      try {
+        final r = await stub.toCooperationQuery(pb.DefaultRequest());
+        yield CooperationInfo()
+          ..name = r.name
+          ..leftCount = r.leftMatchNum;
+      } catch (e) {
+        warn('获取可用数错误', e);
+      }
+    }
+  }
+}
+
+class CooperationInfo {
+  var name = '';
+  // 可用数
+  var leftCount = 0;
 }
 
 class EventRegisterInfo {

+ 28 - 0
app_business/lib/view/home/home.dart

@@ -1,3 +1,4 @@
+import 'package:app_business/service/api.dart';
 import 'package:app_business/view/home/data_detail.dart';
 import 'package:app_business/view/home/event_manage/event_manage_controller.dart';
 import 'package:app_business/view/home/personal_rank.dart';
@@ -17,6 +18,16 @@ class HomeControllerImpl extends HomeController {
   @override
   int get initTabIdx => 0;
 
+  final _leftCountStream =
+      Get.find<ApiService>().cooperationInfo().map((event) => event.leftCount);
+  final leftCount = 0.obs;
+
+  @override
+  void onInit() {
+    leftCount.bindStream(_leftCountStream);
+    super.onInit();
+  }
+
   @override
   List<HomeTab> get tabs => [
         HomeTab(
@@ -61,6 +72,23 @@ class HomeControllerImpl extends HomeController {
       ];
 }
 
+class HomeViewImpl extends HomeView {
+  const HomeViewImpl({super.key});
+
+  HomeControllerImpl get c => controller as HomeControllerImpl;
+
+  @override
+  List<Widget> actions(BuildContext context) {
+    return [
+      Obx(() => Text('可用数:${c.leftCount.value}',
+          style: const TextStyle(
+              color: Color(0xffffcb00),
+              fontSize: 15.64,
+              fontWeight: FontWeight.w500)))
+    ];
+  }
+}
+
 class _TabBuilder<T> extends StatefulWidget {
   const _TabBuilder({required this.init, required this.builder});
 

+ 25 - 11
libs/track_common/lib/view/home/app_bar.dart

@@ -4,13 +4,22 @@ import 'home_controller.dart';
 
 class HomeAppBar extends GetView<HomeController>
     implements PreferredSizeWidget {
-  const HomeAppBar({super.key, required this.tab});
+  const HomeAppBar({super.key, required this.tab, this.actions});
 
   final Widget tab;
+  final List<Widget>? actions;
 
   @override
   Widget build(BuildContext context) {
     final statusBarHeight = MediaQuery.of(context).viewPadding.top;
+    final wActions = <Widget>[];
+    if (actions!= null){
+      for (final one in actions!!){
+        wActions.add(one);
+        wActions.add(const SizedBox(width: 12));
+      }
+    }
+    
 
     return SizedBox.expand(
         child: Container(
@@ -43,16 +52,21 @@ class HomeAppBar extends GetView<HomeController>
                           style: const TextStyle(
                               color: Colors.white, fontSize: 15.64))
                     ]))),
-          TextButton(
-              onPressed: () {},
-              child: const Row(
-                crossAxisAlignment: CrossAxisAlignment.center,
-                children: [
-                  Icon(Icons.radio, color: Colors.white),
-                  Text(' 广播',
-                      style: TextStyle(color: Colors.white, fontSize: 15.64))
-                ],
-              ))
+          Row(
+            mainAxisSize: MainAxisSize.min,
+            children: wActions,
+          ),
+          const SizedBox(width: 24)
+          // TextButton(
+          //     onPressed: () {},
+          //     child: const Row(
+          //       crossAxisAlignment: CrossAxisAlignment.center,
+          //       children: [
+          //         Icon(Icons.radio, color: Colors.white),
+          //         Text(' 广播',
+          //             style: TextStyle(color: Colors.white, fontSize: 15.64))
+          //       ],
+          //     ))
         ],
       ),
     ));

+ 8 - 0
libs/track_common/lib/view/home/home_view.dart

@@ -6,6 +6,13 @@ import 'home_controller.dart';
 class HomeView extends GetView<HomeController> {
   const HomeView({super.key});
   static const name = '/HomeView';
+  
+  
+  List<Widget> actions(BuildContext context){
+    return [];
+  }
+  
+  
 
   @override
   Widget build(BuildContext context) {
@@ -20,6 +27,7 @@ class HomeView extends GetView<HomeController> {
             indicatorPadding: const EdgeInsets.only(bottom: 0),
             indicator: CustomTabIndicator(),
             dividerColor: Colors.transparent),
+        actions: actions(context),
       ),
       body: Container(
           decoration: const BoxDecoration(