Optimized channel list

This commit is contained in:
LittleSheep 2024-07-06 18:17:54 +08:00
parent cc59814b55
commit 90daff5b97
4 changed files with 92 additions and 84 deletions

View File

@ -33,8 +33,10 @@ void main() async {
appRunner: () async { appRunner: () async {
WidgetsFlutterBinding.ensureInitialized(); WidgetsFlutterBinding.ensureInitialized();
_initializeFirebase(); await Future.wait([
_initializePlatformComponents(); _initializeFirebase(),
_initializePlatformComponents(),
]);
runApp(const SolianApp()); runApp(const SolianApp());
}, },

View File

@ -3,7 +3,6 @@ import 'package:font_awesome_flutter/font_awesome_flutter.dart';
import 'package:get/get.dart'; import 'package:get/get.dart';
import 'package:solian/models/channel.dart'; import 'package:solian/models/channel.dart';
import 'package:solian/providers/auth.dart'; import 'package:solian/providers/auth.dart';
import 'package:solian/providers/content/call.dart';
import 'package:solian/providers/content/channel.dart'; import 'package:solian/providers/content/channel.dart';
import 'package:solian/router.dart'; import 'package:solian/router.dart';
import 'package:solian/screens/account/notification.dart'; import 'package:solian/screens/account/notification.dart';
@ -30,7 +29,7 @@ class _ChatScreenState extends State<ChatScreen> {
getProfile() async { getProfile() async {
final AuthProvider auth = Get.find(); final AuthProvider auth = Get.find();
if (!await auth.isAuthorized) return; if (!await auth.isAuthorized) return;
final prof = await auth.getProfile(); final prof = await auth.getProfile();
_accountId = prof.body['id']; _accountId = prof.body['id'];
} }
@ -65,7 +64,6 @@ class _ChatScreenState extends State<ChatScreen> {
@override @override
Widget build(BuildContext context) { Widget build(BuildContext context) {
final AuthProvider auth = Get.find(); final AuthProvider auth = Get.find();
final ChatCallProvider call = Get.find();
return Material( return Material(
color: Theme.of(context).colorScheme.surface, color: Theme.of(context).colorScheme.surface,
@ -84,18 +82,6 @@ class _ChatScreenState extends State<ChatScreen> {
); );
} }
final prefixSlivers = [
Obx(() {
if (call.current.value != null) {
return const SliverToBoxAdapter(
child: ChatCallCurrentIndicator(),
);
} else {
return const SliverToBoxAdapter();
}
}),
];
return DefaultTabController( return DefaultTabController(
length: 2, length: 2,
child: NestedScrollView( child: NestedScrollView(
@ -183,32 +169,35 @@ class _ChatScreenState extends State<ChatScreen> {
return TabBarView( return TabBarView(
children: [ children: [
RefreshIndicator( Column(
onRefresh: () => getChannels(), children: [
child: CustomScrollView( const ChatCallCurrentIndicator(),
slivers: [ Expanded(
...prefixSlivers, child: RefreshIndicator(
ChannelListWidget( onRefresh: () => getChannels(),
channels: child: ChannelListWidget(
_channels.where((x) => x.type == 0).toList(), channels:
selfId: _accountId ?? 0, _channels.where((x) => x.type == 0).toList(),
selfId: _accountId ?? 0,
),
), ),
], ),
), ],
), ),
RefreshIndicator( Column(
onRefresh: () => getChannels(), children: [
child: CustomScrollView( const ChatCallCurrentIndicator(),
slivers: [ Expanded(
...prefixSlivers, child: RefreshIndicator(
ChannelListWidget( onRefresh: () => getChannels(),
channels: child: ChannelListWidget(
_channels.where((x) => x.type == 1).toList(), channels: _channels.where((x) => x.type == 1).toList(),
selfId: _accountId ?? 0, selfId: _accountId ?? 0,
noCategory: true, noCategory: true,
),
), ),
], ),
), ],
), ),
], ],
); );

View File

@ -247,34 +247,34 @@ class RealmChannelListWidget extends StatelessWidget {
builder: (context, snapshot) { builder: (context, snapshot) {
return RefreshIndicator( return RefreshIndicator(
onRefresh: onRefresh, onRefresh: onRefresh,
child: CustomScrollView( child: Column(
slivers: [ children: [
SliverToBoxAdapter( ListTile(
child: ListTile( leading: const Icon(Icons.add_box),
leading: const Icon(Icons.add_box), contentPadding: const EdgeInsets.only(left: 32, right: 8),
contentPadding: const EdgeInsets.only(left: 32, right: 8), tileColor: Theme.of(context).colorScheme.surfaceContainer,
tileColor: Theme.of(context).colorScheme.surfaceContainer, title: Text('channelNew'.tr),
title: Text('channelNew'.tr), subtitle: Text(
subtitle: Text( 'channelNewInRealmHint'
'channelNewInRealmHint' .trParams({'realm': '#${realm.alias}'}),
.trParams({'realm': '#${realm.alias}'}),
),
onTap: () {
AppRouter.instance
.pushNamed(
'channelOrganizing',
extra: ChannelOrganizeArguments(realm: realm),
)
.then((value) {
if (value != null) onRefresh();
});
},
), ),
onTap: () {
AppRouter.instance
.pushNamed(
'channelOrganizing',
extra: ChannelOrganizeArguments(realm: realm),
)
.then((value) {
if (value != null) onRefresh();
});
},
), ),
ChannelListWidget( Expanded(
channels: channels, child: ChannelListWidget(
selfId: snapshot.data?.body['id'] ?? 0, channels: channels,
noCategory: true, selfId: snapshot.data?.body['id'] ?? 0,
noCategory: true,
),
) )
], ],
), ),

View File

@ -115,28 +115,45 @@ class _ChannelListWidgetState extends State<ChannelListWidget> {
@override @override
Widget build(BuildContext context) { Widget build(BuildContext context) {
if (widget.noCategory) { if (widget.noCategory) {
return SliverList.builder( return CustomScrollView(
itemCount: _globalChannels.length, slivers: [
itemBuilder: (context, index) { SliverList.builder(
final element = _globalChannels[index]; itemCount: _globalChannels.length,
return buildItem(element); itemBuilder: (context, index) {
}, final element = _globalChannels[index];
return buildItem(element);
},
),
],
); );
} }
return SliverList.list( return CustomScrollView(
children: [ slivers: [
..._globalChannels.map((e) => buildItem(e)), SliverList.builder(
itemCount: _globalChannels.length,
itemBuilder: (context, index) {
final element = _globalChannels[index];
return buildItem(element);
},
),
..._inRealms.entries.map((element) { ..._inRealms.entries.map((element) {
return ExpansionTile( return SliverList.builder(
tilePadding: const EdgeInsets.symmetric(horizontal: 24), itemCount: element.value.length + 1,
title: Text(element.value.first.realm!.name), itemBuilder: (context, index) {
subtitle: Text( if (index == 0) {
element.value.first.realm!.description, return ListTile(
maxLines: 1, contentPadding: const EdgeInsets.symmetric(horizontal: 28),
overflow: TextOverflow.ellipsis, leading: const Icon(Icons.workspaces, size: 20)
), .paddingOnly(left: 6, right: 10),
children: element.value.map((e) => buildItem(e)).toList(), tileColor: Theme.of(context).colorScheme.surfaceContainerHigh,
title: Text(element.value.first.realm!.name),
);
}
final item = element.value[index - 1];
return buildItem(item);
},
); );
}), }),
], ],