Home > other >  The named parameter 'body' isn't defined. in flutter app
The named parameter 'body' isn't defined. in flutter app

Time:01-20

error picture I want to add a background image png. but it gives me>>> The named parameter 'body' isn't defined. how can I FIX THIS ERROR

import 'package:flutter/material.dart';

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

  @override
  Widget build(BuildContext context) {
    return Scaffold(
    backgroundColor: Colors.white,
        appBar: AppBar(
          backgroundColor: Colors.white,

          body: Column(
              children: <Widget>\[
          Expanded(
          child: Container(
              height: MediaQuery.of(context).size.height*.4,
          padding: EdgeInsets.all(10.0),

          decoration: const BoxDecoration(
            image: DecorationImage(
              image: AssetImage("assets/images/girl.png"),
              fit: BoxFit.cover,

            ),
          ),
              
        ),
      flex: 2,
          ),
  ]
    ),
    ),
    );
  }
}

CodePudding user response:

Try below code you have wrote wrong code :

Refer Scaffold here

  @override
  Widget build(BuildContext context) {
    return Scaffold(
      backgroundColor: Colors.white,
      appBar: AppBar(
        backgroundColor: Colors.white,
        title: Text(
          'App Bar',
          style: TextStyle(
            color: Colors.black,
          ),
        ),
      ),
      body: Column(
        children: <Widget>[
          Expanded(
            child: Container(
              height: MediaQuery.of(context).size.height * .4,
              padding: EdgeInsets.all(10.0),
              decoration: const BoxDecoration(
                image: DecorationImage(
                  image: NetworkImage(
                      "https://miro.medium.com/max/1400/1*-6WdIcd88w3pfphHOYln3Q.png"),
                  fit: BoxFit.cover,
                ),
              ),
            ),
            flex: 2,
          ),
        ],
      ),
    );
  }

CodePudding user response:

You just need to close your AppBar Widget before starting body. body is an attribute of Scaffold tree but you put it in AppBar

Look below:

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

  @override
  Widget build(BuildContext context) {
    return Scaffold(
    backgroundColor: Colors.white,
        appBar: AppBar(
          backgroundColor: Colors.white,
              ), // Here were your problem
          body: Column(
              children: <Widget>[
          Expanded(
          child: Container(
              height: MediaQuery.of(context).size.height*.4,
          padding: EdgeInsets.all(10.0),

          decoration: const BoxDecoration(
            image: DecorationImage(
              image: AssetImage("assets/images/girl.png"),
              fit: BoxFit.cover,

            ),
          ),
              
        ),
      flex: 2,
          ),
  ]
    ),
    );
  }
}

CodePudding user response:

You are actually missing your AppBar circular closing braces

return Scaffold(
    backgroundColor: Colors.white,
        appBar: AppBar(
          backgroundColor: Colors.white,
)
  •  Tags:  
  • Related