Home > Software engineering >  How do I convert the navigator to getx
How do I convert the navigator to getx

Time:09-02

Here I have this source code,

Navigator.push(context, MaterialPageRoute(builder:(context)=>Show(url:i)));

then I want to change it to getx, what does it look like?

After the code is changed to getx, then I want to display it by taking the data from the action along with my source code

Class Show extends StatefulWidget {
  String url;
  Show({Key key, @required this.url}) : super(key: key);
  @override
  _ShowSate createState() => new _ShowState();
}

class _ShowState extends State<Show> {
  @override
  Widget build(BuildContext context){
     return new Scaffold(
       appBar: AppBar(
         title: Text("Image"),
       ),
       body: Image.network(widget.url, width: double.infinity,),
       );
     }
  }

can friends help me to change my source to getx ?

Actually I want to make like this but by using getx https://www.youtube.com/watch?v=l9XOUoJsdy4

CodePudding user response:

its simple and street forward read the documentation https://pub.dev/packages/get the solution is Get.to(()=>Show(url:i)); or Get.to(Show(url:i));

CodePudding user response:

First in main.dart, change the MaterialApp widget to GetMaterialApp widget then and then only GetX Navigation Management Technique would work

From:

class MyApp extends StatelessWidget {
  @override
  Widget build(BuildContext context) {
    return MaterialApp(
      home:Home(),
    );
  }
}

To:

class MyApp extends StatelessWidget {
  @override
  Widget build(BuildContext context) {
    return GetMaterialApp(
      home: Home(),
    );
  }
}

Now you can use the Getx Navigation.

From:

Navigator.push(context, MaterialPageRoute(builder: (context)=>Second()));

To:

Get.to(Second());

If we want to pass data through the navigator then we use below method :

// for passing single argument
Get.to(Second(),arguments:"Hello World!");

// for passing multiple argument 
Get.to(Second(),arguments:[10,20]);
  • Related