I want to make a floating widget but not floating all the time, when the widget is pulled up from the floating navigation bar it will appear like the picture in the middle
Asked
Active
Viewed 577 times
2
-
use showBottomSheet : https://api.flutter.dev/flutter/material/ScaffoldState/showBottomSheet.html – Saeed Ghasemi Nov 15 '22 at 11:10
-
thanks but how to open by pulling from the bottom up?, I tried to build the container myself and then added a gesture detector after being tapped to the top it didn't work, Is it mandatory to use a stack? – anyusernewbie Nov 15 '22 at 11:20
-
1it worked i used GestureDetector to zoom the widget – anyusernewbie Nov 15 '22 at 11:30
2 Answers
0
this sample code of flutter for using showBottomSheet:
import 'package:flutter/material.dart';
void main() => runApp(const MyApp());
class MyApp extends StatelessWidget {
const MyApp({super.key});
static const String _title = 'Flutter Code Sample';
@override
Widget build(BuildContext context) {
return MaterialApp(
title: _title,
home: Scaffold(
appBar: AppBar(title: const Text(_title)),
body: const MyStatelessWidget(),
),
);
}
}
class MyStatelessWidget extends StatelessWidget {
const MyStatelessWidget({super.key});
@override
Widget build(BuildContext context) {
return Center(
child: ElevatedButton(
child: const Text('showBottomSheet'),
onPressed: () {
Scaffold.of(context).showBottomSheet<void>(
(BuildContext context) {
return Container(
height: 200,
color: Colors.amber,
child: Center(
child: Column(
mainAxisAlignment: MainAxisAlignment.center,
mainAxisSize: MainAxisSize.min,
children: <Widget>[
const Text('BottomSheet'),
ElevatedButton(
child: const Text('Close BottomSheet'),
onPressed: () {
Navigator.pop(context);
},
),
],
),
),
);
},
);
},
),
);
}
}

Saeed Ghasemi
- 141
- 1
- 10
0
You can also try using sliding_up_panel to get the same functionality. It is pretty straight forward to implement and offers plenty customization features as well:
@override
Widget build(BuildContext context) {
return Scaffold(
appBar: AppBar(
title: Text("SlidingUpPanelExample"),
),
body: Stack(
children: <Widget>[
Center(child: Text("This is the Widget behind the sliding panel"),),
SlidingUpPanel(
panel: Center(child: Text("This is the sliding Widget"),),
)
],
)
);
}
Try the Stack variant so that it doesn't hinder too much with your current code.

Risheek Mittal
- 1,077
- 2
- 18