Reputation: 57
I want to put a text at the bottom but does not allow me to do so! It is a splash screen class. When I add another child it keeps on giving me error and when changing child to children also.
class SplashScreen extends StatefulWidget {
@override
_SplashScreenState createState() => _SplashScreenState();
}
class _SplashScreenState extends State<SplashScreen> {
startTime() async {
return Timer(
Duration(seconds: 2),
() => Navigator.of(context).pushReplacementNamed('/HomeScreen')
);
}
@override
void initState() {
super.initState();
startTime();
}
@override
Widget build(BuildContext context) {
return Scaffold(
body: Container(
decoration: BoxDecoration(color: Colors.blue[400]),
child: Center(
child: Image.asset('assets/bus.gif'),
)
,)
);
}
}
Upvotes: 3
Views: 13390
Reputation: 370
You will need to wrap those two widgets (image and bottom text) in the Column widget. The centered text will also be wrapped into Center and Expanded widgets, so your code should look like this.
body: Container(
decoration: BoxDecoration(color: Colors.blue[400]),
child: Column(
children: <Widget>[
Expanded(
child: Center(
child: Text("Centered text"),
),
),
Align(
alignment: Alignment.bottomCenter,
child: Text("Bottom text"),
)
],
),
),
You need to use Column so you can put multiple widgets into it (in this case, 2). The column will wrap its widget with height, because of that we are using Expanded widget which will Expand centered text to the whole screen and leave enough space for the bottom text to show. I hope this helps.
Upvotes: 7