What is the exact position of the BackButton in an AppBar? Is kToolbarHeight 4px off? - flutter

Description
How do you position a custom back button on the exact location where the back button usually would be in an app bar?
Is kToolbarHeight 4px off?
Goal
I fade in the original app bar as the bottom sheet is pushed to the top.
Currently I'm using a Stack widget that positions the back button with kToolbarHeight from the top, but apparently that doesn't really match (It's rather kToolbarHeight - 4px).
I use a custom implementation of a back button, but this problem persists with the original backButton widget too.
Stack(
children: [
Map(...),
const Positioned(
top: kToolbarHeight,
left: 4.0,
child: CustomBackButton(),
),
],
);
Groundwork
I've looked it up in the dev tools and the original source code but couldn't find a reliable constant nor anything helpful.

Try like this:
Give your CustomBackButton() widget the dimensions of a square of kToolbarHeight side.
Inside your Stack, add a SafeArea child, into which you position the CustomBackButton() in the top left corner. That should place it in the right position.

Related

Flutter margin onFocus FocusNode

How do I set the margin from the edge when the focus hits a specific FocusNode?
As you can see from the video, there is an indentation on top of the buttons, but when you scroll the screen and return the focus to the button, it sticks to the top of the screen, it's understandable, the button is on the screen and in focus, but how to make a small offset from the top?
Try something like this:
Container(
margin: EdgeInsets.only(top: (focusnode.hasFocus) ? 10 : 0),
child: Text((focusnode.hasFocus) ? 'In Focus' : 'No Focus');
);

How to make hero widget fly below other widget in route transition

How to make hero widget fly below appBar and bottomBar widgets in route transition.
I had tried to warp other widgets with hero also but no luck.
During a transition, Flutter places the Hero's in the order they are found in the widget (element) tree; last one on top. So you might be able to organise your screen in such a way that, the app bar and bottom bar heros are found later in the tree than the body containing other heros. For example with a Stack:
Stack(
children: [
Body(),
Positioned(
top: 0,
left: 0,
right: 0,
child: AppBar(),
),
Positioned(
bottom: 0,
left: 0,
right: 0,
child: BottomBar(),
),
],
)
This relies on the implementation details of Flutter's heros, so it is rather hacky.
Another approach would be to copy Flutter's HeroController, Hero and related code and modify it to order the Hero OverlayEntries by a new "z-index" property of the Hero widget.
The Heros "fly" in the Navigator's Overlay. So yet another approach could be to place your app bar and bottom bar on top of the Navigator (for example with a Stack like above).
None of these are great of course.

How to make that bottomSheet not to cover or I can get height of BottomSheet?

I want to use BottomSheet as Footer but BottomSheet hide other container from body?
I think about 2 ways.
First way, Getting height of the BottomSheet and calculate
...
return Container(
height: MediaQuery.of(context).size.height - bottomSheetSize
children: [
Expanded(
child: Container(
color: Colors.white,
child: listView,
)
),
...
or second way, the BottomSheet doesn't cover a body
I don't know how to get size of the BottomSheet or not to cover body.
Can you help me with one of option?
You cannot do anything in the current screen if you open bottom sheets. If you are making a footer type of thing, use another container at the bottom of the first container wrapped in a column or use Stack and stack the footer on top of the first container.

Fade in/out FloatingActionButton?

Is there any way to slowly fade-in and out a floating action button? I have in my list a FAB to offer the user a way to quickly scroll to the top of the list.
So far I've found in various posts how to detect when the list is scrolled to the top or away from the top (https://medium.com/#diegoveloper/flutter-lets-know-the-scrollcontroller-and-scrollnotification-652b2685a4ac), but I fail to find how I can change the alpha value of a widget. Any idea how to solve this?
Thanks
Martin
This example is from flutter dev page:
With a AnimatedOpacity you can fade any widget.
Just put you floating action button as child of AnimatedOpacity.
Here is some example:
AnimatedOpacity(
// If the widget is visible, animate to 0.0 (invisible).
// If the widget is hidden, animate to 1.0 (fully visible).
opacity: _visible ? 1.0 : 0.0,
duration: Duration(milliseconds: 500),
// The green box must be a child of the AnimatedOpacity widget.
child: Container(
width: 200.0,
height: 200.0,
color: Colors.green,
),
);
You can find more info and full code here: https://flutter.dev/docs/cookbook/animation/opacity-animation

SlideTransition in flutter takes space before it slides in

I implemented SlideTransition for a widget in flutter, and it slides in as expected. The issue is that before the animation is called, the space where the slider is going to be displayed later is empty.
How can I make the parent to give this space to other widgets in the layout until the moment that a slider comes into view?
I was thinking about giving a slider the initial height of zero, but then the widgets inside the slider would act funny as the height changes in sync with sliding. I wonder if there is a simpler way.
The parent is:
new Scaffold(
appBar: _appBar,
body: new Column(
children: <Widget>[
new Expanded(
child: _body;
}),
),
new SlideTransition(
position: _sliderPosition, //
child: _slider,
),
],
);
And the position is defined as:
_sliderPosition = new MaterialPointArcTween(
begin: const Offset(0.0, 1.0),
end: Offset.zero,
).animate(_animationController);
I solved this issue by replacing _slider with _buildSlider() which returns null until a slider is needed.
This is also better for performance as there is no need to render a slider if it's hidden.
Bumped into the same issue with a SlideTransition taking the full height during a vertical slide. In the end I achieved the slide effect by using a SizeTransition instead, and setting its axisAlignment property accordingly (-1, 0, 1 for top/center/bottom in my case).