I have a question. Please see the image to understand better what I mean.
I want to create the yellow Containers like in the given image.
Here is my code:
import "package:flutter/material.dart";
void main(List<String> args) => runApp(const MyApp());
class MyApp extends StatelessWidget {
const MyApp({super.key});
@override
Widget build(BuildContext context) {
return const MaterialApp(
home: Mypage(),
);
}
}
class Mypage extends StatefulWidget {
const Mypage({super.key});
@override
State<Mypage> createState() => _MypageState();
}
class _MypageState extends State<Mypage> {
TextEditingController height_controller = TextEditingController(text: '');
@override
Widget build(BuildContext context) {
return Scaffold(
backgroundColor: Colors.grey.shade800,
appBar: AppBar(
centerTitle: true,
backgroundColor: Colors.grey.shade800,
title: const Text(
'BMI Calculator',
style: TextStyle(color: Colors.amber),
),
),
body: Padding(
padding: const EdgeInsets.all(20.0),
child: Column(
children: [
Row(
children: [
Align(
alignment: Alignment.topLeft,
child: SizedBox(
height: 150,
width: 150,
child: TextField(
controller: height_controller,
keyboardType: const TextInputType.numberWithOptions(),
decoration: const InputDecoration(
floatingLabelAlignment: FloatingLabelAlignment.center,
label: Text(
'Height',
style: TextStyle(color: Colors.amber, fontSize: 30),
textAlign: TextAlign.center,
),
),
),
),
),
const SizedBox(
width: 70,
),
const Align(
alignment: Alignment.topRight,
child: SizedBox(
height: 150,
width: 150,
child: TextField(
keyboardType: TextInputType.numberWithOptions(),
decoration: InputDecoration(
floatingLabelAlignment: FloatingLabelAlignment.center,
label: Text('Weight',
style:
TextStyle(color: Colors.amber, fontSize: 30)),
),
),
),
)
],
),
TextButton(
onPressed: () {},
child: const Text(
'Calculate',
style: TextStyle(color: Colors.amber, fontSize: 30),
),
),
const SizedBox(
height: 300,
),
Container(
alignment: Alignment.center,
height: 30,
width: 300,
decoration: BoxDecoration(
borderRadius: BorderRadius.circular(30), color: Colors.amber),
),
const SizedBox(
height: 30,
),
Container(
height: 30,
width: 300,
decoration: BoxDecoration(
borderRadius: BorderRadius.circular(30), color: Colors.amber),
),
],
),
),
);
}
}
2
Answers
SizedBox.expand > Column > [Expanded, Expanded] should give you a full-page with two equal vertical halves. Like this:
Wrap column widget with Stack and add column with all the top widget as a first one and in the second one add those containers wrapped in Align widget. this is how you can achieve what you want. You can take reference from below code snippet.