draggable_fab.dart
3.53 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
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。
),
)),
],
);
}
}