Flutter don't find widget properties : 'child' isn't defined

Viewed 266

Because few guys posted some wrong solutions (that wasn't bad ideas), i replied to them then they deleted their posts. I got flag by moderation ... so i post every answer here.

1/ I'm trying to make a simple ElevatedButton using the child and onPressed Properties.

2/ I tried to follow the documentation available here: https://api.flutter.dev/flutter/material/ElevatedButton-class.html

I also used samples but every times i get the same error: "The named parameter 'child' isn't defined." ('onPressed' also not defined ...')

3/ A picture of the auto-completion properties: ElevatedButton Properties

Flutter version used: Flutter 2.0.4 • channel stable • https://github.com/flutter/flutter.git Framework • revision b1395592de (10 days ago) • 2021-04-01 14:25:01 -0700 Engine • revision 2dce47073a Tools • Dart 2.12.2

This is the full code, again i can run&debug but i still have Errors in my Visual studio compiler as you can see in the screenshot ... and i don't understand why.

I press F5 to run the Emulator then i use "fultter run" to start my app.

Problems

    import 'package:flutter/material.dart';

void main() => runApp(MaterialApp(
      home: Home(),
    ));

class Home extends StatelessWidget {
  @override
  Widget build(BuildContext context) {
    return Scaffold(
      appBar: AppBar(
        title: Text("HelloWorld"),
        centerTitle: true,
        backgroundColor: Colors.red[600],
      ),

      body: Center(
        child: Row(
          mainAxisAlignment: MainAxisAlignment.spaceEvenly,
          crossAxisAlignment: CrossAxisAlignment.center,
          children: [
            Text("Hello World"),
            ElevatedButton.icon(
              label: Text("Click"),
              icon: Icon(Icons.airplanemode_active),
              onPressed: () {},
            ),
            Container(
              color: Colors.lightBlue,
              padding: EdgeInsets.all(20.0),
              child: Text("container"),
            ),
          ],
        ),
      ),
      floatingActionButton: FloatingActionButton(
        child: Icon(Icons.add),
        backgroundColor: Colors.red[600],
        onPressed: () {},
      ),
      
      bottomNavigationBar: BottomAppBar(
        child: Container(
          height: 45,
          width: 100,
        ),
       
        color: Colors.pink,
      ),
      floatingActionButtonLocation: FloatingActionButtonLocation.centerDocked,
    );
  }
}

class TestFul extends StatefulWidget {
  @override
  _TestFulState createState() => _TestFulState();
}

class _TestFulState extends State<TestFul> {
  @override
  Widget build(BuildContext context) {
    return Container();
  }
}

Thanks everyone for your fast answer to my post.

surprisingly i can debug and run my code using my emulator. but i still have the errors as you can see in the image link: Problems

I tried to clean / caches / restart etc... but nothing change. And of course i'm importing the material.dart Is it maybe the Flutter 2.0.4 version the cause ?

PS: I'm coding on Visual Studio Code. I don't think that coding without take a look to the errors is a good practice ^^'.

1 Answers

enter image description here

I tried your code and it is executing perfectly on my system. If u still have issues with this Widget(ElevatedButton)then just try to use a simple button and wrap it inside a Card()

Card(
      elevation: 5,
      child: //Todo: button
)
Related