In flutter I am trying to build a very basic thing. Three elements on top of each other and vertically centered, like this:
I don’t want to use MaterialApp, so my code for now is this:
import 'package:flutter/material.dart';
void main() {
runApp(const MyApp());
}
class MyApp extends StatelessWidget {
const MyApp({super.key});
@override
Widget build(BuildContext context) {
return Container(
decoration: const BoxDecoration(color: Colors.black),
child: Row(children: [
Column(
children: const <Widget>[Text('ELE1')],
),
Column(
children: const <Widget>[Text('ELE2')],
),
Column(
children: const <Widget>[Text('ELE3')],
),
]),
);
}
}
But I am getting an error:
ErrorSummary(‘No Directionality widget found.’),
Which is odd because I thought a column could be contained in a row which in turn could be contained in a container, no ?
2
Answers
if you need to use MaterailApp this is how you use it
Rows
are horizontal,Columns
vertical. Just replacing thatRow
with aColumn
might do the trick for you, but it also it doesn’t make sense to have eachText
wrapped in its ownColumn
. So just replacewith