RuffianZhong / flutter_lifecycle

Flutter Lifecycle
MIT License
14 stars 3 forks source link

getting typerror #2

Open sunil-singh-chaudhary opened 1 week ago

sunil-singh-chaudhary commented 1 week ago

_TypeError (type 'Null' is not a subtype of type 'PageRoute' in type cast)

my main.dart

`class _MyAppState extends State with Lifecycle { FlutterLocalNotificationsPlugin? flutterLocalNotificationsPlugin;

@override void initState() { super.initState(); getLifecycle().addObserver(AViewModel()); }}`

and

`import 'dart:developer';

import 'package:flutter/widgets.dart'; import 'package:flutter_lifecycle_aware/lifecycle_observer.dart'; import 'package:flutter_lifecycle_aware/lifecycle_owner.dart'; import 'package:flutter_lifecycle_aware/lifecycle_state.dart';

///Where you need to monitor the StatefulWidget lifecycle class AViewModel extends LifecycleObserver { ///resources to be released ScrollController controller = ScrollController();

///initData void initData() { log('AViewModel - initData called'); }

///destroy/release resources void destroy() { log('AViewModel - destroy called');

controller.dispose();

}

///Lifecycle callback listener @override void onLifecycleChanged(LifecycleOwner owner, LifecycleState state) { if (state == LifecycleState.onCreate) { log('AViewModel - onCreate called'); } else if (state == LifecycleState.onInit) { initData(); log('AViewModel - onInit called'); } else if (state == LifecycleState.onDestroy) { destroy(); } else if (state == LifecycleState.onResume) { log('AViewModel - resumed called'); } else if (state == LifecycleState.onPause) { log('AViewModel - paused called'); } else if (state == LifecycleState.onStop) { log('AViewModel - onStop called'); } } } `

RuffianZhong commented 6 days ago

@sunil-singh-chaudhary Perhaps you should check the basic usage rules of Flutter, as this error seems unrelated to this library