Home > Blockchain >  could not find a generator for route RouteSettings("org_Item", null) in the _WidgetsAppSta
could not find a generator for route RouteSettings("org_Item", null) in the _WidgetsAppSta

Time:09-04

I´m newbie to flutter and reveice one exception about route, I don't why I am getting this error in the debug console 'could not find a generator for route RouteSettings("org_Item", null) in the _WidgetsAppState.'

provinces_item.dart

import 'package:flutter/foundation.dart';
import 'package:flutter/material.dart';
import 'package:let_us_volunteer/screens/orgscreen.dart';

class provwidget extends StatelessWidget {
  final String id;
  final String title;
  final String image;
  provwidget(this.id, this.title, this.image);
  void selectOrg(BuildContext ctx) {
    Navigator.of(ctx).pushNamed(orgscreen.routeName);
  }

  @override
  Widget build(BuildContext context) {
    return InkWell(
      onTap: () => selectOrg(context),
      child: Image.asset(image),
    );
  }
}

main.dart

import 'package:flutter/material.dart';
import 'package:let_us_volunteer/screens/log_in.dart';
import 'screens/page_view.dart';
import 'screens/log_in.dart';
import 'screens/orgscreen.dart';

void main() async {
  runApp(page_view());
}

class MyApp extends StatelessWidget {
  const MyApp({Key? key}) : super(key: key);

  // This widget is the root of your application.
  @override
  Widget build(BuildContext context) {
    return MaterialApp(
      title: 'flutter demo',
      theme: ThemeData(
        primarySwatch: Colors.purple,
        primaryColor: Colors.purple,
      ),
      home: const log_in_screen(),
      routes: {
        '/': (context) => log_in_screen(),
        orgscreen.routeName: (context) => orgscreen(),
      },
    );
  }
}

orgscreen.dart

import 'package:flutter/material.dart';

class orgscreen extends StatefulWidget {
  static const routeName = 'org_Item';

  @override
  State<orgscreen> createState() => _orgscreenState();
}

class _orgscreenState extends State<orgscreen> {
  @override
  Widget build(BuildContext context) {
    return Scaffold(
      appBar: AppBar(title: Text('ggg')),
      body: null,
    );
  }
}

If someone knows the solution it would be grateful for help, and explaining what was wrong, thanks

CodePudding user response:

Try to remove your home: const log_in_screen(), and for format case use '/org_Item';

title: 'flutter demo',
theme: ThemeData(
  primarySwatch: Colors.purple,
  primaryColor: Colors.purple,
),
routes: {
  '/': (context) => log_in_screen(),
  orgscreen.routeName: (context) => orgscreen(),
},

And not sure about your page_view, you can check

 runApp(MyApp());

CodePudding user response:

The correct way of define route is use / with it, So change your route to this:

static const routeName = '/org_Item';

when yo do not run your main class (MyApp) in your runApp, it can not define that route, so also correct this:

runApp(MyApp());

last thing when you define / this in your routes, you should not use home property of MaterialApp, so remove home: const log_in_screen(), and your final MaterialApp should look like this:

MaterialApp(
      title: 'flutter demo',
      theme: ThemeData(
        primarySwatch: Colors.purple,
        primaryColor: Colors.purple,
      ),
      routes: {
        '/': (context) => log_in_screen(),
        orgscreen.routeName: (context) => orgscreen(),
      },
    )
  • Related