问题描述
我是状态管理人员的新手,提供程序包扑朔迷离。 有多少种不同的原因会导致产生此类异常,我该如何解决, 在 didChangeDependencies 中调用 getFollowing()方法时会生成此异常。
关注.dart
class Follows with ChangeNotifier{
List<Follow> _following =[];
String userid;
String token;
List<Follow> get followingUser{
return [..._following];
}
void updates(String token,String userid){
this.userid = userid;
this.token = token;
}
Future<void> getFollowing(String id) async {
final response = await http.get("${Domain.ADDRESS}/user/following/$id",headers: {"auth-token" : this.token});
final data =json.decode(response.body)["following"] as List;
List<Follow> followingData =[];
data.forEach((user){
followingData.add(Follow(
id: user["_id"],username: user["username"],fullname: user["fullname"],imageUrl: user["imageUrl"],followerCount : (user["followers"] as List).length
));
});
_following = [...followingData];
notifyListeners();
}
.........
}
Main.dart
return MultiProvider(
providers: [
ChangeNotifierProvider(
create: (ctx) => Auth(),),ChangeNotifierProxyProvider<Auth,Follows>(
create: (ctx)=>Follows(),update : (context,auth,previous) => Follows()..updates(auth.token,auth.userId)
),]
child : .......
);
FollowList.dart
class FollowList extends StatefulWidget {
static const followRoutes = "/follow-list";
final String id;
FollowList({this.id});
@override
_FollowListState createState() => _FollowListState();
}
class _FollowListState extends State<FollowList> {
bool isLoading = false;
@override
void didChangeDependencies() {
setState(() {
isLoading = true;
});
Provider.of<Follows>(context,listen: false).getFollowing(widget.id).then((_){
setState(() {
isLoading = false;
});
});
super.didChangeDependencies();
}
@override
Widget build(BuildContext context) {
List<Follow> following = Provider.of<Follows>(context,listen: false).followingUser;
return Scaffold(
appBar: AppBar(title: Text("following),body: isLoading ? Center(child: CircularProgressIndicator(strokeWidth: 1,))
: ListView.builder(
itemBuilder: (context,index) => UserCard(
id: following[index].id,fullname :following[index].fullname,username :following[index].username,followerCount : following[index].followerCount,imageUrl: following[index].imageUrl,followPressed: true,itemCount: following.length,);
}
}
请指定在何处调用dispose方法 未处理的异常:处置后使用了追随者。 E / flutter(8465):在Follows上调用dispose()后,将无法再使用它。
解决方法
暂无找到可以解决该程序问题的有效方法,小编努力寻找整理中!
如果你已经找到好的解决方法,欢迎将解决方案带上本链接一起发送给小编。
小编邮箱:dio#foxmail.com (将#修改为@)