Home > database >  SizedBox in flutter has 0 argument?
SizedBox in flutter has 0 argument?

Time:08-24

I'm a beginner at flutter. I'm practicing to make in Scaffold. In my code, the last area that Sized Box has errors in child and elevation, and color. I don't understand why they are used in not correctly, Could you explain that to me?

enter image description here

import 'package:flutter/material.dart';

void main() => runApp(MyApp());


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

  @override
  Widget build(BuildContext context) {
    return MaterialApp(
    home:Scaffold(

      appBar: AppBar(
        backgroundColor: Colors.white,
        leading: IconButton(
          icon: Icon(Icons.menu, color: Colors.pink,),
          onPressed: () {
            print("menu button is clicked");
          }
        ),
        title: IconButton(
          onPressed: () { print("이미지버튼 동작"); },
          icon: Image.asset('assets/images/Slimer_by_shinrider-dcqaiza.webp')),
        ),
        body: Container(
          width: 100,
          height: 200,
          margin: EdgeInsets.all(5.0),
          decoration: BoxDecoration(
              color: Colors.pinkAccent,
              border: Border.all(color: Colors.purple)
          ),
        ),
        child: SizedBox(
              height: 80, width: 100,
              child: Card(
                shape: RoundedRectangleBorder(
                  borderRadius: BorderRadius.circular(16.0)
                ),
              ),
              elevation: 4.0,
              color: Colors.red
            )
        )


    );
  }
}

CodePudding user response:

your body is Container, which is only need 1 Widget as child.

if you want to use more than 1 Widget , you need to wrap your children that provide List<Widget> as their children.

such as : Column, Row , ListView, etc.

What you miss is you add 1 close bracket in your code

        body: Container(
          width: 100,
          height: 200,
          margin: EdgeInsets.all(5.0),
          decoration: BoxDecoration(
              color: Colors.pinkAccent,
              border: Border.all(color: Colors.purple)
          ),
        ),   <= here your error , you close your container , so your child not included inside the container.

remove what i notice above

CodePudding user response:

You have closed Container and Card early on. Please check below against yours and use below to fix the issue.

void main() => runApp(MyApp());

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

  @override
  Widget build(BuildContext context) {
    return MaterialApp(
        home: Scaffold(
            appBar: AppBar(
              backgroundColor: Colors.white,
              leading: IconButton(
                  icon: Icon(
                    Icons.menu,
                    color: Colors.pink,
                  ),
                  onPressed: () {
                    print("menu button is clicked");
                  }),
              title: IconButton(
                  onPressed: () {
                    print("이미지버튼 동작");
                  },
                  icon: Image.asset(
                      'assets/images/Slimer_by_shinrider-dcqaiza.webp')),
            ),
            body: Container(
                width: 100,
                height: 200,
                margin: EdgeInsets.all(5.0),
                decoration: BoxDecoration(
                    color: Colors.pinkAccent,
                    border: Border.all(color: Colors.purple)),
                child: SizedBox(
                    height: 80,
                    width: 100,
                    child: Card(
                        shape: RoundedRectangleBorder(
                            borderRadius: BorderRadius.circular(16.0)),
                        elevation: 4.0,
                        color: Colors.red)))));
  }
}
  • Related