Reputation: 854
Here is the code. We have a TabController
(from sdk), I am extending this TabController
class:
class TabController extends ChangeNotifier {
int length;
TabController({ int initialIndex = 0,
@required this.length,
@required TickerProvider vSync
}):assert(length != null),
assert(vSync != null);
} //end of TabController
class AppTabController extends TabController {
AppTabController(int mInitialIndex,
int mLength,
TickerProvider mVsync):super(length: mLength, mVsync: vsync ){}
}
Now this AppTabController
's constructor is giving syntax error. Seems like I can't extend TabController class
because:
vsync
is not a member variable of TabController
TabController
constructor itself due to which if the required args are not passed then it will crash.These are the compile errors:
vsync
isn't definedUpvotes: 4
Views: 2091
Reputation: 455
@RahulLohra
If you use your own TickerProvider
(as in the @yahocho example), you will need to implement the correct abstract method createTicker
, as follows:
import 'package:flutter/foundation.dart';
import 'package:flutter/scheduler.dart';
class MyTickerProvider extends TickerProvider{
@override
Ticker createTicker(onTick) =>
Ticker(onTick, debugLabel: kDebugMode ? 'created by $this' : null);
}
Notes:
return null
in createTicker
, you will see an error in the log every time you run the animation.Upvotes: 0
Reputation: 1779
this.length
requires member variable.@required
requires assert
:
instead of =
TickerProvider
because it is abstract class
. I made myTickerProvider
as the example.AppTabController appTabController = new AppTabController(mLength:10, mVsync:new myTickerProvider());
class TabController extends ChangeNotifier {
int length;
TabController({
int initialIndex = 0,
@required this.length,
@required TickerProvider vSync
}) : assert(length != null),
assert(vSync != null);
} //end of TabController
class AppTabController extends TabController {
AppTabController({int mInitialIndex,
int mLength,
TickerProvider mVsync}):super(length: mLength, vSync: mVsync);
}
class myTickerProvider extends TickerProvider{
@override
Ticker createTicker(onTick) {
// TODO: implement createTicker
return null;
}
}
Upvotes: 2