【发布时间】:2021-03-17 22:46:33
【问题描述】:
所以我想要一个提供者,其初始状态将是用户的位置,这就是我现在拥有的,对吗?
import 'package:flutter/foundation.dart';
import 'package:flutter_riverpod/all.dart';
import 'package:location/location.dart';
class MapApiState {
final LocationData userLocation;
MapApiState({@required this.userLocation});
}
class MapNotifier extends StateNotifier<MapApiState> {
static Location _location = Location();
MapNotifier() : super(null) {
_location.getLocation().then((initialState) =>
super.state = MapApiState(userLocation: initialState));
}
}
这是正确的方法吗?我现在如何为此声明全局提供程序变量? super(null) 让我担心。但我不能只放“super(_location.getLocation())”
另外,我应该如何实例化我的全局提供程序变量?
【问题讨论】:
标签: flutter dart flutter-provider riverpod