0

I'm new to flutter and java script. So I have very little experience. I want to write a small application. I made 2 pages where the list of seals and the list of objects are pulled up on api. But I want to be able to navigate through these pages through the side menu. I created this menu. But I can not go to another page from this menu. Here is my application (main). I will be grateful for your help.

import 'package:flutter/material.dart';
import 'package:flutter_app_seals/model/object_list/JsonObject.dart';
import 'package:flutter_app_seals/model/seals_list/JsonSeals.dart';

void main() {
  runApp(Mains());

}


class Mains extends StatelessWidget {
  @override
  Widget build(BuildContext context) {
    return MaterialApp(
        debugShowCheckedModeBanner: false,
        home: Scaffold(
            appBar: AppBar(
            centerTitle: true,
              title: Text('Seals Log'),
    ),
              drawer: Drawer(
               child: ListView(
               children: <Widget>[
                    ListTile(
                      title: Text("Seals List"),
                      trailing: Icon(Icons.arrow_back),
                        onTap:() {
                          Navigator.push(
                            context,
                            MaterialPageRoute(builder: (context) => Seals()),
                          );
                        }

                    ),
                      ListTile(
                        title: Text("Object List"),
                        trailing: Icon(Icons.arrow_downward),
                          onTap:() {
                            Navigator.push(
                              context,
                              MaterialPageRoute(builder: (context) => Object()),
                            );
                          }
                      )
                ],
             ),
           ),

         )
    );
  }
}
class Seals extends StatelessWidget {
  @override
  Widget build(BuildContext context) {
    return MaterialApp(
        debugShowCheckedModeBanner: false,
        home:JsonParseSeals(),
      
    );
  }
}

class Object extends StatelessWidget {
  @override
  Widget build(BuildContext context) {
    return MaterialApp(
        debugShowCheckedModeBanner: false,
        home:JsonParseObject()
    );
  }
}
Error:

======== Exception caught by gesture ===============================================================
The following assertion was thrown while handling a gesture:
Navigator operation requested with a context that does not include a Navigator.

The context used to push or pop routes from the Navigator must be that of a widget that is a descendant of a Navigator widget.
When the exception was thrown, this was the stack: 
dart-sdk/lib/_internal/js_dev_runtime/private/ddc_runtime/errors.dart 231:49  throw_
packages/flutter/src/widgets/navigator.dart 2690:9                            <fn>
packages/flutter/src/widgets/navigator.dart 2696:14                           of
packages/flutter/src/widgets/navigator.dart 2095:34                           push
packages/flutter_app_seals/main.dart 41:39                                    <fn>
...
Handler: "onTap"
Recognizer: TapGestureRecognizer#d2f91
  debugOwner: GestureDetector
  state: ready
  won arena
  finalPosition: Offset(63.0, 65.0)
  finalLocalPosition: Offset(63.0, 17.0)
  button: 1
  sent tap down
====================================================================================================
MaksIngenr
  • 61
  • 9

1 Answers1

0

Add onTap action to your ListTile:

ListTile(
  title: Text("Seals list"),
  trailing: Icon(Icons.arrow_back),
  onTap() {
    Navigator.push(
      context,
      MaterialPageRoute(builder: (context) => Object_list()),
    );
  }
),

You can read more in Official Documentation.

fartem
  • 2,361
  • 2
  • 8
  • 20