Skip to content

#465_connecting_banner #586

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
wants to merge 2 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
324 changes: 189 additions & 135 deletions lib/widgets/app.dart
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think some of your code has been auto-formatted and this project doesn't use auto-formatting, so I think you should check that. If your editor or IDE automatically reformats the existing code, you'll want to turn that off.

Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import 'dart:async';

import 'snackbar.dart';
import 'package:flutter/foundation.dart';
import 'package:flutter/material.dart';
import 'package:flutter/scheduler.dart';
Expand All @@ -16,6 +16,8 @@ import 'recent_dm_conversations.dart';
import 'store.dart';
import 'subscription_list.dart';
import 'text.dart';
import 'package:connectivity_plus/connectivity_plus.dart';
import 'package:flutter/material.dart';

class ZulipApp extends StatelessWidget {
const ZulipApp({super.key, this.navigatorObservers});
Expand Down Expand Up @@ -113,49 +115,64 @@ class ZulipApp extends StatelessWidget {
);

return GlobalStoreWidget(
child: Builder(builder: (context) {
final globalStore = GlobalStoreWidget.of(context);
// TODO(#524) choose initial account as last one used
final initialAccountId = globalStore.accounts.firstOrNull?.id;
return MaterialApp(
title: 'Zulip',
localizationsDelegates: ZulipLocalizations.localizationsDelegates,
supportedLocales: ZulipLocalizations.supportedLocales,
theme: theme,

navigatorKey: navigatorKey,
navigatorObservers: navigatorObservers ?? const [],
builder: (BuildContext context, Widget? child) {
if (!ready.value) {
SchedulerBinding.instance.addPostFrameCallback(
(_) => _declareReady());
}
GlobalLocalizations.zulipLocalizations = ZulipLocalizations.of(context);
return child!;
},

// We use onGenerateInitialRoutes for the real work of specifying the
// initial nav state. To do that we need [MaterialApp] to decide to
// build a [Navigator]... which means specifying either `home`, `routes`,
// `onGenerateRoute`, or `onUnknownRoute`. Make it `onGenerateRoute`.
// It never actually gets called, though: `onGenerateInitialRoutes`
// handles startup, and then we always push whole routes with methods
// like [Navigator.push], never mere names as with [Navigator.pushNamed].
onGenerateRoute: (_) => null,

onGenerateInitialRoutes: (_) {
return [
MaterialWidgetRoute(page: const ChooseAccountPage()),
if (initialAccountId != null) ...[
HomePage.buildRoute(accountId: initialAccountId),
InboxPage.buildRoute(accountId: initialAccountId),
],
];
});
child: Builder(builder: (context) {
final globalStore = GlobalStoreWidget.of(context);
// TODO(#524) choose initial account as last one used
final initialAccountId = globalStore.accounts.firstOrNull?.id;
return MaterialApp(
title: 'Zulip',
localizationsDelegates: ZulipLocalizations.localizationsDelegates,
supportedLocales: ZulipLocalizations.supportedLocales,
theme: theme,

navigatorKey: navigatorKey,
navigatorObservers: navigatorObservers ?? const [],
builder: (BuildContext context, Widget? child) {
if (!ready.value) {
SchedulerBinding.instance.addPostFrameCallback(
(_) => _declareReady());
}
GlobalLocalizations.zulipLocalizations = ZulipLocalizations.of(context);
return child!;
},

// We use onGenerateInitialRoutes for the real work of specifying the
// initial nav state. To do that we need [MaterialApp] to decide to
// build a [Navigator]... which means specifying either `home`, `routes`,
// `onGenerateRoute`, or `onUnknownRoute`. Make it `onGenerateRoute`.
// It never actually gets called, though: `onGenerateInitialRoutes`
// handles startup, and then we always push whole routes with methods
// like [Navigator.push], never mere names as with [Navigator.pushNamed].
onGenerateRoute: (_) => null,

onGenerateInitialRoutes: (_) {
return [
MaterialWidgetRoute(page: const ChooseAccountPage()),
if (initialAccountId != null) ...[
HomePage.buildRoute(accountId: initialAccountId),
InboxPage.buildRoute(accountId: initialAccountId),
],
];
});
}));
}
}
















/// The Zulip "brand color", a purplish blue.
///
/// This is chosen as the sRGB midpoint of the Zulip logo's gradient.
Expand All @@ -166,18 +183,18 @@ class ChooseAccountPage extends StatelessWidget {
const ChooseAccountPage({super.key});

Widget _buildAccountItem(
BuildContext context, {
required int accountId,
required Widget title,
Widget? subtitle,
}) {
BuildContext context, {
required int accountId,
required Widget title,
Widget? subtitle,
}) {
return Card(
clipBehavior: Clip.hardEdge,
child: ListTile(
title: title,
subtitle: subtitle,
onTap: () => Navigator.push(context,
HomePage.buildRoute(accountId: accountId))));
clipBehavior: Clip.hardEdge,
child: ListTile(
title: title,
subtitle: subtitle,
onTap: () => Navigator.push(context,
HomePage.buildRoute(accountId: accountId))));
}

@override
Expand All @@ -186,27 +203,31 @@ class ChooseAccountPage extends StatelessWidget {
assert(!PerAccountStoreWidget.debugExistsOf(context));
final globalStore = GlobalStoreWidget.of(context);
return Scaffold(
appBar: AppBar(
title: Text(zulipLocalizations.chooseAccountPageTitle),
actions: const [ChooseAccountPageOverflowButton()]),
body: SafeArea(
minimum: const EdgeInsets.all(8),
child: Center(
child: ConstrainedBox(
constraints: const BoxConstraints(maxWidth: 400),
child: Column(mainAxisAlignment: MainAxisAlignment.center, children: [
for (final (:accountId, :account) in globalStore.accountEntries)
_buildAccountItem(context,
accountId: accountId,
title: Text(account.realmUrl.toString()),
subtitle: Text(account.email)),
const SizedBox(height: 12),
ElevatedButton(
onPressed: () => Navigator.push(context,
AddAccountPage.buildRoute()),
child: Text(zulipLocalizations.chooseAccountButtonAddAnAccount)),
]))),
));
appBar: AppBar(
title: Text(zulipLocalizations.chooseAccountPageTitle),
actions: const [ChooseAccountPageOverflowButton()]),
body: SafeArea(
minimum: const EdgeInsets.all(8),
child: Center(
child: ConstrainedBox(
constraints: const BoxConstraints(maxWidth: 400),
child: Column(mainAxisAlignment: MainAxisAlignment.center, children: [
for (final (:accountId, :account) in globalStore.accountEntries)
_buildAccountItem(context,
accountId: accountId,
title: Text(account.realmUrl.toString()),
subtitle: Text(account.email)),
const SizedBox(height: 12),
ElevatedButton(
onPressed: () => Navigator.push(context,
AddAccountPage.buildRoute()),
child: Text(zulipLocalizations.chooseAccountButtonAddAnAccount)),
SizedBox(
height: 40, // Adjust the height as needed
child: SnackBarPage(),
),
]))),
));
}
}

