mod: 代码整理

This commit is contained in:
guozhigq
2024-01-21 14:01:33 +08:00
parent ca6091b90d
commit 538b3d88aa

View File

@@ -2,12 +2,10 @@ import 'dart:async';
import 'package:flutter/material.dart'; import 'package:flutter/material.dart';
import 'package:flutter_smart_dialog/flutter_smart_dialog.dart'; import 'package:flutter_smart_dialog/flutter_smart_dialog.dart';
import 'package:get/get.dart'; import 'package:get/get.dart';
import 'package:hive/hive.dart';
import 'package:pilipala/http/video.dart'; import 'package:pilipala/http/video.dart';
import 'package:pilipala/models/common/reply_type.dart'; import 'package:pilipala/models/common/reply_type.dart';
import 'package:pilipala/models/video/reply/item.dart'; import 'package:pilipala/models/video/reply/item.dart';
import 'package:pilipala/utils/feed_back.dart'; import 'package:pilipala/utils/feed_back.dart';
import 'package:pilipala/utils/storage.dart';
class VideoReplyNewDialog extends StatefulWidget { class VideoReplyNewDialog extends StatefulWidget {
final int? oid; final int? oid;
@@ -34,23 +32,16 @@ class _VideoReplyNewDialogState extends State<VideoReplyNewDialog>
final TextEditingController _replyContentController = TextEditingController(); final TextEditingController _replyContentController = TextEditingController();
final FocusNode replyContentFocusNode = FocusNode(); final FocusNode replyContentFocusNode = FocusNode();
final GlobalKey _formKey = GlobalKey<FormState>(); final GlobalKey _formKey = GlobalKey<FormState>();
bool ableClean = false;
Timer? timer;
Box localCache = GStrorage.localCache;
late double sheetHeight;
@override @override
void initState() { void initState() {
super.initState(); super.initState();
// 监听输入框聚焦 // 监听输入框聚焦
// replyContentFocusNode.addListener(_onFocus); // replyContentFocusNode.addListener(_onFocus);
_replyContentController.addListener(_printLatestValue);
// 界面观察者 必须 // 界面观察者 必须
WidgetsBinding.instance.addObserver(this); WidgetsBinding.instance.addObserver(this);
// 自动聚焦 // 自动聚焦
_autoFocus(); _autoFocus();
sheetHeight = localCache.get('sheetHeight');
} }
_autoFocus() async { _autoFocus() async {
@@ -60,12 +51,6 @@ class _VideoReplyNewDialogState extends State<VideoReplyNewDialog>
} }
} }
_printLatestValue() {
setState(() {
ableClean = _replyContentController.text != '';
});
}
Future submitReplyAdd() async { Future submitReplyAdd() async {
feedBack(); feedBack();
String message = _replyContentController.text; String message = _replyContentController.text;
@@ -115,10 +100,12 @@ class _VideoReplyNewDialogState extends State<VideoReplyNewDialog>
ConstrainedBox( ConstrainedBox(
constraints: const BoxConstraints( constraints: const BoxConstraints(
maxHeight: 200, maxHeight: 200,
minHeight: 120,
), ),
child: SingleChildScrollView( child: Container(
padding: const EdgeInsets.only( padding: const EdgeInsets.only(
top: 6, right: 15, left: 15, bottom: 10), top: 12, right: 15, left: 15, bottom: 10),
child: SingleChildScrollView(
child: Form( child: Form(
key: _formKey, key: _formKey,
autovalidateMode: AutovalidateMode.onUserInteraction, autovalidateMode: AutovalidateMode.onUserInteraction,
@@ -137,7 +124,9 @@ class _VideoReplyNewDialogState extends State<VideoReplyNewDialog>
style: Theme.of(context).textTheme.bodyLarge, style: Theme.of(context).textTheme.bodyLarge,
), ),
), ),
)), ),
),
),
Divider( Divider(
height: 1, height: 1,
color: Theme.of(context).dividerColor.withOpacity(0.1), color: Theme.of(context).dividerColor.withOpacity(0.1),
@@ -153,17 +142,10 @@ class _VideoReplyNewDialogState extends State<VideoReplyNewDialog>
height: 36, height: 36,
child: IconButton( child: IconButton(
onPressed: () { onPressed: () {
if (keyboardHeight > 0) {
FocusScope.of(context).unfocus();
} else {
FocusScope.of(context) FocusScope.of(context)
.requestFocus(replyContentFocusNode); .requestFocus(replyContentFocusNode);
}
}, },
icon: Icon( icon: Icon(Icons.keyboard,
keyboardHeight > 0
? Icons.keyboard_hide
: Icons.keyboard,
size: 22, size: 22,
color: Theme.of(context).colorScheme.onBackground), color: Theme.of(context).colorScheme.onBackground),
highlightColor: highlightColor:
@@ -172,14 +154,10 @@ class _VideoReplyNewDialogState extends State<VideoReplyNewDialog>
padding: MaterialStateProperty.all(EdgeInsets.zero), padding: MaterialStateProperty.all(EdgeInsets.zero),
backgroundColor: backgroundColor:
MaterialStateProperty.resolveWith((states) { MaterialStateProperty.resolveWith((states) {
// 如果按钮被按下,返回高亮颜色
if (states.contains(MaterialState.pressed)) {
return Theme.of(context).highlightColor; return Theme.of(context).highlightColor;
}
// 默认状态下,返回透明颜色
return Colors.transparent;
}), }),
)), ),
),
), ),
const Spacer(), const Spacer(),
TextButton( TextButton(
@@ -200,22 +178,3 @@ class _VideoReplyNewDialogState extends State<VideoReplyNewDialog>
); );
} }
} }
typedef DebounceCallback = void Function();
class Debouncer {
DebounceCallback? callback;
final int? milliseconds;
Timer? _timer;
Debouncer({this.milliseconds});
run(DebounceCallback callback) {
if (_timer != null) {
_timer!.cancel();
}
_timer = Timer(Duration(milliseconds: milliseconds!), () {
callback();
});
}
}