forked from zulip/zulip-flutter
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
channel_list: Setup "All Channels" page
Fixes parts of zulip#188
- Loading branch information
Showing
5 changed files
with
185 additions
and
2 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,74 @@ | ||
import 'package:flutter/material.dart'; | ||
import 'package:flutter_gen/gen_l10n/zulip_localizations.dart'; | ||
|
||
import '../api/model/model.dart'; | ||
import '../model/narrow.dart'; | ||
import 'icons.dart'; | ||
import 'message_list.dart'; | ||
import 'page.dart'; | ||
import 'store.dart'; | ||
|
||
class ChannelListPage extends StatelessWidget { | ||
const ChannelListPage({super.key}); | ||
|
||
static Route<void> buildRoute({int? accountId, BuildContext? context}) { | ||
return MaterialAccountWidgetRoute(accountId: accountId, context: context, | ||
page: const ChannelListPage()); | ||
} | ||
|
||
@override | ||
Widget build(BuildContext context) { | ||
final store = PerAccountStoreWidget.of(context); | ||
final zulipLocalizations = ZulipLocalizations.of(context); | ||
final streams = store.streams.values.toList(); | ||
return Scaffold( | ||
appBar: AppBar(title: Text(zulipLocalizations.channelListPageTitle)), | ||
body: SafeArea( | ||
child: ListView.builder( | ||
itemCount: streams.length, | ||
itemBuilder: (context, index) => ChannelItem(stream: streams[index])))); | ||
} | ||
} | ||
|
||
@visibleForTesting | ||
class ChannelItem extends StatelessWidget { | ||
const ChannelItem({super.key, required this.stream}); | ||
|
||
final ZulipStream stream; | ||
|
||
@override | ||
Widget build(BuildContext context) { | ||
return Material( | ||
color: Colors.white, | ||
child: InkWell( | ||
onTap: () => Navigator.push(context, MessageListPage.buildRoute(context: context, | ||
narrow: ChannelNarrow(stream.streamId))), | ||
child: Padding( | ||
padding: const EdgeInsets.symmetric(vertical: 8, horizontal: 16), | ||
child: Row(children: [ | ||
Icon(size: 16, iconDataForStream(stream)), | ||
const SizedBox(width: 8), | ||
Expanded(child: Column( | ||
crossAxisAlignment: CrossAxisAlignment.start, | ||
mainAxisAlignment: MainAxisAlignment.spaceBetween, | ||
children: [ | ||
Text(stream.name, | ||
style: const TextStyle( | ||
fontSize: 18, | ||
height: (20 / 18), | ||
// TODO(#95) need dark-theme color | ||
color: Color(0xFF262626)), | ||
maxLines: 1, | ||
overflow: TextOverflow.ellipsis), | ||
if (stream.description.isNotEmpty) Text( | ||
stream.description, | ||
style: const TextStyle( | ||
fontSize: 12, | ||
// TODO(#95) need dark-theme color | ||
color: Color(0xCC262626)), | ||
maxLines: 1, | ||
overflow: TextOverflow.ellipsis), | ||
])), | ||
])))); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,42 @@ | ||
import 'package:checks/checks.dart'; | ||
import 'package:flutter_test/flutter_test.dart'; | ||
import 'package:zulip/api/model/model.dart'; | ||
import 'package:zulip/widgets/channel_list.dart'; | ||
|
||
import '../model/binding.dart'; | ||
import '../example_data.dart' as eg; | ||
import 'test_app.dart'; | ||
|
||
void main() { | ||
TestZulipBinding.ensureInitialized(); | ||
|
||
Future<void> setupChannelListPage(WidgetTester tester, { | ||
required List<ZulipStream> streams, required List<Subscription> subscriptions}) async { | ||
addTearDown(testBinding.reset); | ||
final initialSnapshot = eg.initialSnapshot( | ||
subscriptions: subscriptions, | ||
streams: streams.toList(), | ||
); | ||
await testBinding.globalStore.add(eg.selfAccount, initialSnapshot); | ||
|
||
await tester.pumpWidget(TestZulipApp(accountId: eg.selfAccount.id, child: const ChannelListPage())); | ||
|
||
// global store, per-account store | ||
await tester.pumpAndSettle(); | ||
} | ||
|
||
int getItemCount() { | ||
return find.byType(ChannelItem).evaluate().length; | ||
} | ||
|
||
testWidgets('smoke', (tester) async { | ||
await setupChannelListPage(tester, streams: [], subscriptions: []); | ||
check(getItemCount()).equals(0); | ||
}); | ||
|
||
testWidgets('basic list', (tester) async { | ||
final streams = List.generate(3, (index) => eg.stream()); | ||
await setupChannelListPage(tester, streams: streams, subscriptions: []); | ||
check(getItemCount()).equals(3); | ||
}); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters