179 lines
6.2 KiB
Dart
179 lines
6.2 KiB
Dart
import 'dart:io';
|
|
|
|
import 'package:flutter/material.dart';
|
|
import 'package:get/get.dart';
|
|
import 'package:hgdj/assets_tool/images.dart';
|
|
import 'package:hgdj/hj_utils/screen.dart';
|
|
import 'package:hgdj/tools_base/toast.dart';
|
|
import 'package:hgdj/tools_base/widget/group_text_filed.dart';
|
|
import 'package:image_pickers/image_pickers.dart';
|
|
|
|
/// 评论输入弹层:点空白关闭,自动聚焦拉起键盘
|
|
class CommentInputView extends StatefulWidget {
|
|
static const String routeName = 'comment_input';
|
|
final String? hint;
|
|
final TextEditingController textCtr;
|
|
final String? imgPath;
|
|
final Function(String?)? onImgChange;
|
|
|
|
const CommentInputView({
|
|
super.key,
|
|
this.hint,
|
|
required this.textCtr,
|
|
this.imgPath,
|
|
this.onImgChange,
|
|
});
|
|
|
|
@override
|
|
State<CommentInputView> createState() => _CommentInputViewState();
|
|
}
|
|
|
|
class _CommentInputViewState extends State<CommentInputView> {
|
|
final focus = FocusNode();
|
|
|
|
TextEditingController get textCtr => widget.textCtr;
|
|
//弹层内自己维护一份,选/删图先本地刷新再回调出去
|
|
String? _imgPath;
|
|
|
|
@override
|
|
void initState() {
|
|
super.initState();
|
|
_imgPath = widget.imgPath;
|
|
WidgetsBinding.instance.addPostFrameCallback((timeStamp) {
|
|
focus.requestFocus();
|
|
});
|
|
}
|
|
|
|
@override
|
|
void dispose() {
|
|
focus.dispose();
|
|
super.dispose();
|
|
}
|
|
|
|
void _pickImage() async {
|
|
final listMedia = await ImagePickers.pickerPaths(
|
|
uiConfig: UIConfig(uiThemeColor: Colors.white),
|
|
galleryMode: GalleryMode.image,
|
|
selectCount: 1,
|
|
showCamera: false,
|
|
);
|
|
if (listMedia.isNotEmpty) {
|
|
_imgPath = listMedia.first.path ?? '';
|
|
widget.onImgChange?.call(_imgPath);
|
|
}
|
|
if (mounted) setState(() {});
|
|
}
|
|
|
|
@override
|
|
Widget build(BuildContext context) {
|
|
return Material(
|
|
color: Colors.transparent,
|
|
child: InkWell(
|
|
enableFeedback: false,
|
|
onTap: () => Get.back(),
|
|
child: Container(
|
|
alignment: Alignment.bottomCenter,
|
|
child: GestureDetector(
|
|
onTap: () {},
|
|
child: Container(
|
|
color: Colors.black,
|
|
padding: EdgeInsets.symmetric(horizontal: 16, vertical: 12),
|
|
child: Column(
|
|
crossAxisAlignment: CrossAxisAlignment.start,
|
|
mainAxisSize: MainAxisSize.min,
|
|
children: [
|
|
if (_imgPath?.isNotEmpty == true)
|
|
Container(
|
|
margin: const EdgeInsets.only(bottom: 12),
|
|
width: 60,
|
|
height: 60,
|
|
child: Stack(
|
|
fit: StackFit.expand,
|
|
children: [
|
|
Image.file(
|
|
File(_imgPath!),
|
|
width: 60,
|
|
height: 60,
|
|
fit: BoxFit.cover,
|
|
),
|
|
Positioned(
|
|
top: 0,
|
|
right: 6,
|
|
child: GestureDetector(
|
|
onTap: () {
|
|
_imgPath = null;
|
|
widget.onImgChange?.call(null);
|
|
setState(() {});
|
|
},
|
|
child: Image.asset(
|
|
"close_grey.png".commonImgPath,
|
|
width: 12,
|
|
height: 12,
|
|
),
|
|
),
|
|
),
|
|
],
|
|
),
|
|
),
|
|
Row(
|
|
children: [
|
|
Expanded(
|
|
child: Padding(
|
|
padding: const EdgeInsets.symmetric(vertical: 2),
|
|
child: GroupTextFiled(
|
|
focusNode: focus,
|
|
controller: textCtr,
|
|
height: 32,
|
|
padding: EdgeInsets.symmetric(horizontal: 16),
|
|
textStyle:
|
|
TextStyle(color: Colors.white, fontSize: 14),
|
|
onSubmitted: (value) {
|
|
Get.back(result: true);
|
|
},
|
|
placeholder: widget.hint ?? '请在此输入评论...',
|
|
placeholderTextStyle: TextStyle(
|
|
color: Color(0xff4D4D4D), fontSize: 14),
|
|
decoration: BoxDecoration(
|
|
color: Color(0xff1A1A1A),
|
|
borderRadius: BorderRadius.circular(40)),
|
|
),
|
|
),
|
|
),
|
|
12.sizeBoxW,
|
|
Padding(
|
|
padding: const EdgeInsets.only(
|
|
right: 12, top: 4, bottom: 4),
|
|
child: GestureDetector(
|
|
onTap: _pickImage,
|
|
child: Image.asset(
|
|
'icon_pic.webp'.commentPath,
|
|
width: 30,
|
|
height: 30,
|
|
),
|
|
),
|
|
),
|
|
GestureDetector(
|
|
onTap: () {
|
|
if (textCtr.text.isEmpty) {
|
|
showToast('请输入想要说的话哦~~');
|
|
return;
|
|
}
|
|
Get.back(result: true);
|
|
},
|
|
child: Image.asset(
|
|
'ic_send.webp'.commentPath,
|
|
width: 30,
|
|
height: 30,
|
|
),
|
|
),
|
|
],
|
|
),
|
|
],
|
|
),
|
|
),
|
|
)),
|
|
),
|
|
);
|
|
}
|
|
}
|