我正在尝试使用以下库:
Float and double datatypes in Java
称为animated_background
当我尝试运行代码时,发现以下错误:
Compiler message:
lib/helpers/fade_route.dart:12:18: Error: The getter 'isInitialRoute' isn't defined for the class 'RouteSettings'.
- 'RouteSettings' is from 'package:flutter/src/widgets/navigator.dart' ('/D:/programs/flutter/flutter/packages/flutter/lib/src/widgets/navigator.dart').
Try correcting the name to the name of an existing getter, or defining a getter or field named 'isInitialRoute'.
if (settings.isInitialRoute)
^^^^^^^^^^^^^^
因为这是包含错误的下图:
https://pub.dev/packages/animated_background
这是相关代码:
import 'package:flutter/material.dart';
class FadeRoute<T> extends MaterialPageRoute<T> {
FadeRoute({ WidgetBuilder builder, RouteSettings settings })
: super(builder: builder, settings: settings);
@override
Widget buildTransitions(BuildContext context,
Animation<double> animation,
Animation<double> secondaryAnimation,
Widget child) {
if (settings.isInitialRoute)
return child;
return new FadeTransition(opacity: animation, child: child);
}
}
class SimpleFadeRoute<T> extends FadeRoute<T> {
SimpleFadeRoute({ Widget child, RouteSettings settings })
: super(builder: (_) => child, settings: settings);
}
答案 0 :(得分:1)
该财产was removed from RouteSettings。另请参见以下link。
我们从RouteSetting中删除了isInitialRoute属性,作为其中的一部分 重构,并完整提供了onGenerateInitialRoutes API 控制初始路线的生成。
有多种方法可以迁移此更改。一种方法是设置 将初始路由名称更改为固定值并生成特定路由 (在上面的示例中为FakeSplashRoute)作为路由名称。
MaterialApp(
initialRouteName: ‘fakeSplash’,
onGenerateRoute: (RouteSetting setting) {
if (setting.name == ‘fakeSplash’)
return FakeSplashRoute();
else
return RealRoute(setting);
}
)
如果存在更复杂的用例,则可以使用新的API, 在MaterialApp或CupertinoApp中的onGenerateInitialRoutes。
MaterialApp(
onGenerateRoute: (RouteSetting setting) {
return RealRoute(setting);
},
onGenerateInitialRoutes: (String initialRouteName) {
return <Route>[FakeSplashRoute()];
}
)