Questions tagged [flutter-hooks]
81 questions
0
votes
1 answer
Flutter Hook useState not working with dropdown
After choosing a value from dropdown, the value in useState does not update.
This is my model class
class Data {
final int id;
final String name;
final String someOtherData;
Data({
required this.id,
required this.name,
required…

ramen87x
- 160
- 3
- 18
0
votes
1 answer
Why is the order of flutter_hooks cleanup different than React hooks cleanup?
I'm studying Flutter hooks. I have written a program that is supposed to exhibit the same behavior as Flutter and React hooks. However, I have noticed that the timing of cleanup execution in useEffect differs from React. I have read the official…

mmm
- 3
- 2
0
votes
0 answers
Is using a simple ChangeNotifier the proper way to trigger rebuild in a HookWidget without maintaining a state?
I am implementing setting switch where the value is directly loaded from the shared preference, and when it is changed the value is written into it, and trigger a rebuild to load it again. The setting switch is a HookWidget as follow:
import…

Michael Tsang
- 678
- 5
- 16
0
votes
0 answers
useMemoized() in flutter hooks
Is it recommended to use useMemoized() in Flutter hooks for images and/or media query size when using animations in the widget?
final shortSide = useMemoized(() => MediaQuery.of(context).size.shortestSide);
Image image = useMemoized(() =>…
0
votes
1 answer
Flutter useEffect not updating new values retrieved from LayoutBuilder
I have a function to set the values to the state.
void Function() setSize({double? min, double? max}) {
final currentState = controller?._controllerState;
final newState = currentState?.copyWith(
min: min ?? minSize,
max: max ??…

hrtlkr29
- 383
- 1
- 7
- 21
0
votes
1 answer
How to use Flutter State Restoration with HookWidget
I want to use Flutter State Restoration in my Flutter app. I want to save/restore some data and on internet all articles suggest to use RestorationMixin for this. How can I use RestorationMixin with HookWidget ?

Shahbaz Hashmi
- 2,631
- 2
- 26
- 49
0
votes
0 answers
useEffect of flutter is not using current state from state Notifier of Riverpod
class ListWidget extends HookConsumerWidget {
const ListWidget({Key? key}) : super(key: key);
@override
Widget build(BuildContext context, ref) {
final stateT = ref.watch(listProvider);
final ctrl = ref.read(listProvider.notifier);
…

xahid_rocks
- 632
- 8
- 24
0
votes
0 answers
How to create a custom hook to handle geolocation data using existing flutter hooks?
I'm new to Flutter and now I'm trying to create a custom hook function that stores some information from the geolocation service. I'd like to implement it using the existing hooks from flutter_hooks library, without creating a class.
The main idea…

Sandro Simas
- 1,268
- 3
- 21
- 35
0
votes
2 answers
Text widget shows text with strange styles (Flutter)
I'm using Provider in Flutter for state management. And I want to display some text in my widget using this Provider. The test is shown but is looks very strange height or padding I don't know. So here is a code.
class JobDetailsScreen extends…

Dantes1993
- 3
- 2
0
votes
1 answer
my flutter screen keeps going back to my previous screen on hot reload
I have a welcome page where i can click a button and go to my login screen and i use Get.toNamed to navigate my screens
//Click button on welcome.dart
InkWell(
onTap: () => goto("login"),
child: ....,
)
//goto function for…

Brightcode
- 660
- 9
- 27
0
votes
2 answers
How to manage multiple ScrollView widgets using one useScrollController() hook?
Flutter documentation for ScrollController has this paragraph:
Scroll controllers are typically stored as member variables in State objects and are reused in each State.build. A single scroll controller can be used to control multiple scrollable…

Ruble
- 2,589
- 3
- 6
- 29
0
votes
1 answer
Invalid constant value with useState in HookWidget
Use https://pub.dev/packages/flutter_hooks
There is a simple sample code that changes the letter from "B" to "A" when you tap Text as shown below. (This works fine)
import 'package:flutter/material.dart';
import…

shingo.nakanishi
- 2,045
- 2
- 21
- 55
0
votes
1 answer
Riverpod `StreamProvider` stream causes Flutter `TextFormField` to loose cursor entirely on 1st character input despite no stream events emitted
Overview
The issue consists of the Flutter TextFormField loosing its cursor entirely upon the first character being inputted via a keyboard - see full replication steps below.
Note the TextFormField is watching a stream, which should not (& does…

20937u47897
- 11
- 2
0
votes
1 answer
How to useState of List in Flutter hooks?
I have very simple case of using flutter hooks:
class PositionedTiles extends HookWidget {
@override
Widget build(BuildContext context) {
final counterList = useState
- >([1,2,3,4,5]);
return Scaffold(
body: Text("Counter:…

wapn
- 359
- 1
- 7
- 19
0
votes
2 answers
LateInitializationError: Local 'prefs' has not been initialized
I am working with riverpod and flutter_hooks
I am trying to get implement shared_prefrences using this 2 approaches and this is what I get to so far :
pref_changenotifier.dart
import 'package:flutter/foundation.dart';
import…

Fahmi Sawalha
- 682
- 6
- 19