从另一个页面启动幻灯片拼图项目时出错。
class PuzzlePage extends StatefulWidget {
final int rows, columns;
PuzzlePage({int columns = 3, int rows = 3})
: columns = columns ?? 3,
rows = rows ?? 3;
@override
_PuzzlePageState createState() => _PuzzlePageState();
}
class _PuzzlePageState extends State<PuzzlePage> with
WidgetsBindingObserver {
BuildContext _context;
@override
void initState() {
super.initState();
}
@override
void didChangeDependencies(){
super.didChangeDependencies();
// Additional code
}
@override
void deactivate() {
super.deactivate();
//this method not called when user press android back button or quit
print('deactivate');
}
@override
void dispose() {
super.dispose();
WidgetsBinding.instance.removeObserver(this);
//this method not called when user press android back button or quit
print('dispose');
}
@override
void didChangeAppLifecycleState(AppLifecycleState state) {
//print inactive and paused when quit
print(state);
print("lets do something here");
}
@override
void didUpdateWidget(Widget oldWidget) {
super.didUpdateWidget(oldWidget);
print('didUpdateWidget');
AppBuilder.of(_context).rebuild();
}
Widget build(BuildContext context) {
return AppBuilder(
builder: (context) {
return _PuzzleHome(widget.rows, widget.columns);
});
}
}
class _PuzzleHome extends StatefulWidget {
final int _rows, _columns;
const _PuzzleHome(this._rows, this._columns, {Key key}) : super(key:
key);
@override
PuzzleHomeState createState() =>
PuzzleHomeState(PuzzleAnimator(_columns, _rows));
}
// App Builder
class AppBuilder extends StatefulWidget {
const AppBuilder({Key key, this.builder}) : super(key: key);
final Function(BuildContext) builder;
@override
AppBuilderState createState() => new AppBuilderState();
static AppBuilderState of(BuildContext context) {
return context.ancestorStateOfType(const TypeMatcher<AppBuilderState>());
}
}
class AppBuilderState extends State<AppBuilder> {
@override
Widget build(BuildContext context) {
return Container(
child:widget.builder(context) ,
);
}
void rebuild() {
setState(() {});
print('rebuild called');
}
}
flutter: #0 double.toInt (dart:core-patch/double.dart:183:36)
flutter: #1 _BoxEdge.compareTo (package:flutter/src/semantics/semantics.dart:2194:41)
flutter: #2 Comparable.compare (dart:core/comparable.dart:93:55)
flutter: #3 ListMixin._compareAny (dart:collection/list.dart:340:23)
flutter: #4 Sort._dualPivotQuicksort (dart:_internal/sort.dart:238:34)
flutter: #5 Sort._doSort (dart:_internal/sort.dart:60:7)
flutter: #6 Sort.sort (dart:_internal/sort.dart:33:5)
flutter: #7 _ListBase&Object&ListMixin.sort (dart:collection/list.dart:334:10)
flutter: #8 _childrenInDefaultOrder (package:flutter/src/semantics/semantics.dart:2391:9)
flutter: #9 SemanticsNode._childrenInTraversalOrder (package:flutter/src/semantics/semantics.dart:1979:32)
flutter: #10 SemanticsNode._addToUpdate (package:flutter/src/semantics/semantics.dart:1919:50)
flutter: #11 SemanticsOwner.sendSemanticsUpdate (package:flutter/src/semantics/semantics.dart:2523:14)
flutter: #12 PipelineOwner.flushSemantics (package:flutter/src/rendering/object.dart:961:23)
flutter: #13 _WidgetsFlutterBinding&BindingBase&GestureBinding&ServicesBinding&SchedulerBinding&PaintingBinding&SemanticsBinding&RendererBinding.drawFrame (package:flutter/src/rendering/binding.dart:351:19)
flutter: #14 _WidgetsFlutterBinding&BindingBase&GestureBinding&ServicesBinding&SchedulerBinding&PaintingBinding&SemanticsBinding&RendererBinding&WidgetsBinding.drawFrame (package:flutter/src/widgets/binding.dart:701:13)
flutter: #15 _WidgetsFlutterBinding&BindingBase&GestureBinding&ServicesBinding&SchedulerBinding&PaintingBinding&SemanticsBinding&RendererBinding._handlePersistentFrameCallback (package:flutter/src/rendering/binding.dart:286:5)
flutter: #16 _WidgetsFlutterBinding&BindingBase&GestureBinding&ServicesBinding&SchedulerBinding._invokeFrameCallback (package:flutter/src/scheduler/binding.dart:1012:15)
flutter: #17 _WidgetsFlutterBinding&BindingBase&GestureBinding&ServicesBinding&SchedulerBinding.handleDrawFrame (package:flutter/src/scheduler/binding.dart:952:9)
flutter: #18 _WidgetsFlutterBinding&BindingBase&GestureBinding&ServicesBinding&SchedulerBinding._handleDrawFrame (package:flutter/src/scheduler/binding.dart:864:5)
flutter: #22 _invoke (dart:ui/hooks.dart:219:10)
flutter: #23 _drawFrame (dart:ui/hooks.dart:178:3)
flutter: (elided 3 frames from package dart:async)
flutter:
flutter: Another exception was thrown: NoSuchMethodError: The getter '_duration' was called on null. ```
答案 0 :(得分:3)
当一个变量依赖于另一个变量时,会发生此错误。
例如,对于变量行和列,至少一个或另一个必须具有大于0的值。如果两个都为零或一个为null,则将发生错误。
请注意,将null值传递给函数参数将覆盖默认值,并且null优先。
int check({int value = 3}) {
return value;
}
print(check(value: null)); // this will print null
答案 1 :(得分:0)
您可以检查值是无穷大还是南
if (this.isNaN || this.isInfinite){
// default value
}else{
// your logic
}