Comments (21)
Yeah Scaffold
expands its body, the biggest as possible.
Keyboard Avoider
it was an example on how you can change the position when the keyboard appears. It is not a solution, but a guidance on how you could solve it by building something custom for this case
And it is weird that view insets doesn't work
Check the code for the widget I add inside the modal
import 'package:flutter/cupertino.dart';
import 'package:flutter/material.dart';
import 'dart:math';
import 'dart:collection';
import 'package:flutter/widgets.dart';
import 'package:flutter/rendering.dart';
class ModalFit extends StatelessWidget {
final ScrollController scrollController;
const ModalFit({Key key, this.scrollController}) : super(key: key);
@override
Widget build(BuildContext context) {
return AnimatedPadding(
duration: Duration(milliseconds: 250),
padding: EdgeInsets.only(
bottom: MediaQuery.of(context).viewInsets.bottom),
child: Material(child: SafeArea(
top: false,
child: Column(
mainAxisSize: MainAxisSize.min,
children: <Widget>[
TextField(),
ListTile(
title: Text('Edit'),
leading: Icon(Icons.edit),
onTap: () => Navigator.of(context).pop(),
),
ListTile(
title: Text('Copy'),
leading: Icon(Icons.content_copy),
onTap: () => Navigator.of(context).pop(),
),
ListTile(
title: Text('Cut'),
leading: Icon(Icons.content_cut),
onTap: () => Navigator.of(context).pop(),
),
ListTile(
title: Text('Move'),
leading: Icon(Icons.folder_open),
onTap: () => Navigator.of(context).pop(),
),
ListTile(
title: Text('Delete'),
leading: Icon(Icons.delete),
onTap: () => Navigator.of(context).pop(),
)
],
),
),));
}
}
from modal_bottom_sheet.
tested, that was it. Using the AnimatedPadding worked. thanks!
from modal_bottom_sheet.
Not wrapping showBarBottomSheet inside a StatelessWidget, all the content inside.
Something like the code below
class EditHomeMarquee extends StatelessWidget {
@override
Widget build(BuildContext context) {
return InkWell(
child: HomePageMarquee(
textColor: Theme.of(context).colorScheme.onPrimary,
),
onTap: () {
_editMarqueeSheet(context, 'Cambio de Marquee');
},
);
}
_editMarqueeSheet(BuildContext context, String title) async {
String _prevText =
await Provider.of<FirebaseDataProvider>(context, listen: false)
.getMarquee();
TextEditingController _marqueeController =
TextEditingController(text: _prevText);
return showBarModalBottomSheet(
context: context,
// expand: true,
builder: (BuildContext context, ScrollController scrollController) {
return Modal();
},
);
}
}
class Modal extends StatelessWidget {
@override
Widget build(BuildContext context) {
return AnimatedPadding(
padding: EdgeInsets.only(
bottom: MediaQuery.of(context).viewInsets.bottom,
),
duration: Duration(milliseconds: 250),
child: Material(
color: Theme.of(context).colorScheme.primary,
child: SafeArea(
top: false,
child: Padding(
padding: const EdgeInsets.all(12.0),
child: Column(
mainAxisSize: MainAxisSize.min,
children: <Widget>[
AutoSizeText(
title,
style: TextStyle(
color: Theme.of(context).colorScheme.onPrimary),
),
TextField(
decoration: InputDecoration(hintText: 'escribe aquí'),
controller: _marqueeController,
autofocus: true,
),
FlatButton(
color: Colors.green,
child: AutoSizeText(
'OK',
style: TextStyle(color: Colors.white),
),
onPressed: () {
Provider.of<FirebaseDataProvider>(context,
listen: false)
.setMarquee(_marqueeController.text);
Navigator.of(context).pop();
},
),
FlatButton(
color: Colors.red,
child: AutoSizeText(
'Cancelar',
style: TextStyle(color: Colors.white),
),
onPressed: () {
Navigator.of(context).pop();
},
),
],
),
),
),
),
);
}
from modal_bottom_sheet.
Also you can wrap your modal with this.
Padding(
padding: EdgeInsets.only(bottom: MediaQuery.of(context).viewInsets.bottom),
child: ....
);
It jumps when the keyboard appears, if you want to animate it you can use AnimatedPadding for when the values changes.
from modal_bottom_sheet.
wow, so many solutions, I will test 1 by 1 and report what worked. thanks
from modal_bottom_sheet.
Resizing when keyboard is open is managed by the Scaffold widget. So try to wrap your modal sheet with a Scaffold. Often fixes such issues.
from modal_bottom_sheet.
As @bierbaumtim explains very well, in Flutter as far as I know the Scaffold is the only widget that resizes when the keyboard appears. So using a Scaffold widget inside the modal as parent could be a good solution.
Also you could implement your custom option, check this example.
With this I think it would be better to resize the content inside the modal rather than trying to resize all the modal as it would bring more complexity to this widget.
Let us know how it behaves with the Scaffold!!
from modal_bottom_sheet.
Ok so Scaffold was a better expand: true as this allowed the full modal to show but did not use the correct amount of padding but used the full amount.
With Scaffold no shrinkwrap
with or without kb same height, same with ViewInsets padding
Without Scafoold, using Keyboard Avoider with auto scroll no shrinkwrap
same as with Scaffold but more buggy
ViewInsets padding did not work as no change was seen. edit: same as with scaffold, it uses the full screen.
Unfortunately, there doesn't seem to be a fix to this :(
from modal_bottom_sheet.
class EditHomeMarquee extends StatelessWidget {
@override
Widget build(BuildContext context) {
return InkWell(
child: HomePageMarquee(
textColor: Theme.of(context).colorScheme.onPrimary,
),
onTap: () {
_editMarqueeSheet(context, 'Cambio de Marquee');
},
);
}
_editMarqueeSheet(BuildContext context, String title) async {
String _prevText =
await Provider.of<FirebaseDataProvider>(context, listen: false)
.getMarquee();
TextEditingController _marqueeController =
TextEditingController(text: _prevText);
return showBarModalBottomSheet(
context: context,
// expand: true,
builder: (BuildContext context, ScrollController scrollController) {
return AnimatedPadding(
padding: EdgeInsets.only(
bottom: MediaQuery.of(context).viewInsets.bottom,
),
duration: Duration(milliseconds: 250),
child: Material(
color: Theme.of(context).colorScheme.primary,
child: SafeArea(
top: false,
child: Padding(
padding: const EdgeInsets.all(12.0),
child: Column(
mainAxisSize: MainAxisSize.min,
children: <Widget>[
AutoSizeText(
title,
style: TextStyle(
color: Theme.of(context).colorScheme.onPrimary),
),
TextField(
decoration: InputDecoration(hintText: 'escribe aquí'),
controller: _marqueeController,
autofocus: true,
),
FlatButton(
color: Colors.green,
child: AutoSizeText(
'OK',
style: TextStyle(color: Colors.white),
),
onPressed: () {
Provider.of<FirebaseDataProvider>(context,
listen: false)
.setMarquee(_marqueeController.text);
Navigator.of(context).pop();
},
),
FlatButton(
color: Colors.red,
child: AutoSizeText(
'Cancelar',
style: TextStyle(color: Colors.white),
),
onPressed: () {
Navigator.of(context).pop();
},
),
],
),
),
),
),
);
},
);
}
}
This is what I got by copying your code and these are the results:
from modal_bottom_sheet.
Could you wrap it inside a StatelessWidget just to check it 😓
from modal_bottom_sheet.
Could you wrap it inside a StatelessWidget just to check it 😓
Sorry, I lack the knowledge of wrapping the showBarBottomSheet in a StatelessWidget.
how can I do it with my current example? 😅
I get A value of type 'Future can't be returned from method 'build' because it has a return type of 'Widget'.dart(return_of_invalid_type)
from modal_bottom_sheet.
class EditHomeMarquee extends StatelessWidget {
@override
Widget build(BuildContext context) {
return InkWell(
child: HomePageMarquee(
textColor: Theme.of(context).colorScheme.onPrimary,
),
onTap: () {
_editMarqueeSheet(context, 'Cambio de Marquee');
},
);
}
_editMarqueeSheet(BuildContext context, String title) async {
String _prevText =
await Provider.of<FirebaseDataProvider>(context, listen: false)
.getMarquee();
return showBarModalBottomSheet(
context: context,
// expand: true,
builder: (BuildContext context, ScrollController scrollController) {
return EditMarqueeSheet(
title: title,
prevText: _prevText,
);
},
);
}
}
class EditMarqueeSheet extends StatelessWidget {
final String title;
final String prevText;
const EditMarqueeSheet({Key key, this.title, this.prevText})
: super(key: key);
@override
Widget build(BuildContext context) {
TextEditingController _marqueeController =
TextEditingController(text: prevText);
return AnimatedPadding(
padding: EdgeInsets.only(
bottom: MediaQuery.of(context).viewInsets.bottom,
),
duration: Duration(milliseconds: 250),
child: Material(
color: Theme.of(context).colorScheme.primary,
child: SafeArea(
top: false,
child: Padding(
padding: const EdgeInsets.all(12.0),
child: Column(
mainAxisSize: MainAxisSize.min,
children: <Widget>[
AutoSizeText(
title,
style:
TextStyle(color: Theme.of(context).colorScheme.onPrimary),
),
TextField(
decoration: InputDecoration(hintText: 'escribe aquí'),
controller: _marqueeController,
autofocus: true,
),
FlatButton(
color: Colors.green,
child: AutoSizeText(
'OK',
style: TextStyle(color: Colors.white),
),
onPressed: () {
Provider.of<FirebaseDataProvider>(context, listen: false)
.setMarquee(_marqueeController.text);
Navigator.of(context).pop();
},
),
FlatButton(
color: Colors.red,
child: AutoSizeText(
'Cancelar',
style: TextStyle(color: Colors.white),
),
onPressed: () {
Navigator.of(context).pop();
},
),
],
),
),
),
),
);
}
}
Ok I did it, in terms of performance does it make any difference?
the results were the same with this code btw. weird...
from modal_bottom_sheet.
In this case more than performance would be readability. But it is a good behavior to create StatelessWidgets when you have large widgets and more when you use functions as showBarModalBottomSheet
, showDialog
that push a new route and the context would be different. This will help to make less errors.
I will keep looking to check why is not working in your case. I will try also on Android as I have only tried on iOS.
As recommendation for future comments you do on github is really useful to use code highlighting. (without the end dot)
final example = false;
```dart
final example = false;
```.
from modal_bottom_sheet.
I see thank you for your tips, I am running my app on Android device but the entire theme has been set to iOS but I am still using Material mmm maybe I should not use Material if that makes a difference.
Thank you for your time
from modal_bottom_sheet.
Mmm apparently on my Android simulator works fine, could you let me know which version of fltuter are you using currently?
(You can see if you run the command flutter doctor
)
from modal_bottom_sheet.
Here it is:
[√] Flutter (Channel stable, v1.12.13+hotfix.9, on Microsoft Windows [Version 10.0.18362.778], locale en-US)
[√] Android toolchain - develop for Android devices (Android SDK version 29.0.3)
[√] Android Studio (version 3.6)
[√] VS Code (version 1.44.2)
[√] Connected device (1 available)
from modal_bottom_sheet.
Mmm, could you try removing the device_preview package? Or at least the builder param in MaterialApp. This package creates a new MediaQuery and could be breaking this.
from modal_bottom_sheet.
mmm that could be it!
I will test tomorrow. btw does expand: true parameter mean to always use the full height?
from modal_bottom_sheet.
Yeah, exactly, it expands de modal to use all the screen. And it you set it to false it will fit to the size of its child
from modal_bottom_sheet.
It would be interesting to submit the issue in the package
from modal_bottom_sheet.
Yeah
Scaffold
expands its body, the biggest as possible.
Keyboard Avoider
it was an example on how you can change the position when the keyboard appears. It is not a solution, but a guidance on how you could solve it by building something custom for this caseAnd it is weird that view insets doesn't work
This works with keyboard open, but introduce a new problem:
that is PopupMenu
, because of padding, flutter think it visible for showing widget,
thus, PopupMenu
is covered up by keyboard.
from modal_bottom_sheet.
Related Issues (20)
- How to prevent dialog move up when keyboard show?
- Modal bottom sheet drag doesn't animate on some devices HOT 4
- [Sheet] Expands over screen size on keyboard open HOT 1
- showDragHandle and topRadius for showCupertinoModalBottomSheet HOT 1
- [Sheet] Triggering a re-build in child widget within the first 200ms or so seems to fully break the bottom sheet HOT 11
- Incompatible with the latest version of flutter/dart? HOT 11
- Is this project abandoned ? HOT 2
- The demo code version is not fit with README. HOT 3
- 3.0.0-pre version is not compatible with dart SDK 2.17 (flutter 3.0.1) HOT 2
- Error: The setter 'isMergedIntoParent' isn't defined for the class 'SemanticsNode' in flutter 3.19.0 HOT 3
- Not work anymore HOT 2
- Having problem implementing the modal_bottom_sheet library HOT 5
- [Sheet] Incorrect status bar behaviour
- 【Sheet】it always extended to full when child is a scroll view like listview or gridview? HOT 1
- keyboard appeared, push failed
- Unhandled Exception: 'package:flutter/src/widgets/scroll_controller.dart': Failed assertion: line 201 pos 12: '_positions.isNotEmpty': ScrollController not attached to any scroll views. HOT 1
- [Sheet] How can I avoid loosing the top rounded borders when the sheet is at maxExtent? HOT 1
- [Sheet] Can I close the sheet programmatically or tapping outside the sheet? HOT 3
- [Sheet] Go Router and CupertinoSheetPage with expanded: false
- ModalScrollController cannot be used to get scroll position (eg after adding a listener to it)
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from modal_bottom_sheet.