You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

64 lines
1.7 KiB

4 years ago
import 'package:bytedesk_kefu/bytedesk_kefu.dart';
import 'package:bytedesk_kefu/model/thread.dart';
import 'package:flutter/material.dart';
// 历史会话列表
class HistoryThreadPage extends StatefulWidget {
HistoryThreadPage({Key key}) : super(key: key);
@override
_HistoryThreadPageState createState() => _HistoryThreadPageState();
}
4 years ago
// TODO: 点击thread会话直接进入对话页面
4 years ago
class _HistoryThreadPageState extends State<HistoryThreadPage> {
4 years ago
//
4 years ago
int _page = 0;
int _size = 20;
List<Thread> _historyThreadList = [];
//
@override
void initState() {
_getVisitorThreads();
super.initState();
}
//
@override
Widget build(BuildContext context) {
return Scaffold(
appBar: AppBar(
title: Text('历史会话'),
elevation: 0,
),
body: RefreshIndicator(
child: ListView.builder(
padding: EdgeInsets.all(8.0),
itemBuilder: (_, int index) => ListTile(
leading: Image.network(_historyThreadList[index].avatar),
title: Text('${_historyThreadList[index].nickname}, ${_historyThreadList[index].timestamp}'),
subtitle: Text('${_historyThreadList[index].content}'),
4 years ago
onTap: () {
// 进入客服页面
BytedeskKefu.startChatThread(context, _historyThreadList[index]);
},
4 years ago
),
itemCount: _historyThreadList.length,
),
onRefresh: _onRefresh,
));
}
void _getVisitorThreads() {
BytedeskKefu.getVisitorThreads(_page, _size).then((value) => {
setState(() {
_historyThreadList = value;
})
});
}
Future<void> _onRefresh() async {
_getVisitorThreads();
4 years ago
_page++;
4 years ago
}
}