88 lines
2.6 KiB
Dart
88 lines
2.6 KiB
Dart
|
|
import 'dart:async';
|
|
import 'package:flutter/material.dart';
|
|
import 'package:jiffy/jiffy.dart';
|
|
import 'package:marianum_mobile/api/marianumcloud/talk/room/getRoom.dart';
|
|
import 'package:marianum_mobile/api/marianumcloud/talk/room/getRoomParams.dart';
|
|
import 'package:marianum_mobile/view/pages/talk/chatTile.dart';
|
|
import 'package:marianum_mobile/view/pages/talk/searchChat.dart';
|
|
import 'package:persistent_bottom_nav_bar/persistent_tab_view.dart';
|
|
import 'package:provider/provider.dart';
|
|
import 'package:shared_preferences/shared_preferences.dart';
|
|
|
|
import '../../../model/chatList/chatListProps.dart';
|
|
import '../../../widget/confirmDialog.dart';
|
|
import '../../../widget/unimplementedDialog.dart';
|
|
import 'chatView.dart';
|
|
import 'joinChat.dart';
|
|
|
|
class ChatList extends StatefulWidget {
|
|
const ChatList({Key? key}) : super(key: key);
|
|
|
|
@override
|
|
State<ChatList> createState() => _ChatListState();
|
|
}
|
|
|
|
class _ChatListState extends State<ChatList> {
|
|
|
|
@override
|
|
void initState() {
|
|
super.initState();
|
|
|
|
WidgetsBinding.instance.addPostFrameCallback((timeStamp) {
|
|
_query();
|
|
});
|
|
}
|
|
|
|
void _query({bool renew = false}) {
|
|
Provider.of<ChatListProps>(context, listen: false).run(renew: renew);
|
|
}
|
|
|
|
@override
|
|
Widget build(BuildContext context) {
|
|
|
|
return Scaffold(
|
|
appBar: AppBar(
|
|
title: const Text("Talk"),
|
|
actions: [
|
|
IconButton(
|
|
icon: const Icon(Icons.search),
|
|
onPressed: () async {
|
|
showSearch(context: context, delegate: SearchChat((await GetRoom(GetRoomParams(includeStatus: true)).run()).data.toList()));
|
|
},
|
|
)
|
|
],
|
|
),
|
|
floatingActionButton: FloatingActionButton(
|
|
backgroundColor: Theme.of(context).primaryColor,
|
|
onPressed: () {
|
|
showSearch(context: context, delegate: JoinChat());
|
|
},
|
|
child: const Icon(Icons.add_comment_outlined),
|
|
),
|
|
body: Consumer<ChatListProps>(
|
|
builder: (context, data, child) {
|
|
|
|
if(data.primaryLoading()) {
|
|
return const Center(child: CircularProgressIndicator());
|
|
}
|
|
|
|
List<ChatTile> chats = List<ChatTile>.empty(growable: true);
|
|
|
|
for (var chatRoom in data.getRoomsResponse.sortByLastActivity()) {
|
|
chats.add(ChatTile(data: chatRoom, query: _query));
|
|
}
|
|
|
|
return RefreshIndicator(
|
|
color: Theme.of(context).primaryColor,
|
|
onRefresh: () {
|
|
_query(renew: true);
|
|
return Future.delayed(const Duration(seconds: 3));
|
|
},
|
|
child: ListView(children: chats),
|
|
);
|
|
},
|
|
),
|
|
);
|
|
}
|
|
} |