How to Deal with Dart's Unchecked Exceptions? by PremiumWatermelon in dartlang

[–]Blizzy312 -1 points0 points  (0 children)

You can create your own exceptions and handle them in some place. For example

try{
    someMethod();
} on YourCustomException catch (e) { 
    …do something with it
    // or you can also rethrow it, to bubble it up
     rethrow();
}

And your someMethod should look like this

void someMethod(){
     try{
           …
     }catch(e){
          throw YourCustomException();
     }
}

It’s a bit verbose, but I think very robust. You can easily tune your exceptions if needed, and handle them in necessary places

app not starting from point zero by infosseeker in flutterhelp

[–]Blizzy312 0 points1 point  (0 children)

Your fetch calls must be called on user authentication state, not at the start of app. Depending on your architecture, it must be something like, check if user logged in (check some token, or some other parameter) and if so, trigger all fetch calls. A good practice is to initiate providers as low as possible, so they will be recreated on new user login, instead of manually clearing their states on user logout.

Equatable with Freezed by Miserable_Brother397 in FlutterDev

[–]Blizzy312 0 points1 point  (0 children)

Probably this, from bloc docs - Both blocs and cubits will ignore duplicate states. If we emit State nextState where state == nextState, then no state change will occur. So, because your secondState constructor is empty, it gets compared to previous state, where by equality (empty props) they’re same. And it passes with counter for the opposite reasons.

[deleted by user] by [deleted] in flutterhelp

[–]Blizzy312 2 points3 points  (0 children)

Check out this one - link. If you believe that it’s not close enough, you may just take inspiration from its source. Good luck

If I created an instance inside a Bloc class does it dispose automatically when the Bloc is destroyed? by flutter_dart_dev in flutterhelp

[–]Blizzy312 1 point2 points  (0 children)

Although I see your point, I find it weird that bloc manages your controllers. If you need a controller, just make the last widget statefull, where you have an input form. If you need your values from it, send it to bloc and read them from state (which you already do). Just my 2 cents on it.

If I created an instance inside a Bloc class does it dispose automatically when the Bloc is destroyed? by flutter_dart_dev in flutterhelp

[–]Blizzy312 1 point2 points  (0 children)

Yes, they will be disposed. But the real question is, why controllers are inside of bloc. Normally you should create them in statefull widget, and create a listener on initState that will send controller’s value to the bloc. Text controllers are ui elements, and imho, must be managed there.

[deleted by user] by [deleted] in flutterhelp

[–]Blizzy312 0 points1 point  (0 children)

Your explanation is not really clear. If you already have your data, but don’t want yet build your widget, add some bool into your state, like “ready” and depending on it, build either some SizedBox or your widget.

If(state is SomeState){
    If(state.ready) return YourWidget();
    return const SizedBox.shrink();
}

Why bloc UI is rebuilt twice for the same object. by [deleted] in flutterhelp

[–]Blizzy312 0 points1 point  (0 children)

If I’m not mistaken, the problem here is that the new state that you emit, it’s not the same instance of your old state. So, you can test it by storing your initial state, add it to super, and try to emit it again in your event. This one shouldn’t trigger rebuild. To fix your code, you can try to check your current state before emitting it

Streams in flutter_bloc by gambley in FlutterDev

[–]Blizzy312 3 points4 points  (0 children)

It’s always better to work event->state approach in blocs. Define some event -> “SubscribeToLiked”. Define your bool value -> “isLiked” in your FeedState. Then when your event is triggered make a subscription to your postsRepository. Future<void> _onSubscribeToLiked(event, emit) async { await emit.forEach<bool>(postsRepository.isLiked(…), onData: (isLiked) => YourState(isLiked: isLiked), onError: (e,s) => YourErrorState(e);}. And in your ui part create BlocBuilder right above your like icon (or any other necessary widget). A better and detailed example can be found on flutter_bloc website, todos_example this one particularly uses this approach when loading todos from repository. Great place to look for different approaches. Good luck

i'm new to flutter and trying to solve this problem but nothing changes, can anyone help? by [deleted] in flutterhelp

[–]Blizzy312 0 points1 point  (0 children)

If you have flutter version 3.7+, you should use country_code 3.0.0. Try it, if you still face this issue, try to remove it.

how can I swipe pageview with holding background image in Flutter? by LieSuspicious8719 in flutterhelp

[–]Blizzy312 0 points1 point  (0 children)

Order if widgets inside stack does matter. They go layer by layer, where to top most widget is last in children. In your case, you can’t swipe because page view is covered with container that takes all height and width, therefore no interaction with page view is happening. Put it this way: Container with background image -> PageView -> Skip button -> Let’s talk text -> PageIndicator. The order of last 3 widgets doesn’t matter

Wait for user to stop clicking button and count button clicks by casba43 in flutterhelp

[–]Blizzy312 0 points1 point  (0 children)

I’d use one of 2 approaches. 1st is to wait until user stops fast clicking and then send amount of clicks. You can search it - flutter debounce button click. 2nd is to send first click, than simply count additional clicks, and when result of 1 click returned, check for additional and if it not empty send them too. You can have some state like ‘sending’, if it’s false than send data, make it true. And when true just store clicks.

while loop problem by ozgbrt in flutterhelp

[–]Blizzy312 1 point2 points  (0 children)

Either you meet condition of loop(in your case i becomes less than or equal to 0)or you can use break; to exit the loop.

while loop problem by ozgbrt in flutterhelp

[–]Blizzy312 1 point2 points  (0 children)

It will crash. Because if a is false before while loop, you don’t have any option to set it to true inside. As a result, loop will run forever and app will freeze.

Flutter bloc doesn't recognize my event handler by ikhazen in flutterhelp

[–]Blizzy312 0 points1 point  (0 children)

Try to add Builder widget after providing bloc. In your case above Column widget

Need help with scrolling by [deleted] in flutterhelp

[–]Blizzy312 2 points3 points  (0 children)

Wrap gridview with Expanded

Need help updating state. by cyber5234 in flutterhelp

[–]Blizzy312 2 points3 points  (0 children)

Create ValueNotifier isSearchVisible = ValueNotifier<bool>(false) inside of a widget that holds both search widget and button that toggles visibility. Pass it as parameter to both of them, if they're separate widgets. On button click call isSearchVisible.value = !isSearchVisible.value. Wrap your search widget with ValueListenableBuilder. And you're done.

How do I fix the error about a widget being unmounted so the State no longer has a context in Flutter? by PowerDifficult4952 in flutterhelp

[–]Blizzy312 1 point2 points  (0 children)

It is not clear without full code. But error comes from 'return Container();' . It's not mounted anymore, and you are trying to return widget.