Flutter bottom sheet invisible because of bottom navigation bar - flutter

I'm trying to show bottom sheet and let user pick choice. I did like so
showModalBottomSheet(
context: context,
builder: (builder) {
return Column(
mainAxisSize: MainAxisSize.min,
children: <Widget>[
new ListTile(
leading: new Icon(Icons.image),
title: new Text('From gallary'),
),
new ListTile(
leading: new Icon(Icons.camera_alt),
title: new Text('Take video'),
),
],
);
});
However it barely visible because of bottom navigation bar.
It looks like this.
I want to implement minimum height bottom sheet coming up from top edge of the bottom navigation bar. How can I achieve this?

The showModalBottomSheet has useRootNavigator which is by default false. The documentation says:
The useRootNavigator parameter ensures that the root navigator is used to
display the [BottomSheet] when set to true. This is useful in the case
that a modal [BottomSheet] needs to be displayed above all other content
but the caller is inside another [Navigator].
I think that is solution to your problem.

This could be a solution. Ensure that your main UI is a Stack.
Widget _buildOffstageMenu() => AnimatedPositioned(
duration: Duration(milliseconds: _showUpOffstageMenuDuration),
width: MediaQuery.of(context).size.width,
height: _offstageMenuHeight,
bottom: !_showMenu ? _bottomMenuOffset : 0.0,
curve: Curves.easeInOutExpo,
child: InkWell(
child: Container(
height: _offstageMenuHeight,
color: Colors.white,
child: Column(
children: [
/// your options
],
),
),
onTap: () {
setState(() {
_showMenu = !_showMenu;
});
},
),
);
So in the end you will have something like this
Stack(
children: [
/// your widgets
_buildOffstageMenu(),
],
)

Instead of Column try wrapping children with ListView and make sure shrinkWrap: true,
showModalBottomSheet(
context: context,
builder: (builder) {
return ListView(
shrinkWrap: true,
children: <Widget>[
new ListTile(
leading: new Icon(Icons.image),
title: new Text('From gallary'),
),
new ListTile(
leading: new Icon(Icons.camera_alt),
title: new Text('Take video'),
),
],
);
});

Related

ListView flutter, how to keep at full height always

Im trying to remove the scrolling of my ListView widget. Currently, the user only has a small window of tiles to scroll through. The listview data is paged so only shows 20 items at once- i want to show all 20 items and the whole page to scroll, rather than the user scroll through the list view a few at a time. How can i achieve this?
return Column(
children: [
Expanded(
child: ListView.separated(
separatorBuilder: (context, index) => Container(
height: 1,
color: Constants.listSeparatorGrey,
),
itemCount: pageState.data?.data?.length ?? 0,
itemBuilder: (context, idx) =>
itemBuilder(pageState.data?.data?[idx]),
),
),
Text('${pageState.data?.total ?? 0} results',
style: TextStyles.rowHeader(context)),
Text(
'Page ${pageState.data?.currentPage()} of ${pageState.data?.pageNum()}',
style: TextStyles.rowHeader(context),
),
Row(
mainAxisAlignment: MainAxisAlignment.center,
children: [
Container(width: 20),
if (pageState.data?.hasPrev ?? false)
MyButton(
// isLoading: pageState is Loading,
type: ButtonType.secondary,
label: "Previous",
onPressed: pageApi.prev,
)
else
Container(width: 8),
const SizedBox(
width: 8,
),
(pageState.data?.hasNext ?? false)
? MyButton(
// isLoading: pageState is Loading,
type: ButtonType.secondary,
label: "Next",
onPressed: pageApi.next,
)
: const SizedBox(width: 8)
],
),
],
);
If I correctly understand you. Just move all your content to ListView. So all your page starts scrolling with content.
Widget header = Container(color: Colors.green, height: 100);
List<Widget> content = const [Text("firstCell"), Text("secondCell")];
Widget button =
const TextButton(onPressed: null, child: Text("Next page"));
List<Widget> widgets = [header] + content + [button];
return Scaffold(
appBar: AppBar(
title: const Text('All content in list'),
),
body: ListView(children: widgets),
);
Here result:
All content in ListView
I solved my problem.
I just put the root column in a SingleChildScrollView()
very simple in the end

how can I extend a progress bar in a AlertDialog(fluent UI)?

