mirror of
https://gitlab.com/veilid/veilidchat.git
synced 2025-06-05 13:19:22 -04:00
refactor
This commit is contained in:
parent
2ccad50f9a
commit
360ba436f8
29 changed files with 501 additions and 317 deletions
|
@ -20,13 +20,12 @@ part 'router_cubit.freezed.dart';
|
|||
part 'router_cubit.g.dart';
|
||||
|
||||
final _rootNavKey = GlobalKey<NavigatorState>(debugLabel: 'rootNavKey');
|
||||
final _homeNavKey = GlobalKey<NavigatorState>(debugLabel: 'homeNavKey');
|
||||
|
||||
@freezed
|
||||
class RouterState with _$RouterState {
|
||||
const factory RouterState(
|
||||
{required bool hasAnyAccount,
|
||||
required bool hasActiveChat}) = _RouterState;
|
||||
const factory RouterState({
|
||||
required bool hasAnyAccount,
|
||||
}) = _RouterState;
|
||||
|
||||
factory RouterState.fromJson(dynamic json) =>
|
||||
_$RouterStateFromJson(json as Map<String, dynamic>);
|
||||
|
@ -36,7 +35,6 @@ class RouterCubit extends Cubit<RouterState> {
|
|||
RouterCubit(AccountRepository accountRepository)
|
||||
: super(RouterState(
|
||||
hasAnyAccount: accountRepository.getLocalAccounts().isNotEmpty,
|
||||
hasActiveChat: false,
|
||||
)) {
|
||||
// Subscribe to repository streams
|
||||
_accountRepositorySubscription = accountRepository.stream.listen((event) {
|
||||
|
@ -52,10 +50,6 @@ class RouterCubit extends Cubit<RouterState> {
|
|||
});
|
||||
}
|
||||
|
||||
void setHasActiveChat(bool active) {
|
||||
emit(state.copyWith(hasActiveChat: active));
|
||||
}
|
||||
|
||||
@override
|
||||
Future<void> close() async {
|
||||
await _accountRepositorySubscription.cancel();
|
||||
|
@ -64,19 +58,9 @@ class RouterCubit extends Cubit<RouterState> {
|
|||
|
||||
/// Our application routes
|
||||
List<RouteBase> get routes => [
|
||||
ShellRoute(
|
||||
navigatorKey: _homeNavKey,
|
||||
builder: (context, state, child) => HomeShell(child: child),
|
||||
routes: [
|
||||
GoRoute(
|
||||
path: '/',
|
||||
builder: (context, state) => const HomeAccountReadyMain(),
|
||||
),
|
||||
GoRoute(
|
||||
path: '/chat',
|
||||
builder: (context, state) => const HomeAccountReadyChat(),
|
||||
),
|
||||
],
|
||||
GoRoute(
|
||||
path: '/',
|
||||
builder: (context, state) => const HomeScreen(),
|
||||
),
|
||||
GoRoute(
|
||||
path: '/edit_account',
|
||||
|
@ -116,31 +100,6 @@ class RouterCubit extends Cubit<RouterState> {
|
|||
if (!state.hasAnyAccount) {
|
||||
return '/new_account';
|
||||
}
|
||||
if (responsiveVisibility(
|
||||
context: context,
|
||||
tablet: false,
|
||||
tabletLandscape: false,
|
||||
desktop: false)) {
|
||||
if (state.hasActiveChat) {
|
||||
return '/chat';
|
||||
}
|
||||
}
|
||||
return null;
|
||||
case '/chat':
|
||||
if (!state.hasAnyAccount) {
|
||||
return '/new_account';
|
||||
}
|
||||
if (responsiveVisibility(
|
||||
context: context,
|
||||
tablet: false,
|
||||
tabletLandscape: false,
|
||||
desktop: false)) {
|
||||
if (!state.hasActiveChat) {
|
||||
return '/';
|
||||
}
|
||||
} else {
|
||||
return '/';
|
||||
}
|
||||
return null;
|
||||
case '/new_account':
|
||||
return null;
|
||||
|
|
|
@ -21,7 +21,6 @@ RouterState _$RouterStateFromJson(Map<String, dynamic> json) {
|
|||
/// @nodoc
|
||||
mixin _$RouterState {
|
||||
bool get hasAnyAccount => throw _privateConstructorUsedError;
|
||||
bool get hasActiveChat => throw _privateConstructorUsedError;
|
||||
|
||||
Map<String, dynamic> toJson() => throw _privateConstructorUsedError;
|
||||
@JsonKey(ignore: true)
|
||||
|
@ -35,7 +34,7 @@ abstract class $RouterStateCopyWith<$Res> {
|
|||
RouterState value, $Res Function(RouterState) then) =
|
||||
_$RouterStateCopyWithImpl<$Res, RouterState>;
|
||||
@useResult
|
||||
$Res call({bool hasAnyAccount, bool hasActiveChat});
|
||||
$Res call({bool hasAnyAccount});
|
||||
}
|
||||
|
||||
/// @nodoc
|
||||
|
@ -52,17 +51,12 @@ class _$RouterStateCopyWithImpl<$Res, $Val extends RouterState>
|
|||
@override
|
||||
$Res call({
|
||||
Object? hasAnyAccount = null,
|
||||
Object? hasActiveChat = null,
|
||||
}) {
|
||||
return _then(_value.copyWith(
|
||||
hasAnyAccount: null == hasAnyAccount
|
||||
? _value.hasAnyAccount
|
||||
: hasAnyAccount // ignore: cast_nullable_to_non_nullable
|
||||
as bool,
|
||||
hasActiveChat: null == hasActiveChat
|
||||
? _value.hasActiveChat
|
||||
: hasActiveChat // ignore: cast_nullable_to_non_nullable
|
||||
as bool,
|
||||
) as $Val);
|
||||
}
|
||||
}
|
||||
|
@ -75,7 +69,7 @@ abstract class _$$RouterStateImplCopyWith<$Res>
|
|||
__$$RouterStateImplCopyWithImpl<$Res>;
|
||||
@override
|
||||
@useResult
|
||||
$Res call({bool hasAnyAccount, bool hasActiveChat});
|
||||
$Res call({bool hasAnyAccount});
|
||||
}
|
||||
|
||||
/// @nodoc
|
||||
|
@ -90,17 +84,12 @@ class __$$RouterStateImplCopyWithImpl<$Res>
|
|||
@override
|
||||
$Res call({
|
||||
Object? hasAnyAccount = null,
|
||||
Object? hasActiveChat = null,
|
||||
}) {
|
||||
return _then(_$RouterStateImpl(
|
||||
hasAnyAccount: null == hasAnyAccount
|
||||
? _value.hasAnyAccount
|
||||
: hasAnyAccount // ignore: cast_nullable_to_non_nullable
|
||||
as bool,
|
||||
hasActiveChat: null == hasActiveChat
|
||||
? _value.hasActiveChat
|
||||
: hasActiveChat // ignore: cast_nullable_to_non_nullable
|
||||
as bool,
|
||||
));
|
||||
}
|
||||
}
|
||||
|
@ -108,20 +97,17 @@ class __$$RouterStateImplCopyWithImpl<$Res>
|
|||
/// @nodoc
|
||||
@JsonSerializable()
|
||||
class _$RouterStateImpl with DiagnosticableTreeMixin implements _RouterState {
|
||||
const _$RouterStateImpl(
|
||||
{required this.hasAnyAccount, required this.hasActiveChat});
|
||||
const _$RouterStateImpl({required this.hasAnyAccount});
|
||||
|
||||
factory _$RouterStateImpl.fromJson(Map<String, dynamic> json) =>
|
||||
_$$RouterStateImplFromJson(json);
|
||||
|
||||
@override
|
||||
final bool hasAnyAccount;
|
||||
@override
|
||||
final bool hasActiveChat;
|
||||
|
||||
@override
|
||||
String toString({DiagnosticLevel minLevel = DiagnosticLevel.info}) {
|
||||
return 'RouterState(hasAnyAccount: $hasAnyAccount, hasActiveChat: $hasActiveChat)';
|
||||
return 'RouterState(hasAnyAccount: $hasAnyAccount)';
|
||||
}
|
||||
|
||||
@override
|
||||
|
@ -129,8 +115,7 @@ class _$RouterStateImpl with DiagnosticableTreeMixin implements _RouterState {
|
|||
super.debugFillProperties(properties);
|
||||
properties
|
||||
..add(DiagnosticsProperty('type', 'RouterState'))
|
||||
..add(DiagnosticsProperty('hasAnyAccount', hasAnyAccount))
|
||||
..add(DiagnosticsProperty('hasActiveChat', hasActiveChat));
|
||||
..add(DiagnosticsProperty('hasAnyAccount', hasAnyAccount));
|
||||
}
|
||||
|
||||
@override
|
||||
|
@ -139,14 +124,12 @@ class _$RouterStateImpl with DiagnosticableTreeMixin implements _RouterState {
|
|||
(other.runtimeType == runtimeType &&
|
||||
other is _$RouterStateImpl &&
|
||||
(identical(other.hasAnyAccount, hasAnyAccount) ||
|
||||
other.hasAnyAccount == hasAnyAccount) &&
|
||||
(identical(other.hasActiveChat, hasActiveChat) ||
|
||||
other.hasActiveChat == hasActiveChat));
|
||||
other.hasAnyAccount == hasAnyAccount));
|
||||
}
|
||||
|
||||
@JsonKey(ignore: true)
|
||||
@override
|
||||
int get hashCode => Object.hash(runtimeType, hasAnyAccount, hasActiveChat);
|
||||
int get hashCode => Object.hash(runtimeType, hasAnyAccount);
|
||||
|
||||
@JsonKey(ignore: true)
|
||||
@override
|
||||
|
@ -163,9 +146,8 @@ class _$RouterStateImpl with DiagnosticableTreeMixin implements _RouterState {
|
|||
}
|
||||
|
||||
abstract class _RouterState implements RouterState {
|
||||
const factory _RouterState(
|
||||
{required final bool hasAnyAccount,
|
||||
required final bool hasActiveChat}) = _$RouterStateImpl;
|
||||
const factory _RouterState({required final bool hasAnyAccount}) =
|
||||
_$RouterStateImpl;
|
||||
|
||||
factory _RouterState.fromJson(Map<String, dynamic> json) =
|
||||
_$RouterStateImpl.fromJson;
|
||||
|
@ -173,8 +155,6 @@ abstract class _RouterState implements RouterState {
|
|||
@override
|
||||
bool get hasAnyAccount;
|
||||
@override
|
||||
bool get hasActiveChat;
|
||||
@override
|
||||
@JsonKey(ignore: true)
|
||||
_$$RouterStateImplCopyWith<_$RouterStateImpl> get copyWith =>
|
||||
throw _privateConstructorUsedError;
|
||||
|
|
|
@ -9,11 +9,9 @@ part of 'router_cubit.dart';
|
|||
_$RouterStateImpl _$$RouterStateImplFromJson(Map<String, dynamic> json) =>
|
||||
_$RouterStateImpl(
|
||||
hasAnyAccount: json['has_any_account'] as bool,
|
||||
hasActiveChat: json['has_active_chat'] as bool,
|
||||
);
|
||||
|
||||
Map<String, dynamic> _$$RouterStateImplToJson(_$RouterStateImpl instance) =>
|
||||
<String, dynamic>{
|
||||
'has_any_account': instance.hasAnyAccount,
|
||||
'has_active_chat': instance.hasActiveChat,
|
||||
};
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue