Step 1:Add get package to pubspec.yaml file:
get:
Step 2: Import get package in main.dart file
import 'package:get/get.dart';
Step 3: code
import 'package:flutter/material.dart';
import 'package:get/get.dart';
void main() {
runApp(MyApp());
}
class MyApp extends StatelessWidget {
// This widget is the root of your application.
@override
Widget build(BuildContext context) {
return GetMaterialApp(
title: 'Bottomsheet',
theme: ThemeData(
primarySwatch: Colors.blue,
),
home: HomePage(),
debugShowCheckedModeBanner: false,
);
}
}
class HomePage extends StatelessWidget {
@override
Widget build(BuildContext context) {
return Scaffold(
appBar: AppBar(
title: Text('GeeksforGeeks Bottomsheet'),
backgroundColor: Colors.green[400],
),
body: Center(
child: Column(
mainAxisAlignment: MainAxisAlignment.center,
children: [
ElevatedButton(
child: Text('Show bottomsheet'),
onPressed: (){
},
),
],
),
),
);
}
}
Step 4: add bottomSheet
Get.bottomSheet(
Container(
height: 150,
color: Colors.greenAccent,
child:Column(
children: [
Text('Hii 1', textScaleFactor: 2),
Text('Hii 2', textScaleFactor: 2),
Text('Hii 3', textScaleFactor: 2),
Text('Hii 4', textScaleFactor: 2),
],
)
),
barrierColor: Colors.red[50],
isDismissible: false,
shape: RoundedRectangleBorder(
borderRadius: BorderRadius.circular(35),
side: BorderSide(
width: 5,
color: Colors.black
)
),
enableDrag: false,
);
Complete code
import 'package:flutter/material.dart';
import 'package:get/get.dart';
void main() {
runApp(MyApp());
}
class MyApp extends StatelessWidget {
// This widget is the root of your application.
@override
Widget build(BuildContext context) {
return GetMaterialApp(
title: 'Bottomsheet',
theme: ThemeData(
primarySwatch: Colors.blue,
),
home: HomePage(),
debugShowCheckedModeBanner: false,
);
}
}
class HomePage extends StatelessWidget {
@override
Widget build(BuildContext context) {
return Scaffold(
appBar: AppBar(
title: Text('GeeksforGeeks Bottomsheet'),
backgroundColor: Colors.green[400],
),
body: Center(
child: Column(
mainAxisAlignment: MainAxisAlignment.center,
children: [
ElevatedButton(
child: Text('Show bottomsheet'),
onPressed: (){
Get.bottomSheet(
Container(
height: 150,
color: Colors.greenAccent,
child:Column(
children: [
Text('Hii 1', textScaleFactor: 2),
Text('Hii 2', textScaleFactor: 2),
Text('Hii 3', textScaleFactor: 2),
Text('Hii 4', textScaleFactor: 2),
],
)
),
barrierColor: Colors.red[50],
isDismissible: false,
shape: RoundedRectangleBorder(
borderRadius: BorderRadius.circular(35),
side: BorderSide(
width: 5,
color: Colors.black
)
),
enableDrag: false,
);
},
),
],
),
),
);
}
}