189 lines
5.2 KiB
Dart
189 lines
5.2 KiB
Dart
import 'dart:async';
|
|
|
|
import 'package:cached_network_image/cached_network_image.dart';
|
|
import 'package:flutter/material.dart';
|
|
import 'package:flutter_easyloading/flutter_easyloading.dart';
|
|
import 'package:flutter_slidable/flutter_slidable.dart';
|
|
import 'package:talk/beans/message_bean.dart';
|
|
import 'package:talk/tools/message/message_model.dart';
|
|
|
|
import '../chat/chat_page.dart';
|
|
|
|
///消息列表
|
|
class MessagePage extends StatefulWidget {
|
|
const MessagePage({super.key});
|
|
|
|
@override
|
|
State<MessagePage> createState() => _MessagePageState();
|
|
}
|
|
|
|
class _MessagePageState extends State<MessagePage> {
|
|
List<MessageBean> messageList = [];
|
|
|
|
late StreamSubscription subscription;
|
|
|
|
final MessageModel _viewmodel = MessageModel();
|
|
|
|
@override
|
|
void initState() {
|
|
// TODO: implement initState
|
|
super.initState();
|
|
|
|
subscription = _viewmodel.streamController.stream.listen((newData) {
|
|
String code = newData['code'];
|
|
if (code.isNotEmpty) {
|
|
switch (code) {
|
|
case "getChatHistoryList":
|
|
messageList = newData['data'];
|
|
break;
|
|
default:
|
|
EasyLoading.dismiss();
|
|
EasyLoading.showToast(newData['data']);
|
|
break;
|
|
}
|
|
EasyLoading.dismiss();
|
|
setState(() {});
|
|
}
|
|
});
|
|
|
|
loadData();
|
|
}
|
|
|
|
loadData() {
|
|
EasyLoading.show(status: 'loading...');
|
|
_viewmodel.getChatHistoryList();
|
|
}
|
|
|
|
@override
|
|
void dispose() {
|
|
// TODO: implement dispose
|
|
subscription.cancel();
|
|
super.dispose();
|
|
}
|
|
|
|
@override
|
|
Widget build(BuildContext context) {
|
|
return Scaffold(
|
|
backgroundColor: Color(0xFF121213),
|
|
body: Stack(
|
|
children: [
|
|
Column(
|
|
children: [
|
|
Container(
|
|
margin: EdgeInsets.only(top: MediaQuery.of(context).padding.top + 9, left: 16, right: 16),
|
|
alignment: Alignment.centerLeft,
|
|
child: Text(
|
|
'消息列表',
|
|
style: TextStyle(color: Color(0xFFFF9000), fontSize: 16),
|
|
),
|
|
),
|
|
Expanded(
|
|
child: Container(
|
|
padding: EdgeInsets.only(bottom: 60),
|
|
child: SlidableAutoCloseBehavior(
|
|
child: ListView.builder(
|
|
itemCount: messageList.length,
|
|
itemBuilder: (BuildContext context, int index) {
|
|
return _item(messageList[index], context);
|
|
}),
|
|
),
|
|
))
|
|
],
|
|
)
|
|
],
|
|
),
|
|
);
|
|
}
|
|
|
|
_item(MessageBean data, BuildContext context) {
|
|
return Slidable(
|
|
//左滑划出的菜单
|
|
endActionPane: ActionPane(
|
|
key: Key(UniqueKey().toString()),
|
|
// 菜单宽度
|
|
extentRatio: 0.3,
|
|
dragDismissible: false,
|
|
// 滑动动效
|
|
// DrawerMotion() StretchMotion()
|
|
// motion: ScrollMotion(),
|
|
// A pane can dismiss the Slidable.
|
|
motion: BehindMotion(),
|
|
children: [
|
|
SlidableAction(
|
|
onPressed: doNothing(context, data.id),
|
|
backgroundColor: Color(0xFFFF9000),
|
|
foregroundColor: Colors.black,
|
|
label: '删除',
|
|
),
|
|
],
|
|
),
|
|
|
|
child: GestureDetector(
|
|
behavior: HitTestBehavior.opaque,
|
|
onTap: () {
|
|
Navigator.push(
|
|
context,
|
|
MaterialPageRoute(
|
|
builder: (context) => ChatPage(
|
|
characterId: data.id.toString(),
|
|
)),
|
|
);
|
|
},
|
|
child: Container(
|
|
height: 50,
|
|
margin: EdgeInsets.only(bottom: 10),
|
|
child: Stack(
|
|
alignment: Alignment.center,
|
|
children: [
|
|
///头像
|
|
Positioned(
|
|
left: 16,
|
|
child: ClipOval(
|
|
child: CachedNetworkImage(
|
|
width: 40,
|
|
height: 40,
|
|
imageUrl: data.iconImage!,
|
|
errorWidget: (context, url, error) => const Icon(Icons.error),
|
|
),
|
|
),
|
|
),
|
|
Positioned(
|
|
left: 68,
|
|
top: 6,
|
|
child: Text(
|
|
data.name!,
|
|
style: TextStyle(fontSize: 13, color: Color(0xFFE1E1E1)),
|
|
)),
|
|
Positioned(
|
|
left: 68,
|
|
top: 25,
|
|
child: Container(
|
|
width: 160,
|
|
child: Text(
|
|
'你好',
|
|
maxLines: 1,
|
|
overflow: TextOverflow.ellipsis,
|
|
style: TextStyle(fontSize: 12, color: Color(0xFF777777)),
|
|
),
|
|
)),
|
|
Positioned(
|
|
right: 16,
|
|
top: 6,
|
|
child: Container(
|
|
child: Text(
|
|
'12:39',
|
|
style: TextStyle(fontSize: 10, color: Color(0xFF8D8D8D)),
|
|
),
|
|
)),
|
|
],
|
|
),
|
|
),
|
|
),
|
|
);
|
|
}
|
|
}
|
|
|
|
doNothing(BuildContext context, id) {
|
|
// EasyLoading.showToast("删除");
|
|
}
|