I am new to flutter and i think i have misunderstood the widget and layout system

Hugo Ekman

If I want to add more buttons and text widgets where and how should I do it, should I make some sort of colum and row system or am I totaly of?. And is my code programmed wrong?

import 'package:flutter/material.dart';

void main() {
  runApp(
    const HomeScreen(),
  );
}

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

  @override
  Widget build(BuildContext context) {
    return MaterialApp(
        home: Scaffold(
            appBar: AppBar(
              title: const Text('Dice'),
              centerTitle: true,
            ),
            body: const Dice()));
  }
}

class Dice extends StatefulWidget {
  const Dice({Key? key}) : super(key: key);

  @override
  State<Dice> createState() => _DiceState();
}

class _DiceState extends State<Dice> {
  @override
  Widget build(BuildContext context) {
    return Scaffold(
        body: Center(
      child: Row(
        children: [
          Expanded(
              child: Container(
                  margin: const EdgeInsets.all(15),
                  child: Image.asset('images/1.png'))),
          Expanded(
              child: Container(
                  margin: const EdgeInsets.all(15),
                  child: Image.asset('images/2.png'))),
          Expanded(
              child: Container(
                  margin: const EdgeInsets.all(15),
                  child: Image.asset('images/3.png'))),
          Expanded(
              child: Container(
                  margin: const EdgeInsets.all(15),
                  child: Image.asset('images/4.png'))),
          Expanded(
              child: Container(
                  margin: const EdgeInsets.all(15),
                  child: Image.asset('images/5.png')))
        ],
      ),
    ));
  }

}

I am going to add variables to the children in the container later.

Marcel Dz

For better understanding I would recommend you checking out this medium article. https://medium.com/flutter-community/flutter-layout-cheat-sheet-5363348d037e Here you can view all the important layout widgets you can use.

In general you have a widget tree starting by MaterialApp and you can add as many items as you want. In flutter if you want multiple widgets you can use Row and Columm for that. Both of them provides a children property in brackets [] there you can add multiple widgets inside separated by comma.

Most of the other widgets are also able to provide a children property where you can add even more children widgets. That’s how the widget tree in general works. Actually you have unlimited possibility’s.

Your code is totally fine. By the way you can also create custom widgets if the plenty widgets of flutter doesn’t fit your use case.

In your example you can add whatever you want in your row, text, more images, buttons, everything you like.

Here you can check out the official widget catalog of flutter: https://docs.flutter.dev/development/ui/widgets

Collected from the Internet

Please contact [email protected] to delete if infringement.

edited at
0

Comments

0 comments
Login to comment

Related

I think I have problem with compiling a java file

What have I misunderstood about keras layer sizes?

Have I misunderstood the scope of this default argument shared_ptr?

I am new to Flutter, I try to run my project on Android Studio but I get an error in the console like:

I have a problem with migration as I am new to Laravel. I have tried everything described on here with no success

How can I have widget sizes relative to the screen size in flutter?

I am coding Node struct and I think this is constructor initializer error

I am new to Prolog. I have tried to develop a major selection simple expert system, but I am stuck

@keyframes not working, I have tried everything i can think of

I am new to operating system, What is size of IDT?

So I have this text file that I am working with, and I want to use the info in it for my parking system

I am looking to buy a new hard drive and I wonder if I have to get the exact model

Wordpress "I think you have a wrond seperator"

I think i have done some mistake in allocating segmentcontrol..i am getting an error [unrecognized selector sent to instance]

Am I missing the obvious ? I think I will have to use ispostback here but not understanding how

Node module giving no output - have I misunderstood how to install it?

I have a trouble with layout

I am New To Flutter And I am In Bind with SetState Operation, I am Trying to Organize Code in a Block By Block way but setState is not working,

I think i have a problem with the parenthesces

I am using flutter bottomNavigatonBar widget, Is there anything which it can be raised?

I think is a problem from Node but I am not sure about it

Have I misunderstood how to use the abline function?

I am new to flutter, and I was following a tutorial but I get an error

I am not able to save a widget screenshot to gallery in flutter

I think i have done something that's setstate is not working in flutter

Can anyone can tell how to make this layout in flutter as i am new in flutter i am stuck in this

See attached snapshot. I have created such circle box through container in flutter. But I am seeking for widget. Do flutter have a widget for it?

Can I have a tab control in a widget contained in a layout?

I am creating a django review system. I think my Html is wrong