Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Made the cancellation widget's area next to the search bar more dynamic. #6

Open
wants to merge 1 commit into
base: master
Choose a base branch
from

Conversation

urwrstkn8mare
Copy link

Basically I used an Icon widget instead of a text widget and found that there was way too much space on either side of the widget. The change I made gets the width of the cancellation widget, adds a little bit of padding to the left and right, and then makes the total width plus padding the space taken away from the search bar for the cancellation widget.

NOTE: The image below is using my updated code but I just adjusted the padding to illustrate close to what it looked like before.
image
As you can see in the image above there was too much space on either side. The changes I've made just makes it a little better:
image

Copy link
Contributor

@ThomasEcalle ThomasEcalle left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hi !

Thank you a lot for your help for this package :)
I really like your idea to make the size of the cancellation widget more reasonable.
I perfectly understand that MediaQuery.of(context).size.width * .2 is quite a random size !

I like the way you thought about it but I am not sure it would work.
Indeed, the cancellationWidget is not fully rendered until the animation end.
That leads to _cancellationWidgetKey.currentContext being null at first call and a weird wrap of the text when growing.

So I am not sure about the implementation, although I really like and understand the idea.
What do you think of letting the user give the wanted size ?
Something like :

cancellationWidgetWidth : 200

This way, there is no calculation needed in the SearchBar's package and the User can put any size he wants.
By default, the package would keep the MediaQuery.of(context).size.width * .2

@@ -405,12 +406,45 @@ class _SearchBarState<T> extends State<SearchBar<T>>
duration: Duration(milliseconds: _animate ? 1000 : 0),
child: AnimatedContainer(
duration: Duration(milliseconds: 200),
width:
_animate ? MediaQuery.of(context).size.width * .2 : 0,
width: () {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

May we make a separated method with this logic ?
In order to not make the render method too long

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

oh yeah that is a good idea

// Get the width of the cancellation widget.
final RenderBox renderBox = _cancellationWidgetKey
.currentContext
.findRenderObject();
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

_cancellationWidgetKey.currentContext is null at first call and the app crash

double toBeReturned;

if (_animate) {
final fullWidth = MediaQuery.of(context).size.width;
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You have just forgotten the type : final double fullWidth

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

woops silly mistake

allows the width of the widget to be used.
*/
child: Container(
key: _cancellationWidgetKey,
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You can maybe use the Container above to put the key, not sure if this other one is really needed

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

oh yeah i guess i just didn't notice that. I didn't want to change much of the existing code incase i broke something.

@urwrstkn8mare
Copy link
Author

Thanks for the detailed feedback I really do appreciate it. As you can see I am very new to flutter. A lot of what you said made sense especially the line wrapping part as I noticed that in my testing but didn't know why. Also, most of my testing was with the icon widget for which it worked fine as far as I tested (which was honestly not much).

Anyway, I agree with you and think to allow the user to define the size would make more sense since there would be less logic to run to build the widget. As a bonus, if the user wants he/she can easily just make do that logic themselves with their own code.

That's just what I wanted to say but feel free to not accept the pull request and make your own better implementation or edit mine. Hopefully that made sense (I'm also new to contributing to stuff as well).

lib/flappy_search_bar.dart Outdated Show resolved Hide resolved
@ThomasEcalle
Copy link
Contributor

Hi @urwrstkn8mare !

First of all, I am sorry for the delay.
The situation in my company (in France) with the Covid-19 has forced us to put our open source projects on the side for a moment... But I am back ! :)

Thanks a lot for your work anyway !
I'll try to be more present on this package, despite the difficult context that had lead us to change a lot the way we work here :)

@urwrstkn8mare
Copy link
Author

No problem @ThomasEcalle. This is a weird time. For me, the schools have shut down which I thought meant more time until they gave me a bunch of work online so that's why I've been a little time-constrained.

Anyway, thanks for the help with this. I basically redid it with your requested changes which seemed very good to me. I'm a little time restrained right now as well so I haven't been able to test it at the moment. I will try to test it within a week and come back. But if you want to you can test it instead.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants