draggable_fab.dart 3.53 KB
import 'package:flutter/material.dart';
import 'package:one_key/pages/home/speech_page.dart';
import 'package:one_key/res/colors.dart';

import 'package:one_key/utils/screen_util.dart';

class LongPressFAB extends StatefulWidget {
  const LongPressFAB({super.key});

  @override
  State<LongPressFAB> createState() => _LongPressFABState();
}

class _LongPressFABState extends State<LongPressFAB>
    with SingleTickerProviderStateMixin {
  @override
  Widget build(BuildContext context) {
    return Stack(
      alignment: Alignment.bottomRight,
      children: <Widget>[
        Positioned(
            bottom: w(16),
            right: w(16),
            child: GestureDetector(
              onTap: () {
                showModalBottomSheet(
                    backgroundColor: Colors.transparent,
                    context: context,
                    isScrollControlled: true, // 允许滚动控制
                    builder: (context) {
                      return MediaQuery.removePadding(
                          context: context,
                          removeTop: true,
                          child: Container(
                            height: MediaQuery.of(context).size.height *
                                0.8, // 例如设置高度为屏幕的40%
                            color: Colors.white,

                            padding: EdgeInsets.symmetric(horizontal: w(30)),
                            child: SpeechPage(),
                          ));
                      // return DraggableScrollableSheet(
                      //     initialChildSize: 0.8, // 初始高度为屏幕的40%
                      //     minChildSize: 0.8, // 最小高度为屏幕的20%
                      //     maxChildSize: 0.8, // 最大高度为屏幕的80%
                      //     builder: (BuildContext context,
                      //         ScrollController scrollController) {
                      //       return Container(
                      //         color: Colors.white,
                      //         padding: EdgeInsets.symmetric(horizontal: w(30)),
                      //         child: SpeechPage(),
                      //       );
                      //     });
                    });
              },
              onLongPressStart: (_) async {
                // await SpeechToTextAlibaba.startDialog();
                // //       }, onPressedStop: () async {
                // //
                // //       });// 开始监听语音输入
                // _animationController.forward(); // 开始动画
              },
              onLongPressEnd: (_) async {
                // await SpeechToTextAlibaba
                //     .stopDialog(); // 停止监听语音输入并执行后续操作(如果有的话)
              },
              onLongPressMoveUpdate: (_) {}, // 可选:更新长按位置,但不改变逻辑(通常不需要)
              child: Container(
                // 实际的按钮外观,可以根据需要自定义样式和内容
                padding: EdgeInsets.all(16), // 根据需要调整内边距和大小等属性以适应设计需求。这里仅为示例。
                decoration: BoxDecoration(
                    color: MyColours.color_438E93,
                    borderRadius:
                        BorderRadius.circular(r(30))), // 示例颜色和圆角设置。根据需要调整。
                child: Icon(Icons.mic,
                    color: Colors.white), // 图标示例。可以根据需要替换为其他Widget。
              ),
            )),
      ],
    );
  }
}