luffy
luffy

Reputation: 51

parameter getPages is not defined

I'm trying to learn to use get, but I'm having a few problems where getPages isn't defined, this is my code, and I hope you can help me. I know it is not defined but isn't it included in the package that I imported?

import 'package:flutter/material.dart';
import 'package:todos/routes.dart';



void main() {
  runApp(const MyApp());
}

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.blue,
        fontFamily: "Poppins"
      ),
      initialRoute: GetRoutes.login,
      getPages: GetRoutes.routes, //This line here isn't defined



    );
  }
}

and this is my GetRoutes class

class GetRoutes{


  static const String login = "/login";
  static const String signup = "/signup";
  static const String home = "/home";


  static List<GetPage> routes = [

    GetPage(
      name: GetRoutes.login,
       page: () => const LoginScreen()
       ),
    GetPage(
      name: GetRoutes.signup,
       page: () => const SignupScreen(),
       ),


  ];
}

Upvotes: 1

Views: 520

Answers (1)

Md. Yeasin Sheikh
Md. Yeasin Sheikh

Reputation: 63769

Change MaterialApp to GetMaterialApp

 @override
  Widget build(BuildContext context) {
    return GetMaterialApp(

Also you can use just MaterialApp with routes like

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

  @override
  Widget build(BuildContext context) {
    return MaterialApp(
      title: 'Flutter Demo',
      theme: ThemeData(primarySwatch: Colors.blue, fontFamily: "Poppins"),
      initialRoute: GetRoutes.login,
      routes: GetRoutes.routes,
    );
  }
}

class GetRoutes {
  static const String login = "/login";
  static const String signup = "/signup";
  static const String home = "/home";

  static var routes = {
    login: (_) => LoginPage(),
    // add others
  };
}

Upvotes: 2

Related Questions