ChangeNotifier in Flutter notifies all listeners, even if the data hasn’t actually changed and UI is getting rebuild. This means every widget that calls Provider.of(context) or uses Consumer will rebuild when notifyListeners() is called, regardless of whether the value they depend on has changed. The situation is similar with BLoCBuilder or BLoCListener – when there…
TextEditingController State in Flutter
n Flutter, TextEditingController is typically used with StatefulWidget because it needs to persist its state across widget rebuilds and be disposed after it is not needed. Example The best practice for managing a TextEditingController is to use a StatefulWidget so that the controller is properly disposed of when no longer needed. import ‘package:flutter/material.dart’; class MyStatefulWidget…
Flutter PopScope Usage
PopScope in Flutter is a widget that allows you to control the behavior of the system back button (Android) or the back swipe gesture (iOS). It’s useful when you want to override or prevent navigation pops under certain conditions. Usages of PopScope Prevent Accidental Exits: Show a confirmation dialog before exiting an app. Example: Asking…
Flutter Dev Cheatsheet
Here’s a Flutter Dev Development CheatSheet to help you with key concepts, commands, and code snippets: 1. Flutter CLI Commands Create a new project: flutter create my_app Run the app: flutter run -d chrome Build the app: Android APK: flutter build apk | appbundle iOS: flutter build ios Check devices: flutter devices Clean the project:…
What are the options for Dependency Injection in Flutter
There are several options for Dependency Injection in Flutter and your choice depends on the pick of State Management Solution, likability to code generators, etc ioc_container The ioc_container package offers a lightweight and high-performance DI solution. It emphasizes flexibility and simplicity, allowing for easy replacement of services, lifecycle management, and lazy initialization. Its minimalistic design…
Wrap Everythyng in Flutter
You could Wrap Every element in Flutter so it could be replaced, parameterized, customized, made more testable and more. The aspects are: internationalization – you want to support your users locale, colors – you want to support light and dark theme, themes, icons – so they could switch between themes (and locales) packages – could…
Flutter Custom Header to every Request with the http package
Yes, you can add a Custom Header to every request with the http package in Flutter. Here’s an example of how you can achieve this: import ‘package:http/http.dart’ as http; class AuthHttpClient { final http.Client client; AuthHttpClient({ required this.client, }); //plain request path through. All details are in the hands of the user of this method…
How to Accomplish Speed of Application Development with Flutter
Flutter is a powerful and efficient framework to accomplish high Speed of Development of mobile web and desktop applications. Here are some tips to help you achieve speed in your Flutter application development: 0. Follow a guideline, single approach on doing things and enforce it endlessly When things are done in specific way in every…
In Flutter – insert code with mixin
In Flutter, you can insert various types of code in a mixin and add it with the with keyword. Here are some examples: Functions You can define functions in a mixin that can be used by classes that inherit from it. mixin MyMixin on Object { void myFunction() { print(‘Hello from mixin!’); } } class…
How to check every request in spring boot & if it is invalid – return 401
How to check for presence of specific header in every request with spring boot and if it is not – return 401? You can achieve this by implementing a custom HandlerInterceptor in Spring Boot. Here’s an example: import org.springframework.stereotype.Component; import org.springframework.web.servlet.HandlerInterceptor; import org.springframework.web.servlet.ModelAndView; import jakarta.servlet.http.HttpServletRequest; import jakarta.servlet.http.HttpServletResponse; //import javax.servlet.http.HttpServletRequest; //import javax.servlet.http.HttpServletResponse; import java.util.Arrays; @Component public…