-1

i am trying to put a drawer here but i keep getting an error. i have put a comment where the error is.Please check it out and help me.

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

AppBar appBar(String name) {

  return AppBar(
    leading: Text(""),
    title: Text(
      name,
      style: TextStyle(color: Colors.blue),
    ),
    // centerTitle: true,
    
    elevation: 0,
    backgroundColor: Colors.transparent,
    
    actions: <Widget>[
      IconButton(
          icon: Icon(
            Icons.notification_important,
            color: Colors.blue,
          ),
          onPressed: () {}),
      
    ],
 );
}

class Drawer extends StatefulWidget {
  @override
  _DrawerState createState() => _DrawerState ();
}


class _DrawerState extends State <Drawer> {

@override

Widget build(BuildContext context) {

    return Scaffold(
      

      drawer: new Drawer (

i get an error here that states that: The named parameter 'child' isn't defined. Try correcting the name to an existing named parameter's name, or defining a named parameter with the name 'child'. Can i please get some help in fixing this.

              child: <Widget>[

                ListView(
                
                  children : <Widget>[

                    ListTile(

                      onTap: (){},
                      leading: Icon(Icons.arrow_back),
                      title: Text("Back"),
  
                    ),

                    ListTile(

                      onTap: (){},
                      leading: Icon(Icons.home),
                      title: Text("Home"),
                    ),

                    ListTile(

                      onTap: (){},
                      leading: Icon(Icons.settings),
                      title: Text("Settings"),
                    ),


                     ListTile(

                      onTap: (){},
                      leading: Icon(Icons.mood_bad),
                      title: Text("Logout"),
                    ),
            ]
          ),
        ],               

      ),

     
    );
  }


}
Doug Stevenson
  • 297,357
  • 32
  • 422
  • 441
Manuel
  • 23
  • 3

2 Answers2

0

You named your class "Drawer", which overwrites the default class. Just change your class to "MyDrawer".

And you need to have a Widget not a list of widget as a child but I'm sure you will be able to fix that.

Lulupointu
  • 3,364
  • 1
  • 12
  • 28
0

child can be Widget not a List<Widget> and also rename the class to something else dont use Drawer.

drawer: Drawer(
        child: ListView(
          children: [
            ListTile(
              onTap: () {},
              leading: Icon(Icons.arrow_back),
              title: Text("Back"),
            ),
            ListTile(
              onTap: () {},
              leading: Icon(Icons.home),
              title: Text("Home"),
            ),
            ListTile(
              onTap: () {},
              leading: Icon(Icons.settings),
              title: Text("Settings"),
            ),
            ListTile(
              onTap: () {},
              leading: Icon(Icons.mood_bad),
              title: Text("Logout"),
            ),
          ],
        ),
      ),

Hope this will fix your issue

Sachin Bhankhar
  • 900
  • 8
  • 14