didChaneDependencies 不工作/颤振
didChaneDependencies not working / flutter
这是我尝试使用 didChaneDependencies 的屏幕之一的代码:
import 'package:flutter/material.dart';
import 'package:provider/provider.dart';
import 'package:shop/screens/cart_screen.dart';
import '../widgets/products_grid.dart';
import '../widgets/badge.dart';
import '../widgets/app_drawer.dart';
import '../providers/products.dart';
import '../providers/cart.dart';
enum FilterOptions {
Favorites,
All,
}
class ProductsOverviewScreen extends StatefulWidget {
@override
_ProductsOverviewScreenState createState() => _ProductsOverviewScreenState();
}
class _ProductsOverviewScreenState extends State<ProductsOverviewScreen> {
var _showOnlyFavorite = false;
var _isInit = true;
@override
void initState() {
print('initState');
super.initState();
}
@override
void didChaneDependencies() {
print('didChaneDependencies');
super.didChangeDependencies();
}
问题是它没有启动。
编译器使用以下消息突出显示它:
The method doesn't override an inherited method. Try updating this
class to match the superclass, or removing the override annotation.
我确实尝试删除 @override ,但这并没有解决问题,我看不到
print('didChaneDependencies');
在调试器中。
修复函数名称的拼写问题,您在 didChangeDependencies
函数名称
中缺少一个 G
@override
void didChangeDependencies() {
....
这是我尝试使用 didChaneDependencies 的屏幕之一的代码:
import 'package:flutter/material.dart';
import 'package:provider/provider.dart';
import 'package:shop/screens/cart_screen.dart';
import '../widgets/products_grid.dart';
import '../widgets/badge.dart';
import '../widgets/app_drawer.dart';
import '../providers/products.dart';
import '../providers/cart.dart';
enum FilterOptions {
Favorites,
All,
}
class ProductsOverviewScreen extends StatefulWidget {
@override
_ProductsOverviewScreenState createState() => _ProductsOverviewScreenState();
}
class _ProductsOverviewScreenState extends State<ProductsOverviewScreen> {
var _showOnlyFavorite = false;
var _isInit = true;
@override
void initState() {
print('initState');
super.initState();
}
@override
void didChaneDependencies() {
print('didChaneDependencies');
super.didChangeDependencies();
}
问题是它没有启动。 编译器使用以下消息突出显示它:
The method doesn't override an inherited method. Try updating this class to match the superclass, or removing the override annotation.
我确实尝试删除 @override ,但这并没有解决问题,我看不到
print('didChaneDependencies');
在调试器中。
修复函数名称的拼写问题,您在 didChangeDependencies
函数名称
@override
void didChangeDependencies() {
....