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 {
WidgetsFlutterBinding.ensureInitialized();
_initializeFirebase();
_initializePlatformComponents();
await Future.wait([
_initializeFirebase(),
_initializePlatformComponents(),
]);
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:solian/models/channel.dart';
import 'package:solian/providers/auth.dart';
import 'package:solian/providers/content/call.dart';
import 'package:solian/providers/content/channel.dart';
import 'package:solian/router.dart';
import 'package:solian/screens/account/notification.dart';
@ -65,7 +64,6 @@ class _ChatScreenState extends State<ChatScreen> {
@override
Widget build(BuildContext context) {
final AuthProvider auth = Get.find();
final ChatCallProvider call = Get.find();
return Material(
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(
length: 2,
child: NestedScrollView(
@ -183,32 +169,35 @@ class _ChatScreenState extends State<ChatScreen> {
return TabBarView(
children: [
RefreshIndicator(
onRefresh: () => getChannels(),
child: CustomScrollView(
slivers: [
...prefixSlivers,
ChannelListWidget(
channels:
_channels.where((x) => x.type == 0).toList(),
selfId: _accountId ?? 0,
Column(
children: [
const ChatCallCurrentIndicator(),
Expanded(
child: RefreshIndicator(
onRefresh: () => getChannels(),
child: ChannelListWidget(
channels:
_channels.where((x) => x.type == 0).toList(),
selfId: _accountId ?? 0,
),
),
],
),
),
],
),
RefreshIndicator(
onRefresh: () => getChannels(),
child: CustomScrollView(
slivers: [
...prefixSlivers,
ChannelListWidget(
channels:
_channels.where((x) => x.type == 1).toList(),
selfId: _accountId ?? 0,
noCategory: true,
Column(
children: [
const ChatCallCurrentIndicator(),
Expanded(
child: RefreshIndicator(
onRefresh: () => getChannels(),
child: ChannelListWidget(
channels: _channels.where((x) => x.type == 1).toList(),
selfId: _accountId ?? 0,
noCategory: true,
),
),
],
),
),
],
),
],
);

View File

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

View File

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