ScopedQuery<Result> constructor
const
ScopedQuery<Result> (
- Result provider(
- QueryScopedValueRef<
Ref> ref
- QueryScopedValueRef<
- Object? name,
- bool autoDisposeWhenUnreferenced = false,
ScopedQuery makes it possible to define values globally and manage state individually and safely.
Specify in provider
a callback that returns the value you wish to manage.
Normally hashCode is used to manage state names, but if you want to specify a special name, specify name
.
If autoDisposeWhenUnreferenced
is set to true
, ScopedQuery will be automatically disposed of when it is no longer referenced by any widget.
ScopedQueryを利用してグローバルに値を定義して個別に安全に状態を管理することが可能になります。
provider
に管理したい値を返すコールバックを指定してください。
通常はhashCodeを用いて状態の名前を管理しますが、特別に名前を指定したい場合はname
を指定してください。
autoDisposeWhenUnreferenced
をtrue
にすると、ScopedQueryがどのウィジェットからも参照されなくなった時に自動的に破棄されます。
final stateQuery = ScopedQuery(
() => "state",
);
class TestPage extends PageScopedWidget {
@override
Widget build(BuildContext context, PageRef ref) {
final state = ref.page.query(stateQuery);
return Scaffold(
body: Center(child: Text("${state}")), // `state`
);
}
}
Implementation
const ScopedQuery(
super.provider, {
super.name,
super.autoDisposeWhenUnreferenced = false,
});