1
0
mirror of https://gitlab.com/comunic/comunicmobile synced 2024-10-23 06:53:23 +00:00

Can specify arguments for pages

This commit is contained in:
Pierre HUBERT 2020-04-15 16:03:04 +02:00
parent b52748a93b
commit c7d8843f06

View File

@ -23,23 +23,35 @@ class HomeRoute extends StatefulWidget {
State<StatefulWidget> createState() => _HomeRouteState(); State<StatefulWidget> createState() => _HomeRouteState();
} }
class CurrPage {
final BarCallbackActions action;
final Map<String, dynamic> args;
const CurrPage(this.action, {this.args}) : assert(action != null);
}
class _HomeRouteState extends State<HomeRoute> { class _HomeRouteState extends State<HomeRoute> {
BarCallbackActions _currTab = BarCallbackActions.OPEN_CONVERSATIONS; CurrPage get _currTab => history.last;
List<BarCallbackActions> history = List(); List<CurrPage> history = List();
/// Change currently visible tab /// Change currently visible tab
void _changeTab(BarCallbackActions newTab) { void _pushPage(CurrPage newPage) {
setState(() { setState(() {
_currTab = newTab; history.add(newPage);
}); });
} }
/// Pop the page
void _popPage() {
history.removeLast();
setState(() {});
}
/// Allows to go to previous tab /// Allows to go to previous tab
Future<bool> _willPop() async { Future<bool> _willPop() async {
if (history.length == 1) return true; if (history.length == 1) return true;
history.removeLast(); _popPage();
_changeTab(history[history.length - 1]);
return false; return false;
} }
@ -64,20 +76,21 @@ class _HomeRouteState extends State<HomeRoute> {
break; break;
default: default:
if (_currTab != action) history.add(action); _pushPage(CurrPage(action));
_changeTab(action);
} }
} }
@override @override
void initState() { void initState() {
super.initState(); super.initState();
history.add(_currTab);
// Default page: conversations list
_pushPage(CurrPage(BarCallbackActions.OPEN_CONVERSATIONS));
} }
/// Build the body of the application /// Build the body of the application
Widget _buildBody(BuildContext context) { Widget _buildBody(BuildContext context) {
switch (_currTab) { switch (_currTab.action) {
case BarCallbackActions.OPEN_NOTIFICATIONS: case BarCallbackActions.OPEN_NOTIFICATIONS:
return NotificationsScreen(); return NotificationsScreen();
@ -109,7 +122,7 @@ class _HomeRouteState extends State<HomeRoute> {
child: Scaffold( child: Scaffold(
appBar: ComunicAppBar( appBar: ComunicAppBar(
onTap: _onTap, onTap: _onTap,
selectedAction: _currTab, selectedAction: _currTab.action,
), ),
body: SafeArea( body: SafeArea(
child: _buildBody(context), child: _buildBody(context),