I would like to implement an AlertDialog using Flutter and fluent_ui for Windows. This is a progressive progress bar, so the percentage will change when some of my other code executes. My problem is that the Progress Bar does not extend until the end of the AlertDialog. Currently, the progress bar looks like below, set at progress of 50.
Edit: Below is the code I have tried
showDialog(
context: context,
builder: (context) {
return ContentDialog(
title: Text(title),
content: const Expanded(
child: ProgressBar(value: 50, strokeWidth: 10),
),
actions: [
const SizedBox(),
Button(
style: MyButtonStyles.dialogYes(),
child: const Text('OK', style: TextStyle(fontSize: 16.0)),
onPressed: () {
Navigator.pop(context);
}),
],
);
},
);
You can replace Expanded with SizedBox by providing infinity/ specific width.
Also, can be use SizedBox.fromSize.
ContentDialog(
title: Text("title"),
content: SizedBox(
width: double.infinity,
child: ProgressBar(value: 50, strokeWidth: 10),
),

What is this overlapped widget name?

what is this overlap widget ? or is this some kind of effect ? please
Use this function on button click:
void _settingModalBottomSheet(BuildContext context){
showModalBottomSheet(
context: context,
builder: (BuildContext bc){
return Container(
child: new Wrap(
children: <Widget>[
new ListTile(
leading: new Icon(Icons.music_note),
title: new Text('Music'),
onTap: () => {}
),
new ListTile(
leading: new Icon(Icons.videocam),
title: new Text('Video'),
onTap: () => {},
),
],
),
);
});
}
It's called ModalBottomSheet, You can use this package to create powerful modal bottom sheets.

Flutter bottomSheet with input in a column and an attachment icon on the bottom, keyboard hides the icon when active

I am showing a bottom sheet with showModalBottomSheet like so:
showModalBottomSheet(
isScrollControlled: true,
context: context,
backgroundColor: Colors.transparent,
builder: (BuildContext context) {
return StatefulBuilder(
builder: (BuildContext context, StateSetter setState) {
return Container(
height: MediaQuery.of(context).size.height * .90,
width: double.infinity,
child: Column(
children: [
Expanded(
child: PostCreate(isImageType: isImageType)
),
Padding(
padding: const EdgeInsets.fromLTRB(20, 0, 0, 20),
child: Align(
alignment: Alignment.bottomLeft,
child: IconButton(
onPressed: () {
setState(() {
isImageType = true;
});
},
icon: Icon(Icons.attach_file_rounded),
)
),
)
],
),
);
}
);
}
);
The PostCreate widget contains a column with a * form (single input) and a section for adding the images. When the keyboard is not visible the attach_file_rounded Icon is where you would expect (bottom left), but when the input is focused and the keyboard is visible, the icon is hidden behind the keyboard. I'm not concerned about the code in PostCreate because if I change it to just a form/input in Expanded:
Expanded(
child: Form(
child: TextFormField(
autofocus: true,
)
)
)
I have the same exact problem. What's the way for me to align something on the bottom left of a bottom sheet that will dynamically sit above the keyboard when it is active? Another thing to note, is that I do want the PostCreate widget to expand, allowing room for certain things (like the attach_file icon) on the bottom of the sheet. That is all working as expected, I just need it to adjust with the keyboard.
I figured this out by adding padding: MediaQuery.of(context).viewInsets, to the Padding widget around the Align/IconButton widgets.
Padding(
padding: MediaQuery.of(context).viewInsets,
child: Align(
alignment: Alignment.bottomLeft,
child: IconButton(
onPressed: () {
setState(() {
isImageType = true;
});
},
icon: Icon(Icons.attach_file_rounded),
)
),
)

flutter: how to remove icon from expansion panel

in flutter expansion panel, there is a icon on it by default
i want to remove the icon from expansion panel
how i'm gonna do this?
here is my code
ExpansionPanelList(
expansionCallback: (int index, bool isExpanded) {},
children: [
ExpansionPanel(
headerBuilder: (BuildContext context, bool isExpanded) {
return Stack(children: [
ListTile(//and the rest of code...
the only way to do it is by editing the ExpansionPanel source code.
I added a new property called hasIcon and set it by default to true
(to make sure it will not break the code).
ExpansionPanel(
hasIcon: false, // <------
canTapOnHeader: true,
headerBuilder: (BuildContext context, bool isExpanded) {
return ListTile(
title: Text(
'Title',
),
);
},
body: Container(), // <------
isExpanded: false, // <------
),
and here is how you edit the source code:
Press CTRL + click on ExpansionPanel widget,
then search for
this.isExpanded = false,
and add below it
this.isExpanded = false,
this.hasIcon = true,
then search for
final bool isExpanded;
and add below it
final bool isExpanded;
final bool hasIcon;
finally, search for
Widget header = Row(
children: <Widget>[
Expanded(
child: AnimatedContainer(
duration: widget.animationDuration,
curve: Curves.fastOutSlowIn,
margin: _isChildExpanded(index) ? widget.expandedHeaderPadding : EdgeInsets.zero,
child: ConstrainedBox(
constraints: const BoxConstraints(minHeight: _kPanelHeaderCollapsedHeight),
child: headerWidget,
),
),
),
expandIconContainer,
],
);
and replace it
Widget header = Row(
children: <Widget>[
Expanded(
child: AnimatedContainer(
duration: widget.animationDuration,
curve: Curves.fastOutSlowIn,
margin: _isChildExpanded(index) ? widget.expandedHeaderPadding : EdgeInsets.zero,
child: ConstrainedBox(
constraints: const BoxConstraints(minHeight: _kPanelHeaderCollapsedHeight),
child: headerWidget,
),
),
),
Container(
child: child.hasIcon? expandIconContainer:null,
),
],
);
This works,
Just add SizedBox.shrink() to the trailing properties of ExpansionTile
ExpansionTile(
trailing: SizedBox.shrink(),
title: Text(
"Title",
style: TextStyle(
fontSize: 18.0,
fontWeight: FontWeight.bold
),
),
children: <Widget>[
ExpansionTile(
title: Text(
'Sub title',
),
children: <Widget>[
ListTile(
title: Text('data'),
)
],
),
ListTile(
title: Text(
'data'
),
)
],
),
You can add this file to your code and use it in place of ExpansionPanelList.
Or You could edit the source code of ExpansionPanelList directly on your version of flutter (not recommended)
If you are using ExpantionTile inside the panel, you can provide trailing widget to it which will replace the arrow.
There is an ongoing effort in adding this feature to ExpansionPanel, but that is moment, it is not supported.
You can extend this and customize or other libraries which provide this feature. (The one mentioned by #bensal)
I had a similar issue with ExpandablePanel, I created an ExpandableThemeData and set the hasIcon property to false.
var themeData = ExpandableThemeData(hasIcon: false);
ExpandablePanel(
theme: themeDate,
... rest of the code...
)