Reputation: 127
How to add a button,this button bottom of screen and top of listview? like this
Upvotes: 5
Views: 17499
Reputation: 7492
You can just do it using 'Stack' widget.
import 'package:flutter/material.dart';
void main() {
runApp(MyApp());
}
class MyApp extends StatelessWidget {
@override
Widget build(BuildContext context) {
return MaterialApp(
title: 'Flutter Demo',
theme: ThemeData(
primarySwatch: Colors.blue,
visualDensity: VisualDensity.adaptivePlatformDensity,
),
home: MyHomePage(title: 'Flutter Demo Home Page'),
);
}
}
class MyHomePage extends StatefulWidget {
MyHomePage({Key key, this.title}) : super(key: key);
final String title;
@override
_MyHomePageState createState() => _MyHomePageState();
}
class _MyHomePageState extends State<MyHomePage> {
@override
void initState() {
super.initState();
}
@override
Widget build(BuildContext context) {
return Scaffold(
appBar: AppBar(
title: Text(widget.title),
),
body: _buildBody(),
);
}
Widget _buildBody() {
return Stack(
children: <Widget>[
ListView.builder(
itemCount: 50,
itemBuilder: (context, index) {
return Container(
height: 30,
padding: EdgeInsets.symmetric(horizontal: 20),
child: Text('$index'),
);
},
),
Align(
alignment: Alignment.bottomCenter,
child: Container(
margin: EdgeInsets.symmetric(horizontal: 20, vertical: 40),
width: double.infinity,
child: FlatButton(
child: Text('FlatButton', style: TextStyle(fontSize: 24)),
onPressed: () => {},
color: Colors.green,
textColor: Colors.white,
),
),
),
],
);
}
}
Upvotes: 13