Reputation: 3
i just started to learn flutter and I have a problem for making layout like this picture below, what code for make layout enter image description here
Here is my code :
import 'package:flutter/material.dart';
void main() {
runApp(MyApp());
}
class MyApp extends StatelessWidget {
@override
Widget build(BuildContext context) {
return MaterialApp(
home: Scaffold(
backgroundColor: Colors.teal,
body: SafeArea(
child: Column(
crossAxisAlignment: CrossAxisAlignment.stretch,
children: <Widget>[
Container(
height: 100.0,
color: Colors.white,
child: Text('Container 1'),
),
SizedBox(
height: 20.0,
),
Container(
height: 100.0,
color: Colors.blue,
child: Text('Container 2'),
),
SizedBox(
height: 20.0,
),
Container(
height: 100.0,
color: Colors.red,
child: Text('Container 3'),
),
],
),
),
),
);
}
}
From that code that I write, absolutely different from what i expected to be, please help, i'm new on this and want to make one step ahead for my skill to be better. Thank you...
Upvotes: 0
Views: 1189
Reputation: 14305
I just convert your Column
Widget to Row
and add one center widget inside with Expand
and add Column
widget there.
child: Row(
crossAxisAlignment: CrossAxisAlignment.stretch,
children: <Widget>[
Container(
color: Colors.red,
height: 100.0,
width: 100.0,
),
Expanded(
child: Column(
mainAxisAlignment: MainAxisAlignment.center,
children: <Widget>[
Container(
color: Colors.yellow,
height: 100.0,
width: 100.0,
),
Container(
color: Colors.green,
height: 100.0,
width: 100.0,
)
],
),
),
Container(
color: Colors.blue,
height: 100.0,
width: 100.0,
),
],
),
Upvotes: 1
Reputation: 1187
Here you go
Scaffold(
backgroundColor: Colors.teal,
body: Container(
child: Row(
crossAxisAlignment: CrossAxisAlignment.stretch,
children: <Widget>[
Container(
color: Colors.red,
height: 100.0,
width: 100.0,
),
Expanded(
child: Column(
crossAxisAlignment: CrossAxisAlignment.center,
mainAxisAlignment: MainAxisAlignment.center,
children: <Widget>[
Container(
color: Colors.yellow,
height: 100.0,
width: 100.0,
)
],
),
),
Container(
color: Colors.blue,
height: 100.0,
width: 100.0,
),
],
),
),
),
Upvotes: 0