Browse Source

neon: get active account from Provider

pull/338/head
Nikolas Rimikis 2 years ago
parent
commit
8402e3877a
No known key found for this signature in database
GPG Key ID: 85ED1DE9786A4FF2
  1. 22
      packages/neon/neon/lib/src/pages/home.dart
  2. 1
      packages/neon/neon/lib/src/router.dart

22
packages/neon/neon/lib/src/pages/home.dart

@ -4,12 +4,9 @@ const kQuickBarWidth = kAvatarSize + 20;
class HomePage extends StatefulWidget { class HomePage extends StatefulWidget {
const HomePage({ const HomePage({
required this.account,
super.key, super.key,
}); });
final Account account;
@override @override
State<HomePage> createState() => _HomePageState(); State<HomePage> createState() => _HomePageState();
} }
@ -19,6 +16,7 @@ class _HomePageState extends State<HomePage> {
final _scaffoldKey = GlobalKey<ScaffoldState>(); final _scaffoldKey = GlobalKey<ScaffoldState>();
final drawerScrollController = ScrollController(); final drawerScrollController = ScrollController();
late Account _account;
late GlobalOptions _globalOptions; late GlobalOptions _globalOptions;
late AccountsBloc _accountsBloc; late AccountsBloc _accountsBloc;
late AppsBloc _appsBloc; late AppsBloc _appsBloc;
@ -27,11 +25,11 @@ class _HomePageState extends State<HomePage> {
@override @override
void initState() { void initState() {
super.initState(); super.initState();
_globalOptions = Provider.of<GlobalOptions>(context, listen: false); _globalOptions = Provider.of<GlobalOptions>(context, listen: false);
_accountsBloc = Provider.of<AccountsBloc>(context, listen: false); _accountsBloc = Provider.of<AccountsBloc>(context, listen: false);
_appsBloc = _accountsBloc.getAppsBloc(widget.account); _account = _accountsBloc.activeAccount.value!;
_capabilitiesBloc = _accountsBloc.getCapabilitiesBloc(widget.account); _appsBloc = _accountsBloc.getAppsBloc(_account);
_capabilitiesBloc = _accountsBloc.getCapabilitiesBloc(_account);
_appsBloc.openNotifications.listen((final _) async { _appsBloc.openNotifications.listen((final _) async {
final notificationsAppImplementation = _appsBloc.notificationsAppImplementation.valueOrNull; final notificationsAppImplementation = _appsBloc.notificationsAppImplementation.valueOrNull;
@ -61,9 +59,9 @@ class _HomePageState extends State<HomePage> {
]) { ]) {
try { try {
final (supported, _) = switch (id) { final (supported, _) = switch (id) {
'core' => await widget.account.client.core.isSupported(result.data), 'core' => await _account.client.core.isSupported(result.data),
'news' => await widget.account.client.news.isSupported(), 'news' => await _account.client.news.isSupported(),
'notes' => await widget.account.client.notes.isSupported(result.data), 'notes' => await _account.client.notes.isSupported(result.data),
_ => (true, null), _ => (true, null),
}; };
if (supported || !mounted) { if (supported || !mounted) {
@ -92,7 +90,7 @@ class _HomePageState extends State<HomePage> {
Future _checkMaintenanceMode() async { Future _checkMaintenanceMode() async {
try { try {
final status = await widget.account.client.core.getStatus(); final status = await _account.client.core.getStatus();
if (status.maintenance) { if (status.maintenance) {
if (!mounted) { if (!mounted) {
return; return;
@ -207,7 +205,7 @@ class _HomePageState extends State<HomePage> {
builder: (final context) { builder: (final context) {
if (accountsSnapshot.hasData) { if (accountsSnapshot.hasData) {
final accounts = accountsSnapshot.data!; final accounts = accountsSnapshot.data!;
final account = accounts.find(widget.account.id)!; final account = accounts.find(_account.id)!;
final isQuickBar = navigationMode == NavigationMode.quickBar; final isQuickBar = navigationMode == NavigationMode.quickBar;
final drawer = Drawer( final drawer = Drawer(
@ -303,7 +301,7 @@ class _HomePageState extends State<HomePage> {
dropdownColor: Theme.of(context).colorScheme.primary, dropdownColor: Theme.of(context).colorScheme.primary,
iconEnabledColor: iconEnabledColor:
Theme.of(context).colorScheme.onBackground, Theme.of(context).colorScheme.onBackground,
value: widget.account.id, value: _account.id,
items: accounts items: accounts
.map<DropdownMenuItem<String>>( .map<DropdownMenuItem<String>>(
(final account) => DropdownMenuItem<String>( (final account) => DropdownMenuItem<String>(

1
packages/neon/neon/lib/src/router.dart

@ -33,7 +33,6 @@ class AppRouter extends RouterDelegate<Account> with ChangeNotifier, PopNavigato
name: 'home', name: 'home',
child: HomePage( child: HomePage(
key: Key(currentConfiguration!.id), key: Key(currentConfiguration!.id),
account: currentConfiguration!,
), ),
), ),
], ],

Loading…
Cancel
Save