Expand All @@ -218,88 +239,121 @@ class ChooseAccountPageOverflowButton extends StatelessWidget {
@override
Widget build(BuildContext context) {
return PopupMenuButton<ChooseAccountPageOverflowMenuItem>(
itemBuilder: (BuildContext context) => const [
PopupMenuItem(
value: ChooseAccountPageOverflowMenuItem.aboutZulip,
child: Text('About Zulip')),
],
onSelected: (item) {
switch (item) {
case ChooseAccountPageOverflowMenuItem.aboutZulip:
Navigator.push(context, AboutZulipPage.buildRoute(context));
}
});
itemBuilder: (BuildContext context) => const [
PopupMenuItem(
value: ChooseAccountPageOverflowMenuItem.aboutZulip,
child: Text('About Zulip')),
],
onSelected: (item) {
switch (item) {
case ChooseAccountPageOverflowMenuItem.aboutZulip:
Navigator.push(context, AboutZulipPage.buildRoute(context));
}
});
}
}









class HomePage extends StatelessWidget {
const HomePage({super.key});

static Route<void> buildRoute({required int accountId}) {
return MaterialAccountWidgetRoute(accountId: accountId,
page: const HomePage());
page: const HomePage());
}

@override
Widget build(BuildContext context) {
final store = PerAccountStoreWidget.of(context);
final zulipLocalizations = ZulipLocalizations.of(context);

InlineSpan bold(String text) => TextSpan(
text: text, style: const TextStyle(fontWeight: FontWeight.bold));
InlineSpan bold(String text) =>
TextSpan(
text: text, style: const TextStyle(fontWeight: FontWeight.bold));

int? testStreamId;
if (store.connection.realmUrl.origin == 'https://chat.zulip.org') {
testStreamId = 7; // i.e. `#test here`; TODO cut this scaffolding hack
}

return Scaffold(
appBar: AppBar(title: const Text("Home")),
body: Center(
child: Column(mainAxisAlignment: MainAxisAlignment.center, children: [
DefaultTextStyle.merge(
textAlign: TextAlign.center,
style: const TextStyle(fontSize: 18),
child: Column(children: [
const Text('🚧 Under construction 🚧'),
const SizedBox(height: 12),
Text.rich(TextSpan(
text: 'Connected to: ',
children: [bold(store.realmUrl.toString())])),
Text.rich(TextSpan(
text: 'Zulip server version: ',
children: [bold(store.zulipVersion)])),
Text(zulipLocalizations.subscribedToNStreams(store.subscriptions.length)),
])),
const SizedBox(height: 16),
ElevatedButton(
onPressed: () => Navigator.push(context,
MessageListPage.buildRoute(context: context,
narrow: const AllMessagesNarrow())),
child: Text(zulipLocalizations.allMessagesPageTitle)),
const SizedBox(height: 16),
ElevatedButton(
onPressed: () => Navigator.push(context,
InboxPage.buildRoute(context: context)),
child: const Text("Inbox")), // TODO(i18n)
const SizedBox(height: 16),
ElevatedButton(
onPressed: () => Navigator.push(context,
SubscriptionListPage.buildRoute(context: context)),
child: const Text("Subscribed streams")),
const SizedBox(height: 16),
ElevatedButton(
onPressed: () => Navigator.push(context,
RecentDmConversationsPage.buildRoute(context: context)),
child: Text(zulipLocalizations.recentDmConversationsPageTitle)),
if (testStreamId != null) ...[
const SizedBox(height: 16),
ElevatedButton(
onPressed: () => Navigator.push(context,
MessageListPage.buildRoute(context: context,
narrow: StreamNarrow(testStreamId!))),
child: const Text("#test here")), // scaffolding hack, see above
],
])));
}
}
appBar: AppBar(title: const Text("Home")),
body: SingleChildScrollView(
child: Center(
child: Column(

mainAxisAlignment: MainAxisAlignment.center,
children: [
DefaultTextStyle.merge(

textAlign: TextAlign.center,
style: const TextStyle(fontSize: 18),
child: Column(
children: [
const Text('🚧 Under construction 🚧'),
const SizedBox(height: 12),
Text.rich(TextSpan(
text: 'Connected to: ',
children: [bold(store.realmUrl.toString())])),
Text.rich(TextSpan(
text: 'Zulip server version: ',
children: [bold(store.zulipVersion)])),
Text(zulipLocalizations.subscribedToNStreams(store.subscriptions.length)),
]
)
),
const SizedBox(height: 16),
ElevatedButton(
onPressed: () => Navigator.push(context,
MessageListPage.buildRoute(context: context,
narrow: const AllMessagesNarrow())),
child: Text(zulipLocalizations.allMessagesPageTitle)
),
const SizedBox(height: 16),
ElevatedButton(
onPressed: () => Navigator.push(context,
InboxPage.buildRoute(context: context)),
child: const Text("Inbox")
), // TODO(i18n)
const SizedBox(height: 16),
ElevatedButton(
onPressed: () => Navigator.push(context,
SubscriptionListPage.buildRoute(context: context)),
child: const Text("Subscribed streams")
),
const SizedBox(height: 16),
ElevatedButton(
onPressed: () => Navigator.push(context,
RecentDmConversationsPage.buildRoute(context: context)),
child: Text(zulipLocalizations.recentDmConversationsPageTitle)
),
if (testStreamId != null) ...[
const SizedBox(height: 16),
ElevatedButton(
onPressed: () => Navigator.push(context,
MessageListPage.buildRoute(context: context,
narrow: StreamNarrow(testStreamId!))),
child: const Text("#test here")
),

// Wrap SnackBarPage in a SizedBox to constrain its size
SizedBox(
height: 40, // Adjust the height as needed
child: SnackBarPage(), // class which is imported from snackbar.dart file
),
],
]
)
)
)
);


}}
Loading