mirror of
				https://gitlab.com/comunic/comunicmobile
				synced 2025-11-03 19:54:12 +00:00 
			
		
		
		
	Can specify arguments for pages
This commit is contained in:
		@@ -23,23 +23,35 @@ class HomeRoute extends StatefulWidget {
 | 
			
		||||
  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> {
 | 
			
		||||
  BarCallbackActions _currTab = BarCallbackActions.OPEN_CONVERSATIONS;
 | 
			
		||||
  List<BarCallbackActions> history = List();
 | 
			
		||||
  CurrPage get _currTab => history.last;
 | 
			
		||||
  List<CurrPage> history = List();
 | 
			
		||||
 | 
			
		||||
  /// Change currently visible tab
 | 
			
		||||
  void _changeTab(BarCallbackActions newTab) {
 | 
			
		||||
  void _pushPage(CurrPage newPage) {
 | 
			
		||||
    setState(() {
 | 
			
		||||
      _currTab = newTab;
 | 
			
		||||
      history.add(newPage);
 | 
			
		||||
    });
 | 
			
		||||
  }
 | 
			
		||||
 | 
			
		||||
  /// Pop the page
 | 
			
		||||
  void _popPage() {
 | 
			
		||||
    history.removeLast();
 | 
			
		||||
    setState(() {});
 | 
			
		||||
  }
 | 
			
		||||
 | 
			
		||||
  /// Allows to go to previous tab
 | 
			
		||||
  Future<bool> _willPop() async {
 | 
			
		||||
    if (history.length == 1) return true;
 | 
			
		||||
 | 
			
		||||
    history.removeLast();
 | 
			
		||||
    _changeTab(history[history.length - 1]);
 | 
			
		||||
    _popPage();
 | 
			
		||||
    return false;
 | 
			
		||||
  }
 | 
			
		||||
 | 
			
		||||
@@ -64,20 +76,21 @@ class _HomeRouteState extends State<HomeRoute> {
 | 
			
		||||
        break;
 | 
			
		||||
 | 
			
		||||
      default:
 | 
			
		||||
        if (_currTab != action) history.add(action);
 | 
			
		||||
        _changeTab(action);
 | 
			
		||||
        _pushPage(CurrPage(action));
 | 
			
		||||
    }
 | 
			
		||||
  }
 | 
			
		||||
 | 
			
		||||
  @override
 | 
			
		||||
  void initState() {
 | 
			
		||||
    super.initState();
 | 
			
		||||
    history.add(_currTab);
 | 
			
		||||
 | 
			
		||||
    // Default page: conversations list
 | 
			
		||||
    _pushPage(CurrPage(BarCallbackActions.OPEN_CONVERSATIONS));
 | 
			
		||||
  }
 | 
			
		||||
 | 
			
		||||
  /// Build the body of the application
 | 
			
		||||
  Widget _buildBody(BuildContext context) {
 | 
			
		||||
    switch (_currTab) {
 | 
			
		||||
    switch (_currTab.action) {
 | 
			
		||||
      case BarCallbackActions.OPEN_NOTIFICATIONS:
 | 
			
		||||
        return NotificationsScreen();
 | 
			
		||||
 | 
			
		||||
@@ -109,7 +122,7 @@ class _HomeRouteState extends State<HomeRoute> {
 | 
			
		||||
          child: Scaffold(
 | 
			
		||||
            appBar: ComunicAppBar(
 | 
			
		||||
              onTap: _onTap,
 | 
			
		||||
              selectedAction: _currTab,
 | 
			
		||||
              selectedAction: _currTab.action,
 | 
			
		||||
            ),
 | 
			
		||||
            body: SafeArea(
 | 
			
		||||
              child: _buildBody(context),
 | 
			
		||||
 
 | 
			
		||||
		Reference in New Issue
	
	Block a user