Initial commit: 91dj android client dev_1.0.0
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
@@ -0,0 +1,234 @@
|
||||
import 'package:flutter/cupertino.dart';
|
||||
import 'package:flutter/material.dart';
|
||||
import 'package:jydj/tools_base/global_store/store.dart';
|
||||
import 'package:jydj/tools_base/widget/net_image_widget.dart';
|
||||
import 'package:jydj/tools_base/widget/image_browser_page.dart';
|
||||
import 'package:jydj/routers/jump_router.dart';
|
||||
|
||||
import '../../model/im_message_resp.dart';
|
||||
|
||||
class ChatItemCell extends StatefulWidget {
|
||||
final IMMessageModel? model;
|
||||
final VoidCallback? onResend;
|
||||
final int? peerUid;
|
||||
|
||||
ChatItemCell({Key? key, this.model, this.onResend, this.peerUid}) : super(key: key);
|
||||
|
||||
@override
|
||||
State<StatefulWidget> createState() {
|
||||
return _ChatItemCellState();
|
||||
}
|
||||
}
|
||||
|
||||
class _ChatItemCellState extends State<ChatItemCell> {
|
||||
bool get isImg => widget.model?.image?.isNotEmpty == true;
|
||||
|
||||
bool get isMe => widget.model?.fromSelf == true;
|
||||
|
||||
double imageWidth = 173;
|
||||
|
||||
void _showImageScan(String imageUrl) {
|
||||
if (imageUrl.isNotEmpty) {
|
||||
ImageBrowserPage.open([imageUrl]);
|
||||
}
|
||||
}
|
||||
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
if (isMe) {
|
||||
return _buildRightStyle();
|
||||
} else {
|
||||
return _buildLeftStyle();
|
||||
}
|
||||
}
|
||||
|
||||
Widget _buildLeftStyle() {
|
||||
return Container(
|
||||
padding: EdgeInsets.fromLTRB(0, 12, 0, 6),
|
||||
child: Column(
|
||||
children: [
|
||||
Container(
|
||||
padding: EdgeInsets.fromLTRB(16, 0, 50, 0),
|
||||
child: Row(
|
||||
crossAxisAlignment: CrossAxisAlignment.start,
|
||||
children: [
|
||||
GestureDetector(
|
||||
onTap: () => _openProfile(widget.peerUid),
|
||||
child: SizedBox(
|
||||
width: 40,
|
||||
height: 40,
|
||||
child: NetworkImageLoader(
|
||||
imageUrl: widget.model?.receiverAvatar ?? "",
|
||||
width: 40,
|
||||
height: 40,
|
||||
borderRadius: 20,
|
||||
),
|
||||
),
|
||||
),
|
||||
SizedBox(width: 12),
|
||||
Flexible(
|
||||
child: Column(
|
||||
mainAxisSize: MainAxisSize.max,
|
||||
crossAxisAlignment: CrossAxisAlignment.start,
|
||||
children: [
|
||||
if (isImg)
|
||||
InkWell(
|
||||
onTap: () {
|
||||
_showImageScan(widget.model?.image ?? "");
|
||||
},
|
||||
child: Container(
|
||||
margin: EdgeInsets.only(top: 5),
|
||||
alignment: Alignment.centerLeft,
|
||||
constraints: BoxConstraints(maxWidth: 173),
|
||||
child: _buildImageWidget(isLeft: true),
|
||||
),
|
||||
)
|
||||
else
|
||||
Container(
|
||||
padding: EdgeInsets.symmetric(horizontal: 14, vertical: 10),
|
||||
margin: EdgeInsets.only(top: 5),
|
||||
decoration: BoxDecoration(
|
||||
color: Colors.white.withValues(alpha: .05),
|
||||
borderRadius: BorderRadius.only(
|
||||
bottomLeft: Radius.circular(12),
|
||||
bottomRight: Radius.circular(12),
|
||||
topRight: Radius.circular(12),
|
||||
topLeft: Radius.circular(2)),
|
||||
),
|
||||
child: Text(
|
||||
widget.model?.content ?? "",
|
||||
style: TextStyle(
|
||||
color: Colors.white,
|
||||
fontSize: 12,
|
||||
),
|
||||
),
|
||||
),
|
||||
],
|
||||
),
|
||||
),
|
||||
],
|
||||
),
|
||||
),
|
||||
],
|
||||
),
|
||||
);
|
||||
}
|
||||
|
||||
Widget _buildRightStyle() {
|
||||
return Container(
|
||||
padding: EdgeInsets.fromLTRB(0, 12, 0, 6),
|
||||
child: Column(
|
||||
children: [
|
||||
Container(
|
||||
padding: EdgeInsets.fromLTRB(50, 0, 16, 0),
|
||||
child: Row(
|
||||
crossAxisAlignment: CrossAxisAlignment.center,
|
||||
mainAxisAlignment: MainAxisAlignment.end,
|
||||
children: [
|
||||
_buildSendStatus(),
|
||||
Flexible(
|
||||
child: Column(
|
||||
mainAxisSize: MainAxisSize.min,
|
||||
crossAxisAlignment: CrossAxisAlignment.end,
|
||||
children: [
|
||||
if (isImg)
|
||||
InkWell(
|
||||
onTap: () {
|
||||
_showImageScan(widget.model?.image ?? "");
|
||||
},
|
||||
child: Container(
|
||||
margin: EdgeInsets.only(top: 5),
|
||||
alignment: Alignment.centerRight,
|
||||
constraints: BoxConstraints(maxWidth: 173),
|
||||
child: _buildImageWidget(isLeft: false),
|
||||
),
|
||||
)
|
||||
else
|
||||
Container(
|
||||
padding: EdgeInsets.symmetric(horizontal: 14, vertical: 10),
|
||||
margin: EdgeInsets.only(top: 5),
|
||||
decoration: BoxDecoration(
|
||||
color: Color(0xff1DC194),
|
||||
borderRadius: BorderRadius.only(
|
||||
bottomLeft: Radius.circular(12),
|
||||
bottomRight: Radius.circular(12),
|
||||
topLeft: Radius.circular(12),
|
||||
topRight: Radius.circular(4)),
|
||||
),
|
||||
child: Text(
|
||||
widget.model?.content ?? "",
|
||||
style: TextStyle(
|
||||
color: Color(0xFF000000),
|
||||
fontSize: 12,
|
||||
),
|
||||
),
|
||||
),
|
||||
],
|
||||
),
|
||||
),
|
||||
SizedBox(width: 12),
|
||||
GestureDetector(
|
||||
onTap: () => _openProfile(globalStore.meInfo?.uid),
|
||||
child: SizedBox(
|
||||
width: 40,
|
||||
height: 40,
|
||||
child: NetworkImageLoader(
|
||||
imageUrl: widget.model?.senderAvatar ?? "",
|
||||
width: 40,
|
||||
height: 40,
|
||||
borderRadius: 20,
|
||||
),
|
||||
),
|
||||
),
|
||||
],
|
||||
),
|
||||
),
|
||||
],
|
||||
),
|
||||
);
|
||||
}
|
||||
|
||||
// 发送状态指示: 0发送中(菊花) 1失败(红色叹号,点击重发) 其余正常不展示
|
||||
Widget _buildSendStatus() {
|
||||
final state = widget.model?.messageState;
|
||||
if (state == 0) {
|
||||
return Padding(
|
||||
padding: EdgeInsets.only(right: 8),
|
||||
child: CupertinoActivityIndicator(radius: 8, color: Color(0xff999999)),
|
||||
);
|
||||
}
|
||||
if (state == 1) {
|
||||
return GestureDetector(
|
||||
onTap: widget.onResend,
|
||||
child: Padding(
|
||||
padding: EdgeInsets.only(right: 8),
|
||||
child: Icon(Icons.error, color: Color(0xffFF004F), size: 22),
|
||||
),
|
||||
);
|
||||
}
|
||||
return const SizedBox.shrink();
|
||||
}
|
||||
|
||||
void _openProfile(int? uid) {
|
||||
if (uid != null && uid > 0) {
|
||||
pushToPersonCenter(uid);
|
||||
}
|
||||
}
|
||||
|
||||
Widget _buildImageWidget({bool isLeft = false}) {
|
||||
return Stack(
|
||||
children: [
|
||||
NetworkImageLoader(
|
||||
imageUrl: widget.model?.image ?? "",
|
||||
width: imageWidth,
|
||||
imgBorderRadius: BorderRadius.only(
|
||||
bottomLeft: Radius.circular(12),
|
||||
bottomRight: Radius.circular(12),
|
||||
topRight: Radius.circular(isLeft ? 12 : 0),
|
||||
topLeft: Radius.circular(isLeft ? 0 : 12),
|
||||
),
|
||||
),
|
||||
],
|
||||
);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,157 @@
|
||||
import 'dart:io';
|
||||
|
||||
import 'package:flutter/cupertino.dart';
|
||||
import 'package:flutter/material.dart';
|
||||
import 'package:flutter_screenutil/flutter_screenutil.dart';
|
||||
import 'package:jydj/assets_tool/images.dart';
|
||||
import 'package:jydj/tools_base/widget/group_text_filed.dart';
|
||||
import 'package:jydj/hj_utils/screen.dart';
|
||||
import 'package:image_pickers/image_pickers.dart';
|
||||
|
||||
class InputFootView extends StatefulWidget {
|
||||
final Function(bool) begainCommentHandler; // true 发送
|
||||
final bool isSendStatus;
|
||||
final TextEditingController textEditController;
|
||||
final String? imagePath;
|
||||
final Function(String?)? imgCallback;
|
||||
final Function(String path)? onImageSend; // 选图即发:选完直接发送,不走底部预览
|
||||
final String? placeholder;
|
||||
const InputFootView({
|
||||
super.key,
|
||||
required this.begainCommentHandler,
|
||||
this.isSendStatus = false,
|
||||
required this.textEditController,
|
||||
this.imagePath,
|
||||
this.imgCallback,
|
||||
this.onImageSend,
|
||||
this.placeholder,
|
||||
});
|
||||
|
||||
@override
|
||||
State<InputFootView> createState() => _InputFootViewState();
|
||||
}
|
||||
|
||||
class _InputFootViewState extends State<InputFootView> {
|
||||
bool isImageSelectIng = false;
|
||||
|
||||
void choseImg() async {
|
||||
isImageSelectIng = true;
|
||||
final listMedia = await ImagePickers.pickerPaths(
|
||||
uiConfig: UIConfig(uiThemeColor: Colors.white),
|
||||
galleryMode: GalleryMode.image,
|
||||
selectCount: 1,
|
||||
showCamera: false,
|
||||
);
|
||||
if (listMedia.isNotEmpty) {
|
||||
final ret = listMedia.map((e) => e.path ?? '').toList();
|
||||
String selectedImgPath = ret.first;
|
||||
if (selectedImgPath.isNotEmpty) {
|
||||
// 选完图直接发送,不在底部预览
|
||||
widget.onImageSend?.call(selectedImgPath);
|
||||
}
|
||||
}
|
||||
setState(() {});
|
||||
Future.delayed(Duration(milliseconds: 500), () {
|
||||
isImageSelectIng = false;
|
||||
});
|
||||
}
|
||||
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
return SafeArea(
|
||||
bottom: true,
|
||||
child: Container(
|
||||
color: const Color(0xff000000),
|
||||
child: Container(
|
||||
height: 58,
|
||||
width: double.infinity,
|
||||
margin: EdgeInsets.symmetric(vertical: 12.h, horizontal: 18.w),
|
||||
child: Row(
|
||||
children: [
|
||||
Expanded(
|
||||
child: GestureDetector(
|
||||
onTap: () => widget.begainCommentHandler(false),
|
||||
child: GroupTextFiled(
|
||||
controller: widget.textEditController,
|
||||
height: 32,
|
||||
enabled: false,
|
||||
padding: const EdgeInsets.symmetric(horizontal: 20),
|
||||
textStyle: TextStyle(color: Colors.white, fontSize: 14.sp),
|
||||
placeholder: widget.placeholder ?? '请输入消息',
|
||||
placeholderTextStyle:
|
||||
const TextStyle(color: Color(0xFF525252), fontSize: 12, fontWeight: FontWeight.w400),
|
||||
decoration: BoxDecoration(
|
||||
color: const Color(0x1AFFFFFF),
|
||||
borderRadius: BorderRadius.circular(90),
|
||||
),
|
||||
),
|
||||
),
|
||||
),
|
||||
Container(
|
||||
margin: const EdgeInsets.only(left: 12),
|
||||
child: Stack(
|
||||
children: [
|
||||
SizedBox(
|
||||
height: 24,
|
||||
width: 24,
|
||||
child: GestureDetector(
|
||||
onTap: choseImg,
|
||||
child: widget.imagePath?.isNotEmpty == true
|
||||
? ClipRRect(
|
||||
borderRadius: BorderRadius.circular(4),
|
||||
child: Image.file(
|
||||
File(widget.imagePath!),
|
||||
width: 24,
|
||||
height: 24,
|
||||
fit: BoxFit.cover,
|
||||
),
|
||||
)
|
||||
: Image.asset("icon_pic.webp".commentPath),
|
||||
),
|
||||
),
|
||||
if (widget.imagePath?.isNotEmpty == true)
|
||||
Positioned(
|
||||
top: 0,
|
||||
right: 0,
|
||||
child: GestureDetector(
|
||||
onTap: () {
|
||||
widget.imgCallback?.call(null);
|
||||
setState(() {});
|
||||
},
|
||||
child: Image.asset(
|
||||
"close_grey.png".commonImgPath,
|
||||
width: 12,
|
||||
height: 12,
|
||||
),
|
||||
),
|
||||
),
|
||||
],
|
||||
),
|
||||
),
|
||||
10.sizeBoxW,
|
||||
_buildSendButton(),
|
||||
],
|
||||
),
|
||||
),
|
||||
),
|
||||
);
|
||||
}
|
||||
|
||||
Widget _buildSendButton() {
|
||||
return GestureDetector(
|
||||
onTap: () {
|
||||
widget.begainCommentHandler(true);
|
||||
},
|
||||
child: SizedBox(
|
||||
width: 28,
|
||||
height: 28,
|
||||
child: widget.isSendStatus
|
||||
? const CupertinoActivityIndicator(
|
||||
color: Colors.redAccent,
|
||||
radius: 12,
|
||||
)
|
||||
: Image.asset('ic_send.webp'.commentPath, width: 28, height: 28),
|
||||
),
|
||||
);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,166 @@
|
||||
import 'dart:io';
|
||||
|
||||
import 'package:flutter/material.dart';
|
||||
import 'package:flutter_screenutil/flutter_screenutil.dart';
|
||||
import 'package:get/get.dart';
|
||||
import 'package:jydj/assets_tool/images.dart';
|
||||
import 'package:jydj/tools_base/widget/group_text_filed.dart';
|
||||
import 'package:jydj/hj_utils/screen.dart';
|
||||
import 'package:image_pickers/image_pickers.dart';
|
||||
|
||||
class InputSheetView extends StatefulWidget {
|
||||
final String? hint;
|
||||
final TextEditingController textEditController;
|
||||
final String? selectedImgPath;
|
||||
final Function(String? imgPath)? imgCallback;
|
||||
|
||||
const InputSheetView({
|
||||
super.key,
|
||||
this.hint,
|
||||
required this.textEditController,
|
||||
this.selectedImgPath,
|
||||
this.imgCallback,
|
||||
});
|
||||
|
||||
@override
|
||||
State<InputSheetView> createState() => _InputSheetViewState();
|
||||
}
|
||||
|
||||
class _InputSheetViewState extends State<InputSheetView> with WidgetsBindingObserver {
|
||||
final focus = FocusNode();
|
||||
|
||||
TextEditingController get textEditController => widget.textEditController;
|
||||
bool hasShowKeyboard = false;
|
||||
bool isImageSelectIng = false;
|
||||
String? selectedImgPath;
|
||||
|
||||
@override
|
||||
void initState() {
|
||||
super.initState();
|
||||
selectedImgPath = widget.selectedImgPath;
|
||||
textEditController.addListener(() {
|
||||
if (mounted) setState(() {});
|
||||
});
|
||||
WidgetsBinding.instance.addPostFrameCallback((timeStamp) {
|
||||
focus.requestFocus();
|
||||
});
|
||||
WidgetsBinding.instance.addObserver(this);
|
||||
}
|
||||
|
||||
void choseImg() async {
|
||||
isImageSelectIng = true;
|
||||
final listMedia = await ImagePickers.pickerPaths(
|
||||
uiConfig: UIConfig(uiThemeColor: Colors.white),
|
||||
galleryMode: GalleryMode.image,
|
||||
selectCount: 1,
|
||||
showCamera: false,
|
||||
);
|
||||
if (listMedia.isNotEmpty) {
|
||||
final ret = listMedia.map((e) => e.path ?? '').toList();
|
||||
selectedImgPath = ret.first;
|
||||
widget.imgCallback?.call(selectedImgPath!);
|
||||
}
|
||||
setState(() {});
|
||||
Future.delayed(Duration(milliseconds: 500), () {
|
||||
isImageSelectIng = false;
|
||||
});
|
||||
}
|
||||
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
// 固定输入栏高度,避免 bottomSheet 占满屏幕产生蒙层
|
||||
return Material(
|
||||
color: const Color(0xff000000),
|
||||
child: Container(
|
||||
height: 58,
|
||||
width: double.infinity,
|
||||
margin: EdgeInsets.symmetric(vertical: 12.h, horizontal: 18.w),
|
||||
child: Row(
|
||||
children: [
|
||||
Expanded(
|
||||
child: GestureDetector(
|
||||
onTap: () {
|
||||
focus.requestFocus();
|
||||
},
|
||||
child: GroupTextFiled(
|
||||
focusNode: focus,
|
||||
controller: widget.textEditController,
|
||||
height: 32,
|
||||
padding: const EdgeInsets.symmetric(horizontal: 20),
|
||||
textStyle: TextStyle(color: Colors.white, fontSize: 14.sp),
|
||||
placeholder: widget.hint ?? '请输入消息',
|
||||
placeholderTextStyle:
|
||||
const TextStyle(color: Color(0xFF525252), fontSize: 12, fontWeight: FontWeight.w400),
|
||||
decoration: BoxDecoration(
|
||||
color: const Color(0x1AFFFFFF),
|
||||
borderRadius: BorderRadius.circular(90),
|
||||
),
|
||||
),
|
||||
),
|
||||
),
|
||||
Container(
|
||||
margin: const EdgeInsets.only(left: 12),
|
||||
child: Stack(
|
||||
children: [
|
||||
SizedBox(
|
||||
height: 24,
|
||||
width: 24,
|
||||
child: GestureDetector(
|
||||
onTap: choseImg,
|
||||
child: selectedImgPath?.isNotEmpty == true
|
||||
? ClipRRect(
|
||||
borderRadius: BorderRadius.circular(4),
|
||||
child: Image.file(
|
||||
File(selectedImgPath!),
|
||||
width: 24,
|
||||
height: 24,
|
||||
fit: BoxFit.cover,
|
||||
),
|
||||
)
|
||||
: Image.asset("icon_pic.webp".commentPath),
|
||||
),
|
||||
),
|
||||
if (selectedImgPath?.isNotEmpty == true)
|
||||
Positioned(
|
||||
top: 0,
|
||||
right: 0,
|
||||
child: GestureDetector(
|
||||
onTap: () {
|
||||
widget.imgCallback?.call(null);
|
||||
setState(() {});
|
||||
},
|
||||
child: Image.asset(
|
||||
"close_grey.png".commonImgPath,
|
||||
width: 12,
|
||||
height: 12,
|
||||
),
|
||||
),
|
||||
),
|
||||
],
|
||||
),
|
||||
),
|
||||
10.sizeBoxW,
|
||||
_buildSendButton(),
|
||||
],
|
||||
),
|
||||
),
|
||||
);
|
||||
}
|
||||
|
||||
Widget _buildSendButton() {
|
||||
return GestureDetector(
|
||||
onTap: () {
|
||||
focus.unfocus();
|
||||
Get.back(result: true);
|
||||
},
|
||||
child: Image.asset('ic_send.webp'.commentPath, width: 28, height: 28),
|
||||
);
|
||||
}
|
||||
|
||||
@override
|
||||
void dispose() {
|
||||
focus.unfocus();
|
||||
WidgetsBinding.instance.removeObserver(this);
|
||||
super.dispose();
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user