Swipe up and down to overlay two widget in Flutter - flutter

I'm using flutter
I'm having 2 widget A and B with position like photo above.
How can I move widget B overlay widget A when touch or swipe-up from widget B and back when swipe-down?

Make a GestureDetector and give it a stack as a child. Create a variable in your class thats called y or whatever name you want.
In your stack make 2 positioned widgets.
positioned(
top: 0
left: 0
),
positioned(
top: y
left: 0
)
make your two Widgets A and B childs of the positioned. Widget B has to be in the second positioned for it to overlay the first.
Make an AnimationController in your class and set its start value to 0 and its end value to the y. Use the onVerticalDragDownmethod of the GestureDetector to detect vertical swipes and check if it was from top to bottom or from bottom to top. If it was from bottom to top call animationController.reverse();, if it was from top to bottom call animationController.forward();. In the animationController Listener call setState((){y = animationController.value}). If you dont want it to be animated just set y to the values that you need.

Stack Learn about => https://api.flutter.dev/flutter/widgets/Stack-class.html
A widget that positions its children relative to the edges of its box.
This class is useful if you want to overlap several children in a
simple way, for example having some text and an image, overlaid with a
gradient and a button attached to the bottom.

Related

Flutter - CustomScrollView how to listen sliver's positon

This is my page structure:
CustomScrollView(
SliverToBoxAdapter(),
SliverPersistentHeader(pinned:true, Row(children:[tab_A, tab_B ,tab_C])),
SliverToBoxAdapter(A), // A SliverToBoxAdapter
SliverToBoxAdapter(B), // B SliverToBoxAdapter
SliverToBoxAdapter(C), // C SliverToBoxAdapter
)
My requirement is :
I scroll CustomScrollView. When A SliverToBoxAdapter is visible, tab_A is highlighted, When B SliverToBoxAdapter is visible and A SliverToBoxAdapter is invisible, tab_B is highlighted and so on...
I know scrollController can listen scroll position. But A, B, C SliverToBoxAdapter’s height are uncertain.Calculations are a bit complicated. Any other approaches?

How to use BarChartRodData of fl_chart

I want to make an app and I need to use fl_chart.
The question is: What do I do to make a space for each element evenly.
How can I do it like this screenshot?
Remove the property alignment from the BarChartData (Most probably it's set to center). It's going to use the spaceBetween instead as default.
It's going to be like the following:
BarChart(
BarChartData(
// Remove the `alignment` or change it to `spaceBetween`
alignment: BarChartAlignment.spaceBetween,
...
),
...
),
Also, if not already wrap BarChart with a Expanded widget.
Actually, you could set up "barsSpace" in the parameter of "BarChartGroupData".
Example from fl_chart
BarChartGroupData
PropName
Description
default value
x
x position of the group on horizontal axis
null
barRods
list of BarChartRodData that are a bar line
[]
barsSpace
the space between barRods of the group
2
showingTooltipIndicators
indexes of barRods to show the tooltip on top of them
[]

How to handle Column overflow in Flutter

I created a simple web app with Flutter.
The app layout is divided in two vertically zones: on the left there is a small top-bottom menu, on the right there is the main content inside a DataTable.
I wrapped the DataTable inside a SingleChildScrollView and everything worked fine.
The left side, on the other hand, keeps giving me a vertical overflow.
The tree on the left side is as follows:
Row(
children: [
//Left side menu
Flexible(
Container(
Column()
), //Container
), //Flexible
//Right side
Flexible(...),
],
), //Row
Obviously it is a very simplified version.
I've tried to insert a SingleChildScrollView in almost all places (Column, Container, Flexible), but it doesn't work and it always returns the error.
A RenderFlex overflowed by 174 pixels on the bottom.
Any solutions?
Thank you!
My approach would be to use MediaQuery to get current height and width of the web window. Then spilt the available width in the ratio of 2:7 maybe? You can play around with the ratio.
Now, lets keep the body of Scaffold to be Container with width as MediaQuery.of(context).size.width and height as ... .height. Now Row with childrens be 2 Expanded widgets with flex 2 and flex 7 respectively. Now we have to portion in the screen in the ratio 2:7.
On the left side, as you said, you need a menu, let it be
Expanded(
flex:2,
child: Column())
And on the other side be-
Expanded(
flex:7,
child: Container(
child: SingleChildScrollView() ///then add your stuff for scrolling purposes.
)
)
learn more about MediaQuery here
learn more about Expanded here

Wrap content width of button instead of fixed width

I have a RaisedButton which has a child Text and some Padding inside.
When I press the button, I'm using an AnimatedBuilder and Container to resize the width of the container to show a loading indicator.
return Container(
height: widget.height,
width: lerpWidth(widget.width, minWidth, _animation.value),
)
Now the problem is that I don't want to use a fixed width for my container since the text can be variable from length (translations, showing numbers, ..). If my passed-in string length would be bigger then the Container would not scale with it. I also don't want my button to expand the whole width of the screen.
So basically I want to expand my button to the minimum width of the child (including padding) and use that width to animate the container to show a CircularProgressIndicator

How to determine if one offset contained with another offset area?

I would like to determine if a widget is touching another widget, so far I have the following offset - Positions of widgets. However, this is a single point rather the a contained area.
Offset(48.8, 425.6) <- Box 1
Offset(70.0, 456.0) <-- Box 2
What is the best way to determine if Box 1 is near box 2 ( Box 2 would be scaled out by xx number to improve the matching )
I am using GlobalKeys to determine position like below
RenderBox box1 = box1Key.currentContext.findRenderObject();
Offset box1Pos = box1.localToGlobal(Offset.zero);
RenderBox box2 = box2Key.currentContext.findRenderObject();
Offset box2Pos = box2.localToGlobal(Offset.zero);
You could use the class Rect to define the boundings of one of your widgets and then use the method contains
https://api.flutter.dev/flutter/dart-ui/Rect/contains.html
The Rect class also has the method intersect which can be better suited for your question.
https://api.flutter.dev/flutter/dart-ui/Rect/intersect.html