mirror of
https://gitlab.com/comunic/comunicmobile
synced 2025-06-19 08:15:16 +00:00
Remove Navigator references from conversations pages
This commit is contained in:
@ -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,20 +0,0 @@
|
||||
import 'package:comunic/ui/screens/update_conversation_screen.dart';
|
||||
import 'package:comunic/utils/intl_utils.dart';
|
||||
import 'package:flutter/material.dart';
|
||||
|
||||
/// Create a new conversation route
|
||||
///
|
||||
/// @author Pierre HUBERT
|
||||
|
||||
class CreateConversationRoute extends StatelessWidget {
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
return Scaffold(
|
||||
appBar: AppBar(
|
||||
title: Text(tr("Create a conversation")),
|
||||
),
|
||||
|
||||
body: UpdateConversationScreen(),
|
||||
);
|
||||
}
|
||||
}
|
@ -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(),
|
||||
|
Reference in New Issue
Block a user