Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Flutter route problem with i don't know #3

Open
agentkolby opened this issue May 29, 2021 · 0 comments
Open

Flutter route problem with i don't know #3

agentkolby opened this issue May 29, 2021 · 0 comments

Comments

@agentkolby
Copy link

agentkolby commented May 29, 2021

hi, have big problem im fighting with it for 2 hours but still don't create a solution so i'm comming here and asking for help, yesterday when i was opening my app, everything was going great, today i changed a little bit my code, but i tried even delete this to check is it problem or not, when i deleted this it was still bad. This is my issue in terminal

The following assertion was thrown while handling a gesture:
Could not find a generator for route RouteSettings("/Category-meals", {id: c1, title: Italian}) in
the _WidgetsAppState.
Make sure your root app widget has provided a way to generate
this route.
Generators for routes are searched for in the following order:

  1. For the "/" route, the "home" property, if non-null, is used.
  2. Otherwise, the "routes" table is used, if it has an entry for the route.
  3. Otherwise, onGenerateRoute is called. It should return a non-null value for any valid route not
    handled by "home" and "routes".
  4. Finally if all else fails onUnknownRoute is called.
    Unfortunately, onUnknownRoute was not set.

And this is my files which using route command,

main.dart

`import 'package:flutter/material.dart';

import './category_meals.dart';
import 'categories_screen.dart';

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

class MyApp extends StatelessWidget {
  @override
  Widget build(BuildContext context) {
    return MaterialApp(
      title: 'DeliMeals',
      theme: ThemeData(
          primarySwatch: Colors.pink,
          accentColor: Colors.amber,
          canvasColor: Color.fromRGBO(255, 254, 229, 1),
          textTheme: ThemeData.light().textTheme.copyWith(
                bodyText1: TextStyle(
                  color: Color.fromRGBO(20, 51, 51, 1),
                ),
                bodyText2: TextStyle(
                  color: Color.fromRGBO(20, 51, 51, 1),
                ),
                headline6: TextStyle(
                  fontSize: 24,
                ),
              )),
      home: CategoriesScreen(),
      routes: {
        CategoryMeals.routeName: (ctx) => CategoryMeals(),
      },
    );
  }
}

class MyHomePage extends StatefulWidget {
  @override
  _MyHomePageState createState() => _MyHomePageState();
}

class _MyHomePageState extends State<MyHomePage> {
  @override
  Widget build(BuildContext context) {
    return Scaffold(
      appBar: AppBar(
        title: Text('DeliMeals'),
      ),
      body: Center(
        child: Text('Navigation Time!'),
      ),
    );
  }
}
`

category-meals.dart

`import 'package:flutter/material.dart';
import './dummy_data.dart';

class CategoryMeals extends StatelessWidget {
  static const routeName = 'Category-meals';
  /* final String categoryId;
  final String categoryTitle;
  
  CategoryMeals(this.categoryId, this.categoryTitle); */
  
  @override
  Widget build(BuildContext context) {
    final routesArgs = ModalRoute.of(context).settings.arguments as Map<String, String>;
    final categoryTitle = routesArgs['title'];
    final categoryId = routesArgs['id'];
    final categoryMeals = DUMMY_MEALS.where((meal) {
      return meal.categories.contains(categoryId);
    }).toList();
    return Scaffold(
      appBar: AppBar(
        title: Text(categoryTitle),
      ),
      body: ListView.builder(itemBuilder: (ctx, index) {
        return Text(categoryMeals[index].title);
      }, itemCount: categoryMeals.length,), 
    );
  }
}
`

category-items.dart

`import 'package:flutter/material.dart';
import './category_meals.dart';

class CategoryItem extends StatelessWidget {
  final String id;
  final String title;
  final Color color;

  CategoryItem(this.id, this.title, this.color);

  void selectCategory(BuildContext ctx) {
    Navigator.of(ctx).pushNamed('/Category-meals', arguments: {
      'id': id,
      'title': title
    });
  }

  @override
  Widget build(BuildContext context) {
    return InkWell(
      onTap: () => selectCategory(context),
      splashColor: Theme.of(context).primaryColor,
      borderRadius: BorderRadius.circular(15),
      child: Container(
        padding: const EdgeInsets.all(15),
        child: Text(
          title,
          style: Theme.of(context).textTheme.headline6,
        ),
        decoration: BoxDecoration(
          gradient: LinearGradient(
            colors: [
              color.withOpacity(0.7),
              color,
            ],
            begin: Alignment.topLeft,
            end: Alignment.bottomRight,
          ),
          borderRadius: BorderRadius.circular(15),
        ),
      ),
    );
  }
}

If someone know the solution i would be greatful for helping, and explaining what was wrong, thanks
Agentkolby

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Development

No branches or pull requests

1 participant