mirror of
https://gitlab.com/comunic/comunicmobile
synced 2024-12-26 12:58:51 +00:00
Remove Navigator references from conversations pages
This commit is contained in:
parent
3fa45f9744
commit
32c491ae84
@ -1,7 +1,9 @@
|
||||
import 'package:comunic/helpers/conversations_helper.dart';
|
||||
import 'package:comunic/models/conversation.dart';
|
||||
import 'package:comunic/ui/routes/home_route.dart';
|
||||
import 'package:comunic/ui/routes/update_conversation_route.dart';
|
||||
import 'package:comunic/ui/screens/conversation_screen.dart';
|
||||
import 'package:comunic/ui/widgets/comunic_back_button_widget.dart';
|
||||
import 'package:comunic/utils/intl_utils.dart';
|
||||
import 'package:comunic/utils/ui_utils.dart';
|
||||
import 'package:flutter/material.dart';
|
||||
@ -44,11 +46,10 @@ class _ConversationRouteState extends State<ConversationRoute> {
|
||||
|
||||
if (_conversation == null) return setError(true);
|
||||
|
||||
|
||||
final conversationName =
|
||||
await ConversationsHelper.getConversationNameAsync(_conversation);
|
||||
|
||||
if(!this.mounted) return null;
|
||||
if (!this.mounted) return null;
|
||||
|
||||
if (conversationName == null) return setError(true);
|
||||
|
||||
@ -58,11 +59,11 @@ class _ConversationRouteState extends State<ConversationRoute> {
|
||||
}
|
||||
|
||||
void _openSettings() {
|
||||
Navigator.of(context).push(MaterialPageRoute(builder: (b) {
|
||||
return UpdateConversationRoute(
|
||||
conversationID: widget.conversationID,
|
||||
);
|
||||
}));
|
||||
HomeController.of(context).push(
|
||||
UpdateConversationRoute(
|
||||
conversationID: widget.conversationID,
|
||||
),
|
||||
hideNavBar: true);
|
||||
}
|
||||
|
||||
Widget _buildRouteBody() {
|
||||
@ -95,6 +96,7 @@ class _ConversationRouteState extends State<ConversationRoute> {
|
||||
Widget build(BuildContext context) {
|
||||
return Scaffold(
|
||||
appBar: AppBar(
|
||||
leading: ComunicBackButton(),
|
||||
title: Text(
|
||||
_conversationName == null ? tr("Loading") : _conversationName,
|
||||
),
|
||||
|
@ -1,5 +1,6 @@
|
||||
import 'package:comunic/helpers/account_helper.dart';
|
||||
import 'package:comunic/ui/routes/app_settings_route.dart';
|
||||
import 'package:comunic/ui/routes/conversation_route.dart';
|
||||
import 'package:comunic/ui/screens/conversations_list_screen.dart';
|
||||
import 'package:comunic/ui/screens/friends_list_screen.dart';
|
||||
import 'package:comunic/ui/screens/group_screen.dart';
|
||||
@ -29,8 +30,14 @@ class HomeRoute extends StatefulWidget {
|
||||
class CurrPage {
|
||||
final BarCallbackActions action;
|
||||
final Map<String, dynamic> args;
|
||||
final bool hideNavBar;
|
||||
|
||||
const CurrPage(this.action, {this.args}) : assert(action != null);
|
||||
const CurrPage(
|
||||
this.action, {
|
||||
this.args,
|
||||
this.hideNavBar = false,
|
||||
}) : assert(action != null),
|
||||
assert(hideNavBar != null);
|
||||
|
||||
@override
|
||||
String toString() =>
|
||||
@ -60,6 +67,12 @@ abstract class HomeController extends State<HomeRoute> {
|
||||
|
||||
/// Pop current page. Last page can not be popped
|
||||
void popPage();
|
||||
|
||||
/// Push a new widget
|
||||
void push(Widget w, {bool hideNavBar});
|
||||
|
||||
/// Open a conversation
|
||||
void openConversation(int convID);
|
||||
}
|
||||
|
||||
/// Private implementation of HomeController
|
||||
@ -129,6 +142,9 @@ class _HomeRouteState extends HomeController {
|
||||
/// Build the body of the application
|
||||
Widget _buildBody(BuildContext context) {
|
||||
switch (_currTab.action) {
|
||||
case BarCallbackActions.OPEN_CUSTOM_WIDGET:
|
||||
return _currTab.args["widget"];
|
||||
|
||||
case BarCallbackActions.OPEN_NOTIFICATIONS:
|
||||
return NotificationsScreen();
|
||||
|
||||
@ -158,6 +174,11 @@ class _HomeRouteState extends HomeController {
|
||||
userID: _currTab.args["userID"],
|
||||
);
|
||||
|
||||
case BarCallbackActions.OPEN_CONVERSATION:
|
||||
return ConversationRoute(
|
||||
conversationID: _currTab.args["convID"],
|
||||
);
|
||||
|
||||
default:
|
||||
throw "Invalid tab : " + _currTab.toString();
|
||||
}
|
||||
@ -172,10 +193,12 @@ class _HomeRouteState extends HomeController {
|
||||
child: WillPopScope(
|
||||
onWillPop: _willPop,
|
||||
child: Scaffold(
|
||||
appBar: ComunicAppBar(
|
||||
onTap: _onTap,
|
||||
selectedAction: _currTab.action,
|
||||
),
|
||||
appBar: _currTab.hideNavBar
|
||||
? null
|
||||
: ComunicAppBar(
|
||||
onTap: _onTap,
|
||||
selectedAction: _currTab.action,
|
||||
),
|
||||
body: SafeArea(
|
||||
child: _buildBody(context),
|
||||
),
|
||||
@ -232,4 +255,22 @@ class _HomeRouteState extends HomeController {
|
||||
_pushPage(CurrPage(BarCallbackActions.OPEN_USER_FRIENDS_LIST,
|
||||
args: {"userID": userID}));
|
||||
}
|
||||
|
||||
@override
|
||||
void push(Widget w, {bool hideNavBar = false}) {
|
||||
_pushPage(CurrPage(
|
||||
BarCallbackActions.OPEN_CUSTOM_WIDGET,
|
||||
args: {"widget": w},
|
||||
hideNavBar: hideNavBar,
|
||||
));
|
||||
}
|
||||
|
||||
@override
|
||||
void openConversation(int convID) {
|
||||
_pushPage(CurrPage(
|
||||
BarCallbackActions.OPEN_CONVERSATION,
|
||||
args: {"convID": convID},
|
||||
hideNavBar: true,
|
||||
));
|
||||
}
|
||||
}
|
||||
|
@ -3,6 +3,7 @@ import 'package:comunic/helpers/users_helper.dart';
|
||||
import 'package:comunic/lists/users_list.dart';
|
||||
import 'package:comunic/models/conversation.dart';
|
||||
import 'package:comunic/ui/screens/update_conversation_screen.dart';
|
||||
import 'package:comunic/ui/widgets/comunic_back_button_widget.dart';
|
||||
import 'package:comunic/utils/intl_utils.dart';
|
||||
import 'package:comunic/utils/ui_utils.dart';
|
||||
import 'package:flutter/material.dart';
|
||||
@ -83,6 +84,7 @@ class _UpdateConversationRoute extends State<UpdateConversationRoute> {
|
||||
Widget build(BuildContext context) {
|
||||
return Scaffold(
|
||||
appBar: AppBar(
|
||||
leading: ComunicBackButton(),
|
||||
title: Text(tr("Update a conversation")),
|
||||
),
|
||||
body: _buildBody(),
|
||||
|
@ -3,9 +3,9 @@ import 'package:comunic/helpers/conversations_helper.dart';
|
||||
import 'package:comunic/helpers/users_helper.dart';
|
||||
import 'package:comunic/lists/conversations_list.dart';
|
||||
import 'package:comunic/models/conversation.dart';
|
||||
import 'package:comunic/ui/routes/conversation_route.dart';
|
||||
import 'package:comunic/ui/routes/create_conversation_route.dart';
|
||||
import 'package:comunic/ui/routes/home_route.dart';
|
||||
import 'package:comunic/ui/routes/update_conversation_route.dart';
|
||||
import 'package:comunic/ui/screens/create_conversation_screen.dart';
|
||||
import 'package:comunic/ui/tiles/conversation_tile.dart';
|
||||
import 'package:comunic/utils/intl_utils.dart';
|
||||
import 'package:comunic/utils/ui_utils.dart';
|
||||
@ -94,27 +94,20 @@ class _ConversationScreenState extends State<ConversationsListScreen> {
|
||||
}
|
||||
|
||||
/// Open a conversation
|
||||
void _openConversation(BuildContext context, int conversationId) {
|
||||
Navigator.of(context).push(MaterialPageRoute(builder: (c) {
|
||||
return ConversationRoute(
|
||||
conversationID: conversationId,
|
||||
);
|
||||
}));
|
||||
void _openConversation(int conversationId) {
|
||||
HomeController.of(context).openConversation(conversationId);
|
||||
}
|
||||
|
||||
/// Create a new conversation
|
||||
void _createConversation(BuildContext context) {
|
||||
Navigator.of(context)
|
||||
.push(MaterialPageRoute(builder: (c) => CreateConversationRoute()));
|
||||
void _createConversation() {
|
||||
HomeController.of(context).push(CreateConversationScreen());
|
||||
}
|
||||
|
||||
/// Handle conversations updated requests
|
||||
void _updateConversation(Conversation conversation) {
|
||||
Navigator.of(context).push(
|
||||
MaterialPageRoute(
|
||||
builder: (c) => UpdateConversationRoute(
|
||||
conversationID: conversation.id,
|
||||
),
|
||||
HomeController.of(context).push(
|
||||
UpdateConversationRoute(
|
||||
conversationID: conversation.id,
|
||||
),
|
||||
);
|
||||
}
|
||||
@ -181,7 +174,7 @@ class _ConversationScreenState extends State<ConversationsListScreen> {
|
||||
conversation: _list.elementAt(index),
|
||||
usersList: _list.users,
|
||||
onOpen: (c) {
|
||||
_openConversation(context, c.id);
|
||||
_openConversation(c.id);
|
||||
},
|
||||
onRequestUpdate: _updateConversation,
|
||||
onRequestDelete: _requestDeleteConversation,
|
||||
@ -199,7 +192,7 @@ class _ConversationScreenState extends State<ConversationsListScreen> {
|
||||
right: 20.0,
|
||||
bottom: 20.0,
|
||||
child: FloatingActionButton(
|
||||
onPressed: () => _createConversation(context),
|
||||
onPressed: () => _createConversation(),
|
||||
child: Icon(Icons.add),
|
||||
),
|
||||
),
|
||||
|
@ -1,4 +1,5 @@
|
||||
import 'package:comunic/ui/screens/update_conversation_screen.dart';
|
||||
import 'package:comunic/ui/widgets/comunic_back_button_widget.dart';
|
||||
import 'package:comunic/utils/intl_utils.dart';
|
||||
import 'package:flutter/material.dart';
|
||||
|
||||
@ -6,14 +7,14 @@ import 'package:flutter/material.dart';
|
||||
///
|
||||
/// @author Pierre HUBERT
|
||||
|
||||
class CreateConversationRoute extends StatelessWidget {
|
||||
class CreateConversationScreen extends StatelessWidget {
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
return Scaffold(
|
||||
appBar: AppBar(
|
||||
leading: ComunicBackButton(),
|
||||
title: Text(tr("Create a conversation")),
|
||||
),
|
||||
|
||||
body: UpdateConversationScreen(),
|
||||
);
|
||||
}
|
@ -1,7 +1,7 @@
|
||||
import 'package:comunic/helpers/conversations_helper.dart';
|
||||
import 'package:comunic/lists/users_list.dart';
|
||||
import 'package:comunic/models/conversation.dart';
|
||||
import 'package:comunic/ui/routes/conversation_route.dart';
|
||||
import 'package:comunic/ui/routes/home_route.dart';
|
||||
import 'package:comunic/ui/tiles/simple_user_tile.dart';
|
||||
import 'package:comunic/ui/widgets/pick_user_widget.dart';
|
||||
import 'package:comunic/utils/intl_utils.dart';
|
||||
@ -71,8 +71,8 @@ class _UpdateConversationScreen extends State<UpdateConversationScreen> {
|
||||
label: tr("Add member"),
|
||||
enabled: isOwner,
|
||||
onSelectUser: (user) => setState(() {
|
||||
if (!_members.contains(user)) _members.add(user);
|
||||
}),
|
||||
if (!_members.contains(user)) _members.add(user);
|
||||
}),
|
||||
),
|
||||
|
||||
//Conversation members
|
||||
@ -91,11 +91,11 @@ class _UpdateConversationScreen extends State<UpdateConversationScreen> {
|
||||
_membersMenuItemSelected(i, choice),
|
||||
itemBuilder: (c) =>
|
||||
<PopupMenuEntry<_MembersMenuChoices>>[
|
||||
PopupMenuItem(
|
||||
child: Text(tr("Remove")),
|
||||
value: _MembersMenuChoices.REMOVE,
|
||||
)
|
||||
],
|
||||
PopupMenuItem(
|
||||
child: Text(tr("Remove")),
|
||||
value: _MembersMenuChoices.REMOVE,
|
||||
)
|
||||
],
|
||||
)
|
||||
: null,
|
||||
);
|
||||
@ -110,8 +110,8 @@ class _UpdateConversationScreen extends State<UpdateConversationScreen> {
|
||||
Switch(
|
||||
value: _followConversation,
|
||||
onChanged: (b) => setState(() {
|
||||
_followConversation = b;
|
||||
}),
|
||||
_followConversation = b;
|
||||
}),
|
||||
),
|
||||
Text(tr("Follow conversation"))
|
||||
],
|
||||
@ -158,7 +158,8 @@ class _UpdateConversationScreen extends State<UpdateConversationScreen> {
|
||||
if (isUpdating)
|
||||
error = !(await ConversationsHelper().updateConversation(settings));
|
||||
else {
|
||||
conversationID = await ConversationsHelper().createConversation(settings);
|
||||
conversationID =
|
||||
await ConversationsHelper().createConversation(settings);
|
||||
if (conversationID < 1) error = true;
|
||||
}
|
||||
|
||||
@ -172,9 +173,9 @@ class _UpdateConversationScreen extends State<UpdateConversationScreen> {
|
||||
));
|
||||
|
||||
// Open the conversation
|
||||
Navigator.of(context).pushReplacement(MaterialPageRoute(
|
||||
builder: (c) => ConversationRoute(
|
||||
conversationID: conversationID,
|
||||
)));
|
||||
|
||||
HomeController.of(context).popPage();
|
||||
if (!isUpdating)
|
||||
HomeController.of(context).openConversation(conversationID);
|
||||
}
|
||||
}
|
||||
|
11
lib/ui/widgets/comunic_back_button_widget.dart
Normal file
11
lib/ui/widgets/comunic_back_button_widget.dart
Normal file
@ -0,0 +1,11 @@
|
||||
import 'package:comunic/utils/navigation_utils.dart';
|
||||
import 'package:flutter/material.dart';
|
||||
|
||||
class ComunicBackButton extends StatelessWidget {
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
return BackButton(
|
||||
onPressed: () => popPage(context),
|
||||
);
|
||||
}
|
||||
}
|
@ -10,6 +10,7 @@ typedef OnSelectMenuAction = void Function(BarCallbackActions);
|
||||
|
||||
/// Callback actions
|
||||
enum BarCallbackActions {
|
||||
OPEN_CUSTOM_WIDGET,
|
||||
OPEN_NOTIFICATIONS,
|
||||
OPEN_CONVERSATIONS,
|
||||
OPEN_NEWEST_POSTS,
|
||||
@ -22,6 +23,7 @@ enum BarCallbackActions {
|
||||
OPEN_APP_SETTINGS,
|
||||
OPEN_USER_FRIENDS_LIST,
|
||||
OPEN_ABOUT_DIALOG,
|
||||
OPEN_CONVERSATION,
|
||||
NONE,
|
||||
ACTION_LOGOUT
|
||||
}
|
||||
|
@ -1,5 +1,5 @@
|
||||
import 'package:comunic/helpers/conversations_helper.dart';
|
||||
import 'package:comunic/ui/routes/conversation_route.dart';
|
||||
import 'package:comunic/ui/routes/home_route.dart';
|
||||
import 'package:comunic/utils/intl_utils.dart';
|
||||
import 'package:comunic/utils/ui_utils.dart';
|
||||
import 'package:flutter/material.dart';
|
||||
@ -18,13 +18,7 @@ Future<bool> openPrivateConversation(BuildContext context, int userID) async {
|
||||
}
|
||||
|
||||
// Open the conversation
|
||||
Navigator.of(context).push(
|
||||
MaterialPageRoute(
|
||||
builder: (c) => ConversationRoute(
|
||||
conversationID: convID,
|
||||
),
|
||||
),
|
||||
);
|
||||
HomeController.of(context).openConversation(convID);
|
||||
|
||||
// Success
|
||||
return true;
|
||||
|
@ -10,6 +10,11 @@ import 'package:meta/meta.dart';
|
||||
///
|
||||
/// @author Pierre HUBERT
|
||||
|
||||
/// Pop a page
|
||||
void popPage(BuildContext context) {
|
||||
HomeController.of(context).popPage();
|
||||
}
|
||||
|
||||
/// Open the page of a user
|
||||
void openUserPage({@required int userID, @required BuildContext context}) {
|
||||
assert(userID != null);
|
||||
@ -20,8 +25,7 @@ void openUserPage({@required int userID, @required BuildContext context}) {
|
||||
|
||||
/// Open a post in full screen
|
||||
void openPostFullScreen(int postID, BuildContext context) {
|
||||
Navigator.of(context)
|
||||
.push(MaterialPageRoute(builder: (c) => SinglePostRoute(postID: postID)));
|
||||
HomeController.of(context).push(SinglePostRoute(postID: postID));
|
||||
}
|
||||
|
||||
/// Open a virtual directory
|
||||
|
Loading…
Reference in New Issue
Block a user