mirror of
https://gitlab.com/veilid/veilidchat.git
synced 2025-05-13 03:32:22 -04:00
refactor
This commit is contained in:
parent
2ccad50f9a
commit
360ba436f8
29 changed files with 501 additions and 317 deletions
37
lib/layout/home/active_account_page_controller_wrapper.dart
Normal file
37
lib/layout/home/active_account_page_controller_wrapper.dart
Normal file
|
@ -0,0 +1,37 @@
|
|||
import 'dart:async';
|
||||
|
||||
import 'package:async_tools/async_tools.dart';
|
||||
import 'package:flutter/material.dart';
|
||||
import 'package:provider/provider.dart';
|
||||
import 'package:veilid_support/veilid_support.dart';
|
||||
|
||||
import '../../account_manager/account_manager.dart';
|
||||
|
||||
class ActiveAccountPageControllerWrapper {
|
||||
ActiveAccountPageControllerWrapper(Locator locator, int initialPage) {
|
||||
pageController = PageController(initialPage: initialPage, keepPage: false);
|
||||
|
||||
final activeLocalAccountCubit = locator<ActiveLocalAccountCubit>();
|
||||
_subscription =
|
||||
activeLocalAccountCubit.stream.listen((activeLocalAccountRecordKey) {
|
||||
singleFuture(this, () async {
|
||||
final localAccounts = locator<LocalAccountsCubit>().state;
|
||||
final activeIndex = localAccounts.indexWhere(
|
||||
(x) => x.superIdentity.recordKey == activeLocalAccountRecordKey);
|
||||
if (pageController.page == activeIndex) {
|
||||
return;
|
||||
}
|
||||
await pageController.animateToPage(activeIndex,
|
||||
duration: const Duration(milliseconds: 250),
|
||||
curve: Curves.fastOutSlowIn);
|
||||
});
|
||||
});
|
||||
}
|
||||
|
||||
void dispose() {
|
||||
unawaited(_subscription.cancel());
|
||||
}
|
||||
|
||||
late PageController pageController;
|
||||
late StreamSubscription<TypedKey?> _subscription;
|
||||
}
|
Loading…
Add table
Add a link
Reference in a new issue