channel and message lists
This commit is contained in:
18
flutter/lib/pages/channel_list/channel_list_item.dart
Normal file
18
flutter/lib/pages/channel_list/channel_list_item.dart
Normal file
@@ -0,0 +1,18 @@
|
||||
import 'package:flutter/material.dart';
|
||||
|
||||
import '../../models/channel.dart';
|
||||
|
||||
class ChannelListItem extends StatelessWidget {
|
||||
const ChannelListItem({
|
||||
required this.channel,
|
||||
super.key,
|
||||
});
|
||||
|
||||
final Channel channel;
|
||||
|
||||
@override
|
||||
Widget build(BuildContext context) => ListTile(
|
||||
leading: const SizedBox(width: 40, height: 40, child: const Placeholder()),
|
||||
title: Text(channel.internalName),
|
||||
);
|
||||
}
|
||||
64
flutter/lib/pages/channel_list/root.dart
Normal file
64
flutter/lib/pages/channel_list/root.dart
Normal file
@@ -0,0 +1,64 @@
|
||||
import 'package:flutter/material.dart';
|
||||
import 'package:infinite_scroll_pagination/infinite_scroll_pagination.dart';
|
||||
import 'package:provider/provider.dart';
|
||||
import 'package:simplecloudnotifier/api/api_client.dart';
|
||||
import 'package:simplecloudnotifier/models/channel.dart';
|
||||
|
||||
import '../../state/user_account.dart';
|
||||
import 'channel_list_item.dart';
|
||||
|
||||
class ChannelRootPage extends StatefulWidget {
|
||||
const ChannelRootPage({super.key});
|
||||
|
||||
@override
|
||||
State<ChannelRootPage> createState() => _ChannelRootPageState();
|
||||
}
|
||||
|
||||
class _ChannelRootPageState extends State<ChannelRootPage> {
|
||||
final PagingController<int, Channel> _pagingController = PagingController(firstPageKey: 0);
|
||||
|
||||
late UserAccount userAcc;
|
||||
|
||||
@override
|
||||
void initState() {
|
||||
_pagingController.addPageRequestListener((pageKey) {
|
||||
_fetchPage(pageKey);
|
||||
});
|
||||
super.initState();
|
||||
}
|
||||
|
||||
@override
|
||||
void dispose() {
|
||||
_pagingController.dispose();
|
||||
super.dispose();
|
||||
}
|
||||
|
||||
Future<void> _fetchPage(int pageKey) async {
|
||||
final acc = Provider.of<UserAccount>(context, listen: false);
|
||||
|
||||
if (acc.auth == null) {
|
||||
_pagingController.error = 'Not logged in';
|
||||
return;
|
||||
}
|
||||
|
||||
try {
|
||||
final items = await APIClient.getChannelList(acc.auth!, ChannelSelector.all);
|
||||
|
||||
_pagingController.appendLastPage(items);
|
||||
} catch (error) {
|
||||
_pagingController.error = error;
|
||||
}
|
||||
}
|
||||
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
return PagedListView<int, Channel>(
|
||||
pagingController: _pagingController,
|
||||
builderDelegate: PagedChildBuilderDelegate<Channel>(
|
||||
itemBuilder: (context, item, index) => ChannelListItem(
|
||||
channel: item,
|
||||
),
|
||||
),
|
||||
);
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user