|
| 1 | +import 'package:flutter/material.dart'; |
| 2 | +import 'package:flutter_gen/gen_l10n/zulip_localizations.dart'; |
| 3 | + |
| 4 | +import '../api/model/model.dart'; |
| 5 | +import '../model/narrow.dart'; |
| 6 | +import 'icons.dart'; |
| 7 | +import 'message_list.dart'; |
| 8 | +import 'page.dart'; |
| 9 | +import 'store.dart'; |
| 10 | + |
| 11 | +class ChannelListPage extends StatelessWidget { |
| 12 | + const ChannelListPage({super.key}); |
| 13 | + |
| 14 | + static Route<void> buildRoute({int? accountId, BuildContext? context}) { |
| 15 | + return MaterialAccountWidgetRoute(accountId: accountId, context: context, |
| 16 | + page: const ChannelListPage()); |
| 17 | + } |
| 18 | + |
| 19 | + @override |
| 20 | + Widget build(BuildContext context) { |
| 21 | + final store = PerAccountStoreWidget.of(context); |
| 22 | + final zulipLocalizations = ZulipLocalizations.of(context); |
| 23 | + final streams = store.streams.values.toList(); |
| 24 | + return Scaffold( |
| 25 | + appBar: AppBar(title: Text(zulipLocalizations.channelListPageTitle)), |
| 26 | + body: SafeArea( |
| 27 | + child: ListView.builder( |
| 28 | + itemCount: streams.length, |
| 29 | + itemBuilder: (context, index) => ChannelItem(stream: streams[index])))); |
| 30 | + } |
| 31 | +} |
| 32 | + |
| 33 | +@visibleForTesting |
| 34 | +class ChannelItem extends StatelessWidget { |
| 35 | + const ChannelItem({super.key, required this.stream}); |
| 36 | + |
| 37 | + final ZulipStream stream; |
| 38 | + |
| 39 | + @override |
| 40 | + Widget build(BuildContext context) { |
| 41 | + return Material( |
| 42 | + color: Colors.white, |
| 43 | + child: InkWell( |
| 44 | + onTap: () => Navigator.push(context, MessageListPage.buildRoute(context: context, |
| 45 | + narrow: ChannelNarrow(stream.streamId))), |
| 46 | + child: Padding( |
| 47 | + padding: const EdgeInsets.symmetric(vertical: 8, horizontal: 16), |
| 48 | + child: Row(children: [ |
| 49 | + Icon(size: 16, iconDataForStream(stream)), |
| 50 | + const SizedBox(width: 8), |
| 51 | + Expanded(child: Column( |
| 52 | + crossAxisAlignment: CrossAxisAlignment.start, |
| 53 | + mainAxisAlignment: MainAxisAlignment.spaceBetween, |
| 54 | + children: [ |
| 55 | + Text(stream.name, |
| 56 | + style: const TextStyle( |
| 57 | + fontSize: 18, |
| 58 | + height: (20 / 18), |
| 59 | + // TODO(#95) need dark-theme color |
| 60 | + color: Color(0xFF262626)), |
| 61 | + maxLines: 1, |
| 62 | + overflow: TextOverflow.ellipsis), |
| 63 | + if (stream.description.isNotEmpty) Text( |
| 64 | + stream.description, |
| 65 | + style: const TextStyle( |
| 66 | + fontSize: 12, |
| 67 | + // TODO(#95) need dark-theme color |
| 68 | + color: Color(0xCC262626)), |
| 69 | + maxLines: 1, |
| 70 | + overflow: TextOverflow.ellipsis), |
| 71 | + ])), |
| 72 | + ])))); |
| 73 | + } |
| 74 | +} |
0 commit comments