mirror of
https://gitlab.com/veilid/veilidchat.git
synced 2025-12-10 05:56:41 -05:00
refactor
This commit is contained in:
parent
b35b618a4d
commit
7cf44ef192
21 changed files with 338 additions and 82 deletions
|
|
@ -1 +0,0 @@
|
|||
|
||||
|
|
@ -1,30 +0,0 @@
|
|||
import 'package:flutter/material.dart';
|
||||
|
||||
class ContactsPage extends StatelessWidget {
|
||||
const ContactsPage({super.key});
|
||||
static const path = '/contacts';
|
||||
|
||||
@override
|
||||
Widget build(
|
||||
BuildContext context,
|
||||
) =>
|
||||
const Scaffold(
|
||||
body: Center(
|
||||
child: Column(
|
||||
mainAxisAlignment: MainAxisAlignment.center,
|
||||
children: [
|
||||
Text('Contacts Page'),
|
||||
// ElevatedButton(
|
||||
// onPressed: () async {
|
||||
// ref.watch(authNotifierProvider.notifier).login(
|
||||
// "myEmail",
|
||||
// "myPassword",
|
||||
// );
|
||||
// },
|
||||
// child: const Text("Login"),
|
||||
// ),
|
||||
],
|
||||
),
|
||||
),
|
||||
);
|
||||
}
|
||||
87
lib/layout/home/home.dart
Normal file
87
lib/layout/home/home.dart
Normal file
|
|
@ -0,0 +1,87 @@
|
|||
import 'package:fast_immutable_collections/fast_immutable_collections.dart';
|
||||
import 'package:flutter/material.dart';
|
||||
import 'package:flutter_bloc/flutter_bloc.dart';
|
||||
import 'package:veilid_support/veilid_support.dart';
|
||||
|
||||
import '../../account_manager/account_manager.dart';
|
||||
import '../../theme/theme.dart';
|
||||
import '../../tools/tools.dart';
|
||||
import 'home_account_invalid.dart';
|
||||
import 'home_account_locked.dart';
|
||||
import 'home_account_missing.dart';
|
||||
import 'home_account_ready.dart';
|
||||
import 'home_account_ready/home_account_ready.dart';
|
||||
|
||||
class HomePage extends StatefulWidget {
|
||||
const HomePage({super.key});
|
||||
|
||||
@override
|
||||
HomePageState createState() => HomePageState();
|
||||
}
|
||||
|
||||
class HomePageState extends State<HomePage> with TickerProviderStateMixin {
|
||||
final _unfocusNode = FocusNode();
|
||||
|
||||
@override
|
||||
void initState() {
|
||||
super.initState();
|
||||
|
||||
WidgetsBinding.instance.addPostFrameCallback((_) async {
|
||||
await changeWindowSetup(
|
||||
TitleBarStyle.normal, OrientationCapability.normal);
|
||||
});
|
||||
}
|
||||
|
||||
@override
|
||||
void dispose() {
|
||||
_unfocusNode.dispose();
|
||||
super.dispose();
|
||||
}
|
||||
|
||||
Widget buildWithLogin(BuildContext context, IList<LocalAccount> localAccounts,
|
||||
Typed<FixedEncodedString43>? activeUserLogin) {
|
||||
if (activeUserLogin == null) {
|
||||
// If no logged in user is active, show the loading panel
|
||||
return waitingPage(context);
|
||||
}
|
||||
|
||||
final accountInfo = AccountRepository.instance
|
||||
.getAccountInfo(accountMasterRecordKey: activeUserLogin)!;
|
||||
|
||||
switch (accountInfo.status) {
|
||||
case AccountInfoStatus.noAccount:
|
||||
return const HomeAccountMissing();
|
||||
case AccountInfoStatus.accountInvalid:
|
||||
return const HomeAccountInvalid();
|
||||
case AccountInfoStatus.accountLocked:
|
||||
return const HomeAccountLocked();
|
||||
case AccountInfoStatus.accountReady:
|
||||
return BlocProvider(
|
||||
create: (context) => AccountRecordCubit(
|
||||
record: accountInfo.activeAccountInfo!.accountRecord),
|
||||
child: context.watch<AccountRecordCubit>().state.builder(
|
||||
(context, account) => HomeAccountReady(
|
||||
localAccounts: localAccounts,
|
||||
activeUserLogin: activeUserLogin,
|
||||
activeAccountInfo: accountInfo.activeAccountInfo!,
|
||||
account: account)));
|
||||
}
|
||||
}
|
||||
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
final theme = Theme.of(context);
|
||||
final scale = theme.extension<ScaleScheme>()!;
|
||||
final activeUserLogin = context.watch<ActiveUserLoginCubit>().state;
|
||||
final localAccounts = context.watch<LocalAccountsCubit>().state;
|
||||
|
||||
return SafeArea(
|
||||
child: GestureDetector(
|
||||
onTap: () => FocusScope.of(context).requestFocus(_unfocusNode),
|
||||
child: DecoratedBox(
|
||||
decoration: BoxDecoration(
|
||||
color: scale.primaryScale.activeElementBackground),
|
||||
child:
|
||||
buildWithLogin(context, localAccounts, activeUserLogin))));
|
||||
}
|
||||
}
|
||||
32
lib/layout/home/home_account_invalid.dart
Normal file
32
lib/layout/home/home_account_invalid.dart
Normal file
|
|
@ -0,0 +1,32 @@
|
|||
import 'package:flutter/material.dart';
|
||||
|
||||
class HomeAccountInvalid extends StatefulWidget {
|
||||
const HomeAccountInvalid({super.key});
|
||||
|
||||
@override
|
||||
HomeAccountInvalidState createState() => HomeAccountInvalidState();
|
||||
}
|
||||
|
||||
class HomeAccountInvalidState extends State<HomeAccountInvalid> {
|
||||
@override
|
||||
void initState() {
|
||||
super.initState();
|
||||
}
|
||||
|
||||
@override
|
||||
void dispose() {
|
||||
super.dispose();
|
||||
}
|
||||
|
||||
@override
|
||||
Widget build(BuildContext context) => const Text('Account invalid');
|
||||
}
|
||||
// xxx: delete invalid account
|
||||
// Future.delayed(0.ms, () async {
|
||||
// await showErrorModal(context, translate('home.invalid_account_title'),
|
||||
// translate('home.invalid_account_text'));
|
||||
// // Delete account
|
||||
// await AccountRepository.instance.deleteLocalAccount(activeUserLogin);
|
||||
// // Switch to no active user login
|
||||
// await AccountRepository.instance.switchToAccount(null);
|
||||
// });
|
||||
23
lib/layout/home/home_account_locked.dart
Normal file
23
lib/layout/home/home_account_locked.dart
Normal file
|
|
@ -0,0 +1,23 @@
|
|||
import 'package:flutter/material.dart';
|
||||
|
||||
class HomeAccountLocked extends StatefulWidget {
|
||||
const HomeAccountLocked({super.key});
|
||||
|
||||
@override
|
||||
HomeAccountLockedState createState() => HomeAccountLockedState();
|
||||
}
|
||||
|
||||
class HomeAccountLockedState extends State<HomeAccountLocked> {
|
||||
@override
|
||||
void initState() {
|
||||
super.initState();
|
||||
}
|
||||
|
||||
@override
|
||||
void dispose() {
|
||||
super.dispose();
|
||||
}
|
||||
|
||||
@override
|
||||
Widget build(BuildContext context) => const Text('Account locked');
|
||||
}
|
||||
33
lib/layout/home/home_account_missing.dart
Normal file
33
lib/layout/home/home_account_missing.dart
Normal file
|
|
@ -0,0 +1,33 @@
|
|||
import 'package:flutter/material.dart';
|
||||
|
||||
class HomeAccountMissing extends StatefulWidget {
|
||||
const HomeAccountMissing({super.key});
|
||||
|
||||
@override
|
||||
HomeAccountMissingState createState() => HomeAccountMissingState();
|
||||
}
|
||||
|
||||
class HomeAccountMissingState extends State<HomeAccountMissing> {
|
||||
@override
|
||||
void initState() {
|
||||
super.initState();
|
||||
}
|
||||
|
||||
@override
|
||||
void dispose() {
|
||||
super.dispose();
|
||||
}
|
||||
|
||||
@override
|
||||
Widget build(BuildContext context) => const Text('Account missing');
|
||||
}
|
||||
|
||||
// xxx click to delete missing account or add to postframecallback
|
||||
// Future.delayed(0.ms, () async {
|
||||
// await showErrorModal(context, translate('home.missing_account_title'),
|
||||
// translate('home.missing_account_text'));
|
||||
// // Delete account
|
||||
// await AccountRepository.instance.deleteLocalAccount(activeUserLogin);
|
||||
// // Switch to no active user login
|
||||
// await AccountRepository.instance.switchToAccount(null);
|
||||
// });
|
||||
|
|
@ -1,7 +1,7 @@
|
|||
import 'package:flutter/material.dart';
|
||||
|
||||
import '../chat/chat.dart';
|
||||
import '../tools/tools.dart';
|
||||
import '../../../chat/chat.dart';
|
||||
import '../../../tools/tools.dart';
|
||||
|
||||
class ChatOnlyPage extends StatefulWidget {
|
||||
const ChatOnlyPage({super.key});
|
||||
|
|
@ -1,3 +1,5 @@
|
|||
import 'dart:async';
|
||||
|
||||
import 'package:awesome_extensions/awesome_extensions.dart';
|
||||
import 'package:fast_immutable_collections/fast_immutable_collections.dart';
|
||||
import 'package:flutter/material.dart';
|
||||
|
|
@ -7,36 +9,61 @@ import 'package:flutter_translate/flutter_translate.dart';
|
|||
import 'package:go_router/go_router.dart';
|
||||
import 'package:veilid_support/veilid_support.dart';
|
||||
|
||||
import '../account_manager/account_manager.dart';
|
||||
import '../chat/chat.dart';
|
||||
import '../theme/theme.dart';
|
||||
import '../tools/tools.dart';
|
||||
import 'main_pager/main_pager.dart';
|
||||
import '../../../account_manager/account_manager.dart';
|
||||
import '../../../contact_invitation/contact_invitation.dart';
|
||||
import '../../../proto/proto.dart' as proto;
|
||||
import '../../../theme/theme.dart';
|
||||
import '../../../tools/tools.dart';
|
||||
|
||||
class HomePage extends StatefulWidget {
|
||||
const HomePage({super.key});
|
||||
class HomeAccountReady extends StatefulWidget {
|
||||
const HomeAccountReady(
|
||||
{required IList<LocalAccount> localAccounts,
|
||||
required TypedKey activeUserLogin,
|
||||
required ActiveAccountInfo activeAccountInfo,
|
||||
required proto.Account account,
|
||||
super.key})
|
||||
: _localAccounts = localAccounts,
|
||||
_activeUserLogin = activeUserLogin,
|
||||
_activeAccountInfo = activeAccountInfo,
|
||||
_account = account;
|
||||
|
||||
final IList<LocalAccount> _localAccounts;
|
||||
final TypedKey _activeUserLogin;
|
||||
final ActiveAccountInfo _activeAccountInfo;
|
||||
final proto.Account _account;
|
||||
|
||||
@override
|
||||
HomePageState createState() => HomePageState();
|
||||
HomeAccountReadyState createState() => HomeAccountReadyState();
|
||||
}
|
||||
|
||||
class HomePageState extends State<HomePage> with TickerProviderStateMixin {
|
||||
final _unfocusNode = FocusNode();
|
||||
class HomeAccountReadyState extends State<HomeAccountReady>
|
||||
with TickerProviderStateMixin {
|
||||
//
|
||||
ContactInvitationRepository? _contactInvitationRepository;
|
||||
|
||||
//
|
||||
@override
|
||||
void initState() {
|
||||
super.initState();
|
||||
|
||||
WidgetsBinding.instance.addPostFrameCallback((_) async {
|
||||
await changeWindowSetup(
|
||||
TitleBarStyle.normal, OrientationCapability.normal);
|
||||
// Async initialize repositories for the active user
|
||||
// xxx: this should not be necessary
|
||||
// xxx: but RepositoryProvider doesn't call dispose()
|
||||
Future.delayed(Duration.zero, () async {
|
||||
//
|
||||
final cir = await ContactInvitationRepository.open(
|
||||
widget._activeAccountInfo, widget._account);
|
||||
|
||||
setState(() {
|
||||
_contactInvitationRepository = cir;
|
||||
});
|
||||
});
|
||||
}
|
||||
|
||||
@override
|
||||
void dispose() {
|
||||
_unfocusNode.dispose();
|
||||
super.dispose();
|
||||
_contactInvitationRepository?.dispose();
|
||||
}
|
||||
|
||||
// ignore: prefer_expression_function_bodies
|
||||
|
|
@ -65,6 +92,8 @@ class HomePageState extends State<HomePage> with TickerProviderStateMixin {
|
|||
final theme = Theme.of(context);
|
||||
final scale = theme.extension<ScaleScheme>()!;
|
||||
|
||||
xxx get rid of the cubit here and
|
||||
|
||||
return BlocProvider(
|
||||
create: (context) => AccountRecordCubit(record: accountRecord),
|
||||
child: Column(children: <Widget>[
|
||||
|
|
@ -104,6 +133,8 @@ class HomePageState extends State<HomePage> with TickerProviderStateMixin {
|
|||
]));
|
||||
}
|
||||
|
||||
xxx get rid of this whole function
|
||||
|
||||
Widget buildUserPanel() => Builder(builder: (context) {
|
||||
final activeUserLogin = context.watch<ActiveUserLoginCubit>().state;
|
||||
final localAccounts = context.watch<LocalAccountsCubit>().state;
|
||||
|
|
@ -190,21 +221,15 @@ class HomePageState extends State<HomePage> with TickerProviderStateMixin {
|
|||
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
final theme = Theme.of(context);
|
||||
final scale = theme.extension<ScaleScheme>()!;
|
||||
if (_contactInvitationRepository == null) {
|
||||
return waitingPage(context);
|
||||
}
|
||||
|
||||
return SafeArea(
|
||||
child: GestureDetector(
|
||||
onTap: () => FocusScope.of(context).requestFocus(_unfocusNode),
|
||||
child: DecoratedBox(
|
||||
decoration: BoxDecoration(
|
||||
color: scale.primaryScale.activeElementBackground),
|
||||
child: responsiveVisibility(
|
||||
context: context,
|
||||
phone: false,
|
||||
)
|
||||
? buildTablet()
|
||||
: buildPhone(),
|
||||
)));
|
||||
return responsiveVisibility(
|
||||
context: context,
|
||||
phone: false,
|
||||
)
|
||||
? buildTablet()
|
||||
: buildPhone();
|
||||
}
|
||||
}
|
||||
|
|
@ -5,11 +5,11 @@ import 'package:flutter/material.dart';
|
|||
import 'package:flutter_translate/flutter_translate.dart';
|
||||
import 'package:veilid_support/veilid_support.dart';
|
||||
|
||||
import '../../../proto/proto.dart' as proto;
|
||||
import '../../account_manager/account_manager.dart';
|
||||
import '../../contact_invitation/contact_invitation.dart';
|
||||
import '../../contacts/contacts.dart';
|
||||
import '../../theme/theme.dart';
|
||||
import '../../../../proto/proto.dart' as proto;
|
||||
import '../../../account_manager/account_manager.dart';
|
||||
import '../../../contact_invitation/contact_invitation.dart';
|
||||
import '../../../contacts/contacts.dart';
|
||||
import '../../../theme/theme.dart';
|
||||
|
||||
class AccountPage extends StatefulWidget {
|
||||
const AccountPage({
|
||||
|
|
@ -2,9 +2,9 @@ import 'package:awesome_extensions/awesome_extensions.dart';
|
|||
import 'package:fast_immutable_collections/fast_immutable_collections.dart';
|
||||
import 'package:flutter/material.dart';
|
||||
|
||||
import '../../../proto/proto.dart' as proto;
|
||||
import '../../account_manager/account_manager.dart';
|
||||
import '../../tools/tools.dart';
|
||||
import '../../../../proto/proto.dart' as proto;
|
||||
import '../../../account_manager/account_manager.dart';
|
||||
import '../../../tools/tools.dart';
|
||||
|
||||
class ChatsPage extends StatefulWidget {
|
||||
const ChatsPage({super.key});
|
||||
|
|
@ -11,14 +11,14 @@ import 'package:stylish_bottom_bar/model/bar_items.dart';
|
|||
import 'package:stylish_bottom_bar/stylish_bottom_bar.dart';
|
||||
import 'package:veilid_support/veilid_support.dart';
|
||||
|
||||
import '../../../proto/proto.dart' as proto;
|
||||
import '../../../tools/tools.dart';
|
||||
import '../../account_manager/account_manager.dart';
|
||||
import '../../contact_invitation/contact_invitation.dart';
|
||||
import '../../theme/theme.dart';
|
||||
import 'account.dart';
|
||||
import '../../../../proto/proto.dart' as proto;
|
||||
import '../../../../tools/tools.dart';
|
||||
import '../../../account_manager/account_manager.dart';
|
||||
import '../../../contact_invitation/contact_invitation.dart';
|
||||
import '../../../theme/theme.dart';
|
||||
import 'account_page.dart';
|
||||
import 'bottom_sheet_action_button.dart';
|
||||
import 'chats.dart';
|
||||
import 'chats_page.dart';
|
||||
|
||||
class MainPager extends StatefulWidget {
|
||||
const MainPager(
|
||||
25
lib/layout/home/home_no_active.dart
Normal file
25
lib/layout/home/home_no_active.dart
Normal file
|
|
@ -0,0 +1,25 @@
|
|||
import 'package:flutter/material.dart';
|
||||
|
||||
import '../../tools/tools.dart';
|
||||
|
||||
class HomeNoActive extends StatefulWidget {
|
||||
const HomeNoActive({super.key});
|
||||
|
||||
@override
|
||||
HomeNoActiveState createState() => HomeNoActiveState();
|
||||
}
|
||||
|
||||
class HomeNoActiveState extends State<HomeNoActive> {
|
||||
@override
|
||||
void initState() {
|
||||
super.initState();
|
||||
}
|
||||
|
||||
@override
|
||||
void dispose() {
|
||||
super.dispose();
|
||||
}
|
||||
|
||||
@override
|
||||
Widget build(BuildContext context) => waitingPage(context);
|
||||
}
|
||||
|
|
@ -1,4 +1,4 @@
|
|||
export 'chat_only.dart';
|
||||
export 'home/home_account_ready/chat_only.dart';
|
||||
export 'default_app_bar.dart';
|
||||
export 'edit_account.dart';
|
||||
export 'edit_contact.dart';
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue