Home > OS >  I cant find anything wrong. why cant I add 2 containers in the Column
I cant find anything wrong. why cant I add 2 containers in the Column

Time:07-27

home: Scaffold(
        backgroundColor: Colors.teal,
        body: Column(
          children: [
            Container(
              color: Colors.red,
              width: 100,
              height: 100,
            )
            Container(
              color: Colors.blue,
              width: 100,
              height: 100,
            )

CodePudding user response:

You have forgot to include , end of the Container

Scaffold(
  backgroundColor: Colors.teal,
  body: Column(
    children: [
      Container(
        color: Colors.red,
        width: 100,
        height: 100,
      ), //this
      Container(
        color: Colors.blue,
        width: 100,
        height: 100,
      )
    ],
  ),
);

If you are using vs-code, try Error Lens extension enter image description here

CodePudding user response:

Since you have used home:Scaffold I believe you have a material app. If you had included const before the return Material app it will throw an error here.. also as @Yeasin Sheikh mentioned you have missed a , between Container widgets

import 'package:flutter/material.dart';

void main() {
  runApp(const MyApp());
}

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

  @override
  Widget build(BuildContext context) {
    return MaterialApp(
        home: Scaffold(
      body: Column(
        children: [
          Container(
            color: Colors.red,
            width: 100,
            height: 100,
          ),
          Container(
            color: Colors.blue,
            width: 100,
            height: 100,
          )
        ],
      ),
    ));
  }
}
  • Related