How To Make Modal Bottom Sheet with Text Fields inside in Flutter | Mobile App Development
Modal Bottom Sheet with Text Fields inside
Source Code
import 'package:flutter/material.dart';
void main() {
runApp(MyApp());
}
class MyApp extends StatelessWidget {
@override
Widget build(BuildContext context) {
return MaterialApp(
// Remove the debug banner
debugShowCheckedModeBanner: false,
title: 'Bottom Sheet',
home: HomeScreen(),
);
}
}
class HomeScreen extends StatelessWidget {
// This function is triggered when the floating buttion is pressed
void _show(BuildContext ctx) {
showModalBottomSheet(
isScrollControlled: true,
elevation: 5,
context: ctx,
builder: (ctx) => Padding(
padding: EdgeInsets.all(15),
child: Column(
mainAxisSize: MainAxisSize.min,
crossAxisAlignment: CrossAxisAlignment.start,
children: [
TextField(
keyboardType: TextInputType.name,
decoration: InputDecoration(labelText: 'Name'),
),
TextField(
keyboardType: TextInputType.number,
decoration: InputDecoration(labelText: 'Age'),
),
SizedBox(
height: 15,
),
ElevatedButton(onPressed: () {}, child: Text('Submit'))
],
),
));
}
@override
Widget build(BuildContext context) {
return Scaffold(
appBar: AppBar(
title: Text('Bottom Sheet'),
),
body: Container(),
floatingActionButton: FloatingActionButton(
child: Icon(Icons.add),
onPressed: () => _show(context),
),
);
}
}
Comments
Post a Comment