Browse Source

[new]调整新人引导浮窗

zk 1 year ago
parent
commit
807600175e

+ 88 - 67
lib/dialog/guide_dialog.dart

@@ -8,8 +8,12 @@ import 'package:flutter_screenutil/flutter_screenutil.dart';
 import 'package:flutter_smart_dialog/flutter_smart_dialog.dart';
 import 'package:get/get.dart';
 
-void mainGuide(GlobalKey topGuide, {VoidCallback? knowCallback}) {
-  final topGuideOffset = getWidgetPosition(topGuide);
+void mainGuide(GlobalKey topGuide, GlobalKey aiGuide,
+    {VoidCallback? knowCallback}) {
+  final topWidgetInfo = getWidgetPosition(topGuide);
+  final aiWidgetInfo = getWidgetPosition(aiGuide);
+  double aiBottom =
+      Get.height - aiWidgetInfo.position.dy - aiWidgetInfo.size.height;
   const tag = 'mainGuideDialog';
   double padding = 7.5.w;
   SmartDialog.show(
@@ -26,7 +30,7 @@ void mainGuide(GlobalKey topGuide, {VoidCallback? knowCallback}) {
               Positioned(
                 left: 0,
                 right: 0,
-                top: topGuideOffset.dy - padding,
+                top: topWidgetInfo.position.dy - padding,
                 child: Column(
                   children: [
                     Container(
@@ -67,80 +71,84 @@ void mainGuide(GlobalKey topGuide, {VoidCallback? knowCallback}) {
                   ],
                 ),
               ),
-              Positioned(
-                left: 0,
-                right: 0,
-                bottom: 8.h,
-                child: Column(
-                  children: [
-                    GestureDetector(
-                      onTap: () {
-                        SmartDialog.dismiss(tag: tag);
-                        knowCallback?.call();
-                      },
-                      child: Container(
-                        decoration: BoxDecoration(
-                          border:
-                              Border.all(color: ColorName.white, width: 2.w),
-                          borderRadius: BorderRadius.circular(100.w),
-                        ),
-                        padding: EdgeInsets.symmetric(
-                            horizontal: 28.w, vertical: 11.w),
-                        child: Text(
-                          StringName.guideAiKnow.tr,
-                          style: TextStyle(
-                              fontSize: 15.sp, color: ColorName.white),
+              Builder(builder: (context) {
+                return Positioned(
+                  left: 0,
+                  right: 0,
+                  bottom:
+                      aiBottom - 7.h + MediaQuery.of(context).padding.bottom,
+                  child: Column(
+                    children: [
+                      GestureDetector(
+                        onTap: () {
+                          SmartDialog.dismiss(tag: tag);
+                          knowCallback?.call();
+                        },
+                        child: Container(
+                          decoration: BoxDecoration(
+                            border:
+                                Border.all(color: ColorName.white, width: 2.w),
+                            borderRadius: BorderRadius.circular(100.w),
+                          ),
+                          padding: EdgeInsets.symmetric(
+                              horizontal: 28.w, vertical: 11.w),
+                          child: Text(
+                            StringName.guideAiKnow.tr,
+                            style: TextStyle(
+                                fontSize: 15.sp, color: ColorName.white),
+                          ),
                         ),
                       ),
-                    ),
-                    SizedBox(height: 32.h),
-                    Container(
-                        width: 274.w,
-                        decoration: BoxDecoration(
-                          image: DecorationImage(
-                            image: Assets.images.bgGuideMainAiPopup.provider(),
-                            fit: BoxFit.cover,
+                      SizedBox(height: 32.h),
+                      Container(
+                          width: 274.w,
+                          decoration: BoxDecoration(
+                            image: DecorationImage(
+                              image:
+                                  Assets.images.bgGuideMainAiPopup.provider(),
+                              fit: BoxFit.cover,
+                            ),
                           ),
-                        ),
-                        child: AspectRatio(
-                          aspectRatio: 274 / 76,
-                          child: Align(
-                            alignment: const FractionalOffset(0.6016, 0.361),
-                            child: IntrinsicHeight(
-                              child: Column(
-                                crossAxisAlignment: CrossAxisAlignment.start,
-                                children: [
-                                  Text(
-                                    StringName.guideAiSecretary.tr,
-                                    style: TextStyle(
-                                        fontSize: 16.sp,
-                                        fontWeight: FontWeight.bold,
-                                        color: ColorName.white),
-                                  ),
-                                  Text(
-                                    StringName.guideAiSecretaryDesc.tr,
-                                    style: TextStyle(
-                                        fontSize: 12.sp,
-                                        color: ColorName.white90),
-                                  )
-                                ],
+                          child: AspectRatio(
+                            aspectRatio: 274 / 76,
+                            child: Align(
+                              alignment: const FractionalOffset(0.6016, 0.361),
+                              child: IntrinsicHeight(
+                                child: Column(
+                                  crossAxisAlignment: CrossAxisAlignment.start,
+                                  children: [
+                                    Text(
+                                      StringName.guideAiSecretary.tr,
+                                      style: TextStyle(
+                                          fontSize: 16.sp,
+                                          fontWeight: FontWeight.bold,
+                                          color: ColorName.white),
+                                    ),
+                                    Text(
+                                      StringName.guideAiSecretaryDesc.tr,
+                                      style: TextStyle(
+                                          fontSize: 12.sp,
+                                          color: ColorName.white90),
+                                    )
+                                  ],
+                                ),
                               ),
                             ),
-                          ),
-                        )),
-                    SizedBox(height: 12.h),
-                    Assets.images.iconGuideMainAi
-                        .image(width: 66.w, height: 66.w),
-                  ],
-                ),
-              )
+                          )),
+                      SizedBox(height: 12.h),
+                      Assets.images.iconGuideMainAi
+                          .image(width: 66.w, height: 66.w),
+                    ],
+                  ),
+                );
+              })
             ],
           ),
         );
       });
 }
 
-Offset getWidgetPosition(GlobalKey key) {
+WidgetInfo getWidgetPosition(GlobalKey key) {
   final context = key.currentContext;
   if (context == null) {
     throw Exception('Context is null');
@@ -152,5 +160,18 @@ Offset getWidgetPosition(GlobalKey key) {
   }
 
   final offset = renderObject.localToGlobal(Offset.zero);
-  return offset;
+  final size = renderObject.size;
+  return WidgetInfo(offset, size);
+}
+
+class WidgetInfo {
+  final Offset position;
+  final Size size;
+
+  WidgetInfo(this.position, this.size);
+
+  @override
+  String toString() {
+    return 'WidgetInfo{position: $position, size: $size}';
+  }
 }

+ 1 - 1
lib/module/home/controller.dart

@@ -71,7 +71,7 @@ class HomePageController extends BaseController {
       return;
     }
     //新人引导
-    mainGuide(headGuideKey, knowCallback: () {
+    mainGuide(headGuideKey, mainController.aiGuideKey, knowCallback: () {
       KVUtil.putBool(GuideConstants.mainGuide, false);
     });
   }

+ 2 - 1
lib/module/main/controller.dart

@@ -8,7 +8,6 @@ import 'package:electronic_assistant/module/record/record_handler.dart';
 import 'package:electronic_assistant/resource/assets.gen.dart';
 import 'package:electronic_assistant/resource/colors.gen.dart';
 import 'package:electronic_assistant/resource/string.gen.dart';
-import 'package:electronic_assistant/utils/expand.dart';
 import 'package:flutter/cupertino.dart';
 import 'package:flutter/material.dart';
 import 'package:flutter/services.dart';
@@ -47,6 +46,8 @@ class MainController extends BaseController {
 
   DateTime? get lastPressedAt => _lastPressedAt;
 
+  GlobalKey aiGuideKey = GlobalKey();
+
   void changeIndex(int index) {
     _currentIndex.value = index;
   }

+ 1 - 0
lib/module/main/view.dart

@@ -74,6 +74,7 @@ class MainTabPage extends BasePage<MainController> {
           controller.onChatClick();
         },
         child: SizedBox(
+          key: controller.aiGuideKey,
           width: 52.w,
           child: AspectRatio(
               aspectRatio: 1 / 1,