Click here to Skip to main content
15,891,431 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
In this, I think I am getting errors at the navigators. If I comment both of them out the app runs fine(except the page change). The first navigator is giving this error when I comment it out .The second navigator is working but not as it is supposed to (it gets called when I click on the drawer Icon rather than when i click on the settings icon).

import 'package:flutter/material.dart';
import 'package:meals_app/Screens/Filters_screen.dart';

class MainDrawer extends StatelessWidget {
  const MainDrawer({Key? key}) : super(key: key);
  Widget buildListTile(String title, IconData icon, Function tapHandler) {
    return ListTile(
      leading: Icon(
        icon,
        size: 26,
      ),
      title: Text(
        title,
        style: TextStyle(
            fontFamily: 'RobotoCondensed',
            fontSize: 24,
            fontWeight: FontWeight.bold),
      ),
      onTap: tapHandler(),
    );
  }

  @override
  Widget build(BuildContext context) {
    return Drawer(
      child: Column(children: <Widget>[
        Container(
          height: 120,
          width: double.infinity,
          padding: EdgeInsets.all(20),
          alignment: Alignment.centerLeft,
          color: Colors.white,
          child: Text(
            'data coming',
            style: TextStyle(
                fontWeight: FontWeight.w900, fontSize: 30, color: Colors.black),
          ),
        ),
        SizedBox(
          height: 20,
        ),
        buildListTile('Meals', Icons.restaurant, () {
          Navigator.of(context).pushNamed('/');
        }),
        buildListTile('Settings', Icons.settings, () {
          Navigator.of(context).pushNamed(Filterscreen.routeName);
        })
      ]),
    );
  }
}


This is the drawerscreen ^^

Main.dart-

import 'package:flutter/material.dart';
import 'package:meals_app/Screens/Filters_screen.dart';
import 'package:meals_app/Screens/category_meals_screen.dart';
import 'package:meals_app/Screens/catogeries_screen.dart';
import 'package:meals_app/Screens/meal_detail_screen.dart';
import 'package:meals_app/Screens/tabs_screen.dart';

void main() => runApp(MyApp());

class MyApp extends StatelessWidget {
  const MyApp({Key? key}) : super(key: key);
  @override
  Widget build(BuildContext context) {
    return MaterialApp(
      title: 'MealsApp',
      theme: ThemeData(
        primarySwatch: Colors.blue,
        accentColor: Colors.greenAccent,
        canvasColor: const Color.fromRGBO(255, 253, 220, 1),
        fontFamily: 'Raleway',
        textTheme: ThemeData.light().textTheme.copyWith(
              bodyText1: const TextStyle(color: Colors.red),
              bodyText2: const TextStyle(
                  color: Colors.black12,
                  fontWeight: FontWeight.bold,
                  fontFamily: 'RobotoCondensed',
                  fontSize: 24),
            ),
      ),
      home: TabScreen(), 
      initialRoute: '/',
      routes: {
        // '/': (ctx) => TabScreen(), //This is our default route
        CategoryMealScreen.routeName: (ctx) => CategoryMealScreen(),
        MealDeatilScreen.routeName: (ctx) => MealDeatilScreen(),
        Filterscreen.routeName: (ctx) => Filterscreen(),
      },
     
      onUnknownRoute: (settings) {
        return MaterialPageRoute(builder: (ctx) => categorieScreen());
      }, 
    );
  }
}


What I have tried:

I tried wrapping it(1st navigator) in addPostFrameCallback but it did not work
Posted

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)

  Print Answers RSS
Top Experts
Last 24hrsThis month


CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900