refactor: Use APL
This commit is contained in:
parent
7474bd53d0
commit
544bc15022
40 changed files with 1002 additions and 1273 deletions
|
|
@ -1,52 +0,0 @@
|
|||
import 'package:flutter/material.dart';
|
||||
|
||||
enum FocusPage { FIRST, SECOND }
|
||||
|
||||
class AdaptivePageLayout extends StatelessWidget {
|
||||
final Widget firstScaffold;
|
||||
final Widget secondScaffold;
|
||||
final FocusPage primaryPage;
|
||||
final double minWidth;
|
||||
|
||||
static const double defaultMinWidth = 400;
|
||||
static bool columnMode(BuildContext context) =>
|
||||
MediaQuery.of(context).size.width > 2 * defaultMinWidth;
|
||||
|
||||
AdaptivePageLayout(
|
||||
{this.firstScaffold,
|
||||
this.secondScaffold,
|
||||
this.primaryPage = FocusPage.FIRST,
|
||||
this.minWidth = defaultMinWidth,
|
||||
Key key})
|
||||
: super(key: key);
|
||||
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
return OrientationBuilder(builder: (context, orientation) {
|
||||
if (orientation == Orientation.portrait || !columnMode(context)) {
|
||||
if (primaryPage == FocusPage.FIRST) {
|
||||
return firstScaffold;
|
||||
} else {
|
||||
return secondScaffold;
|
||||
}
|
||||
}
|
||||
return Row(
|
||||
children: <Widget>[
|
||||
Container(
|
||||
width: minWidth,
|
||||
child: firstScaffold,
|
||||
),
|
||||
Container(
|
||||
width: 1,
|
||||
color: Theme.of(context).secondaryHeaderColor, //Color(0xFFE8E8E8),
|
||||
),
|
||||
Expanded(
|
||||
child: Container(
|
||||
child: secondScaffold,
|
||||
),
|
||||
)
|
||||
],
|
||||
);
|
||||
});
|
||||
}
|
||||
}
|
||||
|
|
@ -1,10 +1,8 @@
|
|||
import 'dart:async';
|
||||
|
||||
import 'package:adaptive_dialog/adaptive_dialog.dart';
|
||||
import 'package:adaptive_page_layout/adaptive_page_layout.dart';
|
||||
import 'package:famedlysdk/famedlysdk.dart';
|
||||
import 'package:fluffychat/utils/app_route.dart';
|
||||
import 'package:fluffychat/views/chat_details.dart';
|
||||
import 'package:fluffychat/views/chat_list.dart';
|
||||
import 'package:flutter/material.dart';
|
||||
import 'package:flutter_gen/gen_l10n/l10n.dart';
|
||||
import 'package:url_launcher/url_launcher.dart';
|
||||
|
|
@ -95,9 +93,8 @@ class _ChatSettingsPopupMenuState extends State<ChatSettingsPopupMenu> {
|
|||
final success = await showFutureLoadingDialog(
|
||||
context: context, future: () => widget.room.leave());
|
||||
if (success.error == null) {
|
||||
await Navigator.of(context).pushAndRemoveUntil(
|
||||
AppRoute.defaultRoute(context, ChatListView()),
|
||||
(Route r) => false);
|
||||
await AdaptivePageLayout.of(context)
|
||||
.pushNamedAndRemoveAllOthers('/');
|
||||
}
|
||||
}
|
||||
break;
|
||||
|
|
@ -117,12 +114,9 @@ class _ChatSettingsPopupMenuState extends State<ChatSettingsPopupMenu> {
|
|||
startCallAction(context);
|
||||
break;
|
||||
case 'details':
|
||||
await Navigator.of(context).push(
|
||||
AppRoute.defaultRoute(
|
||||
context,
|
||||
ChatDetails(widget.room),
|
||||
),
|
||||
);
|
||||
await AdaptivePageLayout.of(context).pushNamedAndRemoveAllOthers(
|
||||
'/rooms/${widget.room.id}/details');
|
||||
|
||||
break;
|
||||
}
|
||||
},
|
||||
|
|
|
|||
|
|
@ -1,11 +1,6 @@
|
|||
import 'package:adaptive_dialog/adaptive_dialog.dart';
|
||||
import 'package:adaptive_page_layout/adaptive_page_layout.dart';
|
||||
import 'package:famedlysdk/famedlysdk.dart';
|
||||
import 'package:fluffychat/utils/app_route.dart';
|
||||
import 'package:fluffychat/views/archive.dart';
|
||||
import 'package:fluffychat/views/discover_view.dart';
|
||||
import 'package:fluffychat/views/new_group.dart';
|
||||
import 'package:fluffychat/views/new_private_chat.dart';
|
||||
import 'package:fluffychat/views/settings.dart';
|
||||
import 'package:flutter/material.dart';
|
||||
import 'package:flutter_gen/gen_l10n/l10n.dart';
|
||||
|
||||
|
|
@ -13,15 +8,9 @@ import 'package:future_loading_dialog/future_loading_dialog.dart';
|
|||
import 'matrix.dart';
|
||||
|
||||
class DefaultDrawer extends StatelessWidget {
|
||||
void _drawerTapAction(BuildContext context, Widget view) {
|
||||
void _drawerTapAction(BuildContext context, String route) {
|
||||
Navigator.of(context).pop();
|
||||
Navigator.of(context).pushAndRemoveUntil(
|
||||
AppRoute.defaultRoute(
|
||||
context,
|
||||
view,
|
||||
),
|
||||
(r) => r.isFirst,
|
||||
);
|
||||
AdaptivePageLayout.of(context).pushNamedAndRemoveUntilIsFirst(route);
|
||||
}
|
||||
|
||||
void _setStatus(BuildContext context) async {
|
||||
|
|
@ -64,12 +53,12 @@ class DefaultDrawer extends StatelessWidget {
|
|||
ListTile(
|
||||
leading: Icon(Icons.people_outline),
|
||||
title: Text(L10n.of(context).createNewGroup),
|
||||
onTap: () => _drawerTapAction(context, NewGroupView()),
|
||||
onTap: () => _drawerTapAction(context, '/newgroup'),
|
||||
),
|
||||
ListTile(
|
||||
leading: Icon(Icons.person_add_outlined),
|
||||
title: Text(L10n.of(context).newPrivateChat),
|
||||
onTap: () => _drawerTapAction(context, NewPrivateChatView()),
|
||||
onTap: () => _drawerTapAction(context, '/newprivatechat'),
|
||||
),
|
||||
Divider(height: 1),
|
||||
ListTile(
|
||||
|
|
@ -77,7 +66,7 @@ class DefaultDrawer extends StatelessWidget {
|
|||
title: Text(L10n.of(context).archive),
|
||||
onTap: () => _drawerTapAction(
|
||||
context,
|
||||
Archive(),
|
||||
'/archive',
|
||||
),
|
||||
),
|
||||
ListTile(
|
||||
|
|
@ -85,7 +74,7 @@ class DefaultDrawer extends StatelessWidget {
|
|||
title: Text(L10n.of(context).discoverGroups),
|
||||
onTap: () => _drawerTapAction(
|
||||
context,
|
||||
DiscoverView(),
|
||||
'/discover',
|
||||
),
|
||||
),
|
||||
Divider(height: 1),
|
||||
|
|
@ -94,7 +83,7 @@ class DefaultDrawer extends StatelessWidget {
|
|||
title: Text(L10n.of(context).settings),
|
||||
onTap: () => _drawerTapAction(
|
||||
context,
|
||||
SettingsView(),
|
||||
'/settings',
|
||||
),
|
||||
),
|
||||
],
|
||||
|
|
|
|||
|
|
@ -1,10 +1,9 @@
|
|||
import 'dart:async';
|
||||
|
||||
import 'package:adaptive_dialog/adaptive_dialog.dart';
|
||||
import 'package:adaptive_page_layout/adaptive_page_layout.dart';
|
||||
import 'package:flushbar/flushbar_helper.dart';
|
||||
import 'package:famedlysdk/famedlysdk.dart';
|
||||
import 'package:fluffychat/utils/app_route.dart';
|
||||
import 'package:fluffychat/views/chat_encryption_settings.dart';
|
||||
import 'package:flutter/material.dart';
|
||||
import 'package:flutter_gen/gen_l10n/l10n.dart';
|
||||
|
||||
|
|
@ -23,12 +22,8 @@ class _EncryptionButtonState extends State<EncryptionButton> {
|
|||
|
||||
void _enableEncryptionAction() async {
|
||||
if (widget.room.encrypted) {
|
||||
await Navigator.of(context).push(
|
||||
AppRoute.defaultRoute(
|
||||
context,
|
||||
ChatEncryptionSettingsView(widget.room.id),
|
||||
),
|
||||
);
|
||||
await AdaptivePageLayout.of(context)
|
||||
.pushNamed('/rooms/${widget.room.id}/encryption');
|
||||
return;
|
||||
}
|
||||
if (!widget.room.client.encryptionEnabled) {
|
||||
|
|
|
|||
|
|
@ -1,19 +1,17 @@
|
|||
import 'package:adaptive_dialog/adaptive_dialog.dart';
|
||||
import 'package:adaptive_page_layout/adaptive_page_layout.dart';
|
||||
import 'package:circular_check_box/circular_check_box.dart';
|
||||
import 'package:famedlysdk/famedlysdk.dart';
|
||||
import 'package:fluffychat/config/themes.dart';
|
||||
import 'package:fluffychat/utils/event_extension.dart';
|
||||
import 'package:fluffychat/utils/matrix_locals.dart';
|
||||
import 'package:fluffychat/utils/room_status_extension.dart';
|
||||
import 'package:fluffychat/views/chat.dart';
|
||||
import 'package:flushbar/flushbar_helper.dart';
|
||||
import 'package:flutter/material.dart';
|
||||
import 'package:flutter_gen/gen_l10n/l10n.dart';
|
||||
import 'package:pedantic/pedantic.dart';
|
||||
|
||||
import '../../utils/app_route.dart';
|
||||
import '../../utils/date_time_extension.dart';
|
||||
import '../../views/chat.dart';
|
||||
import '../avatar.dart';
|
||||
import '../dialogs/send_file_dialog.dart';
|
||||
import 'package:future_loading_dialog/future_loading_dialog.dart';
|
||||
|
|
@ -102,11 +100,8 @@ class ChatListItem extends StatelessWidget {
|
|||
}
|
||||
Matrix.of(context).shareContent = null;
|
||||
}
|
||||
await Navigator.pushAndRemoveUntil(
|
||||
context,
|
||||
AppRoute.defaultRoute(context, ChatView(room.id)),
|
||||
(r) => r.isFirst,
|
||||
);
|
||||
await AdaptivePageLayout.of(context)
|
||||
.pushNamedAndRemoveUntilIsFirst('/rooms/${room.id}');
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -1,12 +1,12 @@
|
|||
import 'package:famedlysdk/famedlysdk.dart';
|
||||
import 'package:fluffychat/components/message_content.dart';
|
||||
import 'package:fluffychat/components/reply_content.dart';
|
||||
import 'package:fluffychat/config/themes.dart';
|
||||
import 'package:fluffychat/utils/date_time_extension.dart';
|
||||
import 'package:fluffychat/utils/event_extension.dart';
|
||||
import 'package:fluffychat/utils/string_color.dart';
|
||||
import 'package:flutter/material.dart';
|
||||
|
||||
import '../adaptive_page_layout.dart';
|
||||
import '../avatar.dart';
|
||||
import '../matrix.dart';
|
||||
import '../message_reactions.dart';
|
||||
|
|
@ -88,8 +88,7 @@ class Message extends StatelessWidget {
|
|||
color: color,
|
||||
borderRadius: BorderRadius.circular(radius),
|
||||
),
|
||||
constraints:
|
||||
BoxConstraints(maxWidth: AdaptivePageLayout.defaultMinWidth),
|
||||
constraints: BoxConstraints(maxWidth: FluffyThemes.columnWidth),
|
||||
child: Stack(
|
||||
children: <Widget>[
|
||||
Column(
|
||||
|
|
|
|||
|
|
@ -1,10 +1,9 @@
|
|||
import 'package:adaptive_page_layout/adaptive_page_layout.dart';
|
||||
import 'package:famedlysdk/famedlysdk.dart';
|
||||
import 'package:future_loading_dialog/future_loading_dialog.dart';
|
||||
import 'package:flutter/material.dart';
|
||||
import 'package:flutter_gen/gen_l10n/l10n.dart';
|
||||
|
||||
import '../../utils/app_route.dart';
|
||||
import '../../views/chat.dart';
|
||||
import '../avatar.dart';
|
||||
import '../matrix.dart';
|
||||
|
||||
|
|
@ -19,12 +18,8 @@ class PublicRoomListItem extends StatelessWidget {
|
|||
future: () => _joinRoomAndWait(context),
|
||||
);
|
||||
if (success.error == null) {
|
||||
await Navigator.of(context).push(
|
||||
AppRoute.defaultRoute(
|
||||
context,
|
||||
ChatView(success.result),
|
||||
),
|
||||
);
|
||||
await AdaptivePageLayout.of(context)
|
||||
.pushNamed('/rooms/${success.result}');
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -3,14 +3,13 @@ import 'dart:io';
|
|||
import 'dart:convert';
|
||||
|
||||
import 'package:adaptive_dialog/adaptive_dialog.dart';
|
||||
import 'package:adaptive_page_layout/adaptive_page_layout.dart';
|
||||
import 'package:famedlysdk/encryption.dart';
|
||||
import 'package:famedlysdk/famedlysdk.dart';
|
||||
import 'package:fluffychat/utils/app_route.dart';
|
||||
import 'package:fluffychat/utils/firebase_controller.dart';
|
||||
import 'package:fluffychat/utils/matrix_locals.dart';
|
||||
import 'package:fluffychat/utils/platform_infos.dart';
|
||||
import 'package:fluffychat/utils/sentry_controller.dart';
|
||||
import 'package:fluffychat/views/settings_3pid.dart';
|
||||
import 'package:flushbar/flushbar.dart';
|
||||
import 'package:flutter/foundation.dart';
|
||||
import 'package:flutter/material.dart';
|
||||
|
|
@ -38,7 +37,16 @@ class Matrix extends StatefulWidget {
|
|||
|
||||
final Widget child;
|
||||
|
||||
Matrix({this.child, Key key}) : super(key: key);
|
||||
final GlobalKey<AdaptivePageLayoutState> apl;
|
||||
|
||||
final BuildContext context;
|
||||
|
||||
Matrix({
|
||||
this.child,
|
||||
@required this.apl,
|
||||
@required this.context,
|
||||
Key key,
|
||||
}) : super(key: key);
|
||||
|
||||
@override
|
||||
MatrixState createState() => MatrixState();
|
||||
|
|
@ -52,7 +60,7 @@ class MatrixState extends State<Matrix> {
|
|||
Client client;
|
||||
Store store = Store();
|
||||
@override
|
||||
BuildContext context;
|
||||
BuildContext get context => widget.context;
|
||||
|
||||
Map<String, dynamic> get shareContent => _shareContent;
|
||||
set shareContent(Map<String, dynamic> content) {
|
||||
|
|
@ -76,29 +84,16 @@ class MatrixState extends State<Matrix> {
|
|||
}
|
||||
|
||||
void _initWithStore() async {
|
||||
var initLoginState = client.onLoginStateChanged.stream.first;
|
||||
try {
|
||||
client.init();
|
||||
|
||||
final firstLoginState = await initLoginState;
|
||||
if (firstLoginState == LoginState.logged) {
|
||||
if (PlatformInfos.isMobile) {
|
||||
await FirebaseController.setupFirebase(
|
||||
this,
|
||||
clientName,
|
||||
);
|
||||
}
|
||||
}
|
||||
final storeItem = await store.getItem(SettingKeys.showNoPid);
|
||||
final configOptionMissing = storeItem == null || storeItem.isEmpty;
|
||||
if (configOptionMissing || (!configOptionMissing && storeItem == '1')) {
|
||||
if (configOptionMissing) {
|
||||
await store.setItem(SettingKeys.showNoPid, '0');
|
||||
}
|
||||
await Matrix.of(context)
|
||||
.client
|
||||
.requestThirdPartyIdentifiers()
|
||||
.then((l) {
|
||||
await client.requestThirdPartyIdentifiers().then((l) {
|
||||
if (l.isEmpty) {
|
||||
Flushbar(
|
||||
title: L10n.of(context).warning,
|
||||
|
|
@ -110,12 +105,8 @@ class MatrixState extends State<Matrix> {
|
|||
borderRadius: BorderRadius.circular(6),
|
||||
),
|
||||
child: Text(L10n.of(context).edit),
|
||||
onPressed: () => Navigator.of(context).push(
|
||||
AppRoute.defaultRoute(
|
||||
context,
|
||||
Settings3PidView(),
|
||||
),
|
||||
),
|
||||
onPressed: () =>
|
||||
AdaptivePageLayout.of(context).pushNamed('/settings/3pid'),
|
||||
),
|
||||
flushbarStyle: FlushbarStyle.FLOATING,
|
||||
).show(context);
|
||||
|
|
@ -133,6 +124,7 @@ class MatrixState extends State<Matrix> {
|
|||
StreamSubscription onKeyVerificationRequestSub;
|
||||
StreamSubscription onJitsiCallSub;
|
||||
StreamSubscription onNotification;
|
||||
StreamSubscription<LoginState> onLoginStateChanged;
|
||||
StreamSubscription<UiaRequest> onUiaRequest;
|
||||
StreamSubscription<html.Event> onFocusSub;
|
||||
StreamSubscription<html.Event> onBlurSub;
|
||||
|
|
@ -301,6 +293,8 @@ class MatrixState extends State<Matrix> {
|
|||
}
|
||||
}
|
||||
|
||||
LoginState loginState;
|
||||
|
||||
void initMatrix() {
|
||||
clientName =
|
||||
'${AppConfig.applicationName} ${kIsWeb ? 'Web' : Platform.operatingSystem}';
|
||||
|
|
@ -380,6 +374,19 @@ class MatrixState extends State<Matrix> {
|
|||
onFocusSub = html.window.onFocus.listen((_) => webHasFocus = true);
|
||||
onBlurSub = html.window.onBlur.listen((_) => webHasFocus = false);
|
||||
}
|
||||
onLoginStateChanged ??= client.onLoginStateChanged.stream.listen((state) {
|
||||
if (loginState != state) {
|
||||
loginState = state;
|
||||
widget.apl.currentState.pushNamedAndRemoveAllOthers('/');
|
||||
if (loginState == LoginState.logged) {
|
||||
FirebaseController.context = context;
|
||||
FirebaseController.setupFirebase(
|
||||
this,
|
||||
clientName,
|
||||
).catchError(SentryController.captureException);
|
||||
}
|
||||
}
|
||||
});
|
||||
onUiaRequest ??= client.onUiaRequest.stream.listen(_onUiaRequest);
|
||||
if (kIsWeb || Platform.isLinux) {
|
||||
client.onSync.stream.first.then((s) {
|
||||
|
|
|
|||
|
|
@ -1,12 +1,11 @@
|
|||
import 'dart:math';
|
||||
|
||||
import 'package:adaptive_dialog/adaptive_dialog.dart';
|
||||
import 'package:adaptive_page_layout/adaptive_page_layout.dart';
|
||||
import 'package:famedlysdk/famedlysdk.dart';
|
||||
import 'package:fluffychat/components/adaptive_page_layout.dart';
|
||||
import 'package:fluffychat/components/dialogs/permission_slider_dialog.dart';
|
||||
import 'package:fluffychat/utils/app_route.dart';
|
||||
import 'package:fluffychat/config/themes.dart';
|
||||
import 'package:fluffychat/utils/fluffy_share.dart';
|
||||
import 'package:fluffychat/views/chat.dart';
|
||||
import 'package:flutter/material.dart';
|
||||
import 'content_banner.dart';
|
||||
import 'package:flutter_gen/gen_l10n/l10n.dart';
|
||||
|
|
@ -15,7 +14,6 @@ import '../utils/presence_extension.dart';
|
|||
import 'package:future_loading_dialog/future_loading_dialog.dart';
|
||||
import 'matrix.dart';
|
||||
import 'dialogs/key_verification_dialog.dart';
|
||||
import '../utils/app_route.dart';
|
||||
|
||||
class UserBottomSheet extends StatelessWidget {
|
||||
final User user;
|
||||
|
|
@ -76,12 +74,8 @@ class UserBottomSheet extends StatelessWidget {
|
|||
break;
|
||||
case 'message':
|
||||
final roomId = await user.startDirectChat();
|
||||
await Navigator.of(context).pushAndRemoveUntil(
|
||||
AppRoute.defaultRoute(
|
||||
context,
|
||||
ChatView(roomId),
|
||||
),
|
||||
(Route r) => r.isFirst);
|
||||
await AdaptivePageLayout.of(context)
|
||||
.pushNamedAndRemoveUntilIsFirst('/rooms/${roomId}');
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
|
@ -161,8 +155,8 @@ class UserBottomSheet extends StatelessWidget {
|
|||
}
|
||||
return Center(
|
||||
child: Container(
|
||||
width: min(MediaQuery.of(context).size.width,
|
||||
AdaptivePageLayout.defaultMinWidth * 1.5),
|
||||
width: min(
|
||||
MediaQuery.of(context).size.width, FluffyThemes.columnWidth * 1.5),
|
||||
child: SafeArea(
|
||||
child: Material(
|
||||
elevation: 4,
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue