`filipino_cuisine`: migrate to null safety (#920)

pull/925/head
Brett Morgan 3 years ago committed by GitHub
parent 3905b45fba
commit d14e79b833
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

@ -2,8 +2,8 @@ import 'package:flutter/material.dart';
class Cook extends StatefulWidget { class Cook extends StatefulWidget {
final List<String> dr; final List<String> dr;
final String img; final String? img;
final String nme; final String? nme;
const Cook(this.dr, this.img, this.nme); const Cook(this.dr, this.img, this.nme);
@override @override
@ -11,7 +11,7 @@ class Cook extends StatefulWidget {
} }
class CState extends State<Cook> { class CState extends State<Cook> {
List<bool> cb; late List<bool?> cb;
@override @override
initState() { initState() {
@ -34,13 +34,13 @@ class CState extends State<Cook> {
leading: ClipRRect( leading: ClipRRect(
borderRadius: BorderRadius.circular(50), borderRadius: BorderRadius.circular(50),
child: Hero( child: Hero(
tag: widget.nme, tag: widget.nme!,
child: Image.asset(widget.img, child: Image.asset(widget.img!,
fit: BoxFit.cover, width: 100, height: 100))), fit: BoxFit.cover, width: 100, height: 100))),
title: Text(widget.nme, title: Text(widget.nme!,
style: Theme.of(context) style: Theme.of(context)
.textTheme .textTheme
.headline3 .headline3!
.copyWith(fontFamily: 'ark', color: Colors.black))), .copyWith(fontFamily: 'ark', color: Colors.black))),
margin: const EdgeInsets.only(top: 40, bottom: 30, left: 20)), margin: const EdgeInsets.only(top: 40, bottom: 30, left: 20)),
Expanded( Expanded(

@ -123,12 +123,12 @@ class ScalePainter extends BasePainter {
: radius + ((index + 1) * (size + space)); : radius + ((index + 1) * (size + space));
double progress = page - index; double progress = page - index;
_paint.color = Color.lerp(widget.activeColor, widget.color, progress); _paint.color = Color.lerp(widget.activeColor, widget.color, progress)!;
//last //last
canvas.drawCircle(Offset(radius + (index * (size + space)), radius), canvas.drawCircle(Offset(radius + (index * (size + space)), radius),
lerp(radius, radius * widget.scale, progress), _paint); lerp(radius, radius * widget.scale, progress), _paint);
//first //first
_paint.color = Color.lerp(widget.color, widget.activeColor, progress); _paint.color = Color.lerp(widget.color, widget.activeColor, progress)!;
canvas.drawCircle(Offset(secondOffset, radius), canvas.drawCircle(Offset(secondOffset, radius),
lerp(radius * widget.scale, radius, progress), _paint); lerp(radius * widget.scale, radius, progress), _paint);
} }
@ -154,12 +154,12 @@ class ColorPainter extends BasePainter {
? radius ? radius
: radius + ((index + 1) * (size + space)); : radius + ((index + 1) * (size + space));
_paint.color = Color.lerp(widget.activeColor, widget.color, progress); _paint.color = Color.lerp(widget.activeColor, widget.color, progress)!;
//left //left
canvas.drawCircle( canvas.drawCircle(
Offset(radius + (index * (size + space)), radius), radius, _paint); Offset(radius + (index * (size + space)), radius), radius, _paint);
//right //right
_paint.color = Color.lerp(widget.color, widget.activeColor, progress); _paint.color = Color.lerp(widget.color, widget.activeColor, progress)!;
canvas.drawCircle(Offset(secondOffset, radius), radius, _paint); canvas.drawCircle(Offset(secondOffset, radius), radius, _paint);
} }
} }
@ -311,7 +311,7 @@ class PageIndicator extends StatefulWidget {
final Color color; final Color color;
/// layout of the dots,default is [PageIndicatorLayout.SLIDE] /// layout of the dots,default is [PageIndicatorLayout.SLIDE]
final PageIndicatorLayout layout; final PageIndicatorLayout? layout;
// Only valid when layout==PageIndicatorLayout.scale // Only valid when layout==PageIndicatorLayout.scale
final double scale; final double scale;
@ -324,20 +324,18 @@ class PageIndicator extends StatefulWidget {
final double activeSize; final double activeSize;
const PageIndicator( const PageIndicator(
{Key key, {Key? key,
this.size = 20.0, this.size = 20.0,
this.space = 5.0, this.space = 5.0,
@required this.count, required this.count,
this.activeSize = 20.0, this.activeSize = 20.0,
@required this.controller, required this.controller,
this.color = Colors.white30, this.color = Colors.white30,
this.layout = PageIndicatorLayout.SLIDE, this.layout = PageIndicatorLayout.SLIDE,
this.activeColor = Colors.white, this.activeColor = Colors.white,
this.scale = 0.6, this.scale = 0.6,
this.dropHeight = 20.0}) this.dropHeight = 20.0})
: assert(count != null), : super(key: key);
assert(controller != null),
super(key: key);
@override @override
State<StatefulWidget> createState() { State<StatefulWidget> createState() {

File diff suppressed because it is too large Load Diff

@ -32,8 +32,8 @@ class Home extends StatefulWidget {
} }
class HState extends State<Home> { class HState extends State<Home> {
Map<String, dynamic> fd; Map<String, dynamic>? fd;
Map<String, dynamic> fi; Map<String, dynamic>? fi;
@override @override
void initState() { void initState() {
@ -42,10 +42,10 @@ class HState extends State<Home> {
} }
Future<void> getData() async { Future<void> getData() async {
http.Response r = await http.get( http.Response r = await http.get(Uri.parse(
'https://flutter.github.io/samples/web/filipino_cuisine/data.json'); 'https://flutter.github.io/samples/web/filipino_cuisine/data.json'));
fd = json.decode(r.body) as Map<String, dynamic>; fd = json.decode(r.body) as Map<String, dynamic>?;
setState(() => fi = fd['0'] as Map<String, dynamic>); setState(() => fi = fd!['0'] as Map<String, dynamic>?);
} }
@override @override
@ -66,58 +66,59 @@ class HState extends State<Home> {
flex: 5, flex: 5,
child: Swiper( child: Swiper(
onIndexChanged: (n) => onIndexChanged: (n) =>
setState(() => fi = fd['$n'] as Map<String, dynamic>), setState(() => fi = fd!['$n'] as Map<String, dynamic>?),
itemCount: itemCount:
fd.keys.where((key) => int.tryParse(key) != null).length, fd!.keys.where((key) => int.tryParse(key) != null).length,
itemBuilder: (cx, i) { itemBuilder: (cx, i) {
return Container( return Container(
margin: const EdgeInsets.only(top: 40, bottom: 24), margin: const EdgeInsets.only(top: 40, bottom: 24),
child: ClipRRect( child: ClipRRect(
borderRadius: BorderRadius.circular(20), borderRadius: BorderRadius.circular(20),
child: Hero( child: Hero(
tag: fd['$i']['fn'], tag: fd!['$i']['fn'] as Object,
child: Image.asset(fd['$i']['pf'] as String, child: Image.asset(fd!['$i']['pf'] as String,
fit: BoxFit.cover)), fit: BoxFit.cover)),
)); ));
}, },
viewportFraction: .85, viewportFraction: .85,
scale: .9)), scale: .9)),
Text(fi['fn'] as String, Text(fi!['fn'] as String,
style: style: t.headline2!
t.headline2.copyWith(fontFamily: 'ark', color: Colors.black)), .copyWith(fontFamily: 'ark', color: Colors.black)),
Container( Container(
child: Text(fi['cn'] as String, child: Text(fi!['cn'] as String,
style: t.subtitle1.apply(color: Colors.red, fontFamily: 'opb')), style:
t.subtitle1!.apply(color: Colors.red, fontFamily: 'opb')),
margin: const EdgeInsets.only(top: 10, bottom: 30), margin: const EdgeInsets.only(top: 10, bottom: 30),
), ),
Container( Container(
child: Text(fi['dc'] as String, child: Text(fi!['dc'] as String,
textAlign: TextAlign.center, textAlign: TextAlign.center,
style: t.subtitle1.copyWith(fontFamily: 'opr')), style: t.subtitle1!.copyWith(fontFamily: 'opr')),
margin: const EdgeInsets.only(left: 10, right: 10)), margin: const EdgeInsets.only(left: 10, right: 10)),
Expanded( Expanded(
flex: 2, flex: 2,
child: ListView.builder( child: ListView.builder(
scrollDirection: Axis.horizontal, scrollDirection: Axis.horizontal,
itemCount: fi['ig'].length as int, itemCount: fi!['ig'].length as int?,
itemBuilder: (cx, i) { itemBuilder: (cx, i) {
return Row(children: <Widget>[ return Row(children: <Widget>[
Container( Container(
margin: const EdgeInsets.only(left: 10), margin: const EdgeInsets.only(left: 10),
height: 60, height: 60,
child: Image.asset(fi['ig'][i]['p'] as String, child: Image.asset(fi!['ig'][i]['p'] as String,
fit: BoxFit.contain)), fit: BoxFit.contain)),
Container( Container(
margin: const EdgeInsets.only(left: 5, right: 10), margin: const EdgeInsets.only(left: 5, right: 10),
child: Column( child: Column(
mainAxisAlignment: MainAxisAlignment.center, mainAxisAlignment: MainAxisAlignment.center,
children: <Widget>[ children: <Widget>[
Text(fi['ig'][i]['n'] as String, Text(fi!['ig'][i]['n'] as String,
style: t.subtitle2 style: t.subtitle2!
.copyWith(fontFamily: 'opb')), .copyWith(fontFamily: 'opb')),
Text(fi['ig'][i]['c'] as String, Text(fi!['ig'][i]['c'] as String,
style: style:
t.caption.copyWith(fontFamily: 'opr')) t.caption!.copyWith(fontFamily: 'opr'))
])) ]))
]); ]);
})) }))
@ -130,9 +131,9 @@ class HState extends State<Home> {
context, context,
MaterialPageRoute( MaterialPageRoute(
builder: (cx) => Cook( builder: (cx) => Cook(
(fi['in'] as List).cast(), (fi!['in'] as List).cast(),
fi['pf'] as String, fi!['pf'] as String?,
fi['fn'] as String, fi!['fn'] as String?,
))), ))),
), ),
bottomNavigationBar: BottomAppBar( bottomNavigationBar: BottomAppBar(
@ -142,11 +143,11 @@ class HState extends State<Home> {
mainAxisAlignment: MainAxisAlignment.spaceAround, mainAxisAlignment: MainAxisAlignment.spaceAround,
children: <Widget>[ children: <Widget>[
IconButton( IconButton(
icon: Icon(fi['fv'] as bool icon: Icon(fi!['fv'] as bool
? Icons.favorite ? Icons.favorite
: Icons.favorite_border), : Icons.favorite_border),
onPressed: () => onPressed: () =>
setState(() => fi['fv'] = !(fi['fv'] as bool))), setState(() => fi!['fv'] = !(fi!['fv'] as bool))),
IconButton(icon: const Icon(Icons.share), onPressed: () {}) IconButton(icon: const Icon(Icons.share), onPressed: () {})
])), ])),
); );

@ -14,13 +14,13 @@ class IndexController extends ChangeNotifier {
// ignore: constant_identifier_names // ignore: constant_identifier_names
static const int MOVE = 0; static const int MOVE = 0;
Completer<void> _completer; late Completer<void> _completer;
int index; int? index;
bool animation; bool? animation;
int event; int? event;
Future move(int index, {bool animation = true}) { Future move(int index, {bool? animation = true}) {
this.animation = animation ?? true; this.animation = animation ?? true;
this.index = index; this.index = index;
event = MOVE; event = MOVE;
@ -29,7 +29,7 @@ class IndexController extends ChangeNotifier {
return _completer.future; return _completer.future;
} }
Future next({bool animation = true}) { Future next({bool? animation = true}) {
event = NEXT; event = NEXT;
this.animation = animation ?? true; this.animation = animation ?? true;
_completer = Completer(); _completer = Completer();
@ -37,7 +37,7 @@ class IndexController extends ChangeNotifier {
return _completer.future; return _completer.future;
} }
Future previous({bool animation = true}) { Future previous({bool? animation = true}) {
event = PREVIOUS; event = PREVIOUS;
this.animation = animation ?? true; this.animation = animation ?? true;
_completer = Completer(); _completer = Completer();
@ -63,22 +63,22 @@ class ColorPainter extends CustomPainter {
@override @override
void paint(Canvas canvas, Size size) { void paint(Canvas canvas, Size size) {
int index = info.fromIndex; int index = info.fromIndex!;
_paint.color = colors[index]; _paint.color = colors[index];
canvas.drawRect(Rect.fromLTWH(0.0, 0.0, size.width, size.height), _paint); canvas.drawRect(Rect.fromLTWH(0.0, 0.0, size.width, size.height), _paint);
if (info.done) { if (info.done!) {
return; return;
} }
int alpha; int alpha;
int color; int color;
double opacity; double opacity;
double position = info.position; double? position = info.position;
if (info.forward) { if (info.forward!) {
if (index < colors.length - 1) { if (index < colors.length - 1) {
color = colors[index + 1].value & 0x00ffffff; color = colors[index + 1].value & 0x00ffffff;
opacity = (position <= 0 opacity = (position! <= 0
? (-position / info.viewportFraction) ? (-position / info.viewportFraction!)
: 1 - position / info.viewportFraction); : 1 - position / info.viewportFraction!);
if (opacity > 1) { if (opacity > 1) {
opacity -= 1.0; opacity -= 1.0;
} }
@ -94,9 +94,9 @@ class ColorPainter extends CustomPainter {
} else { } else {
if (index > 0) { if (index > 0) {
color = colors[index - 1].value & 0x00ffffff; color = colors[index - 1].value & 0x00ffffff;
opacity = (position > 0 opacity = (position! > 0
? position / info.viewportFraction ? position / info.viewportFraction!
: (1 + position / info.viewportFraction)); : (1 + position / info.viewportFraction!));
if (opacity > 1) { if (opacity > 1) {
opacity -= 1.0; opacity -= 1.0;
} }
@ -138,9 +138,9 @@ class ParallaxColor extends StatefulWidget {
final TransformInfo info; final TransformInfo info;
const ParallaxColor({ const ParallaxColor({
@required this.colors, required this.colors,
@required this.info, required this.info,
@required this.child, required this.child,
}); });
@override @override
@ -156,17 +156,15 @@ class ParallaxContainer extends StatelessWidget {
final double opacityFactor; final double opacityFactor;
const ParallaxContainer( const ParallaxContainer(
{@required this.child, {required this.child,
@required this.position, required this.position,
this.translationFactor = 100.0, this.translationFactor = 100.0,
this.opacityFactor = 1.0}) this.opacityFactor = 1.0});
: assert(position != null),
assert(translationFactor != null);
@override @override
Widget build(BuildContext context) { Widget build(BuildContext context) {
return Opacity( return Opacity(
opacity: (1 - position.abs()).clamp(0.0, 1.0) * opacityFactor as double, opacity: (1 - position.abs()).clamp(0.0, 1.0) * opacityFactor,
child: Transform.translate( child: Transform.translate(
offset: Offset(position * translationFactor, 0.0), offset: Offset(position * translationFactor, 0.0),
child: child, child: child,
@ -179,9 +177,9 @@ class ParallaxImage extends StatelessWidget {
final Image image; final Image image;
final double imageFactor; final double imageFactor;
ParallaxImage.asset(String name, {double position, this.imageFactor = 0.3}) ParallaxImage.asset(String name,
: assert(imageFactor != null), {required double position, this.imageFactor = 0.3})
image = Image.asset(name, : image = Image.asset(name,
fit: BoxFit.cover, fit: BoxFit.cover,
alignment: FractionalOffset( alignment: FractionalOffset(
0.5 + position * imageFactor, 0.5 + position * imageFactor,
@ -211,10 +209,10 @@ const int kDefaultTransactionDuration = 300;
class TransformInfo { class TransformInfo {
/// The `width` of the `TransformerPageView` /// The `width` of the `TransformerPageView`
final double width; final double? width;
/// The `height` of the `TransformerPageView` /// The `height` of the `TransformerPageView`
final double height; final double? height;
/// The `position` of the widget pass to [PageTransformer.transform] /// The `position` of the widget pass to [PageTransformer.transform]
/// A `position` describes how visible the widget is. /// A `position` describes how visible the widget is.
@ -223,29 +221,29 @@ class TransformInfo {
/// The widge in the right ,may be hidden, of the screen's position is greater than 0.0, 1.0 when out of the screen /// The widge in the right ,may be hidden, of the screen's position is greater than 0.0, 1.0 when out of the screen
/// ///
/// ///
final double position; final double? position;
/// The `index` of the widget pass to [PageTransformer.transform] /// The `index` of the widget pass to [PageTransformer.transform]
final int index; final int? index;
/// The `activeIndex` of the PageView /// The `activeIndex` of the PageView
final int activeIndex; final int? activeIndex;
/// The `activeIndex` of the PageView, from user start to swipe /// The `activeIndex` of the PageView, from user start to swipe
/// It will change when user end drag /// It will change when user end drag
final int fromIndex; final int? fromIndex;
/// Next `index` is greater than this `index` /// Next `index` is greater than this `index`
final bool forward; final bool? forward;
/// User drag is done. /// User drag is done.
final bool done; final bool? done;
/// Same as [TransformerPageView.viewportFraction] /// Same as [TransformerPageView.viewportFraction]
final double viewportFraction; final double? viewportFraction;
/// Copy from [TransformerPageView.scrollDirection] /// Copy from [TransformerPageView.scrollDirection]
final Axis scrollDirection; final Axis? scrollDirection;
TransformInfo( TransformInfo(
{this.index, {this.index,
@ -276,9 +274,8 @@ typedef PageTransformerBuilderCallback = Widget Function(
class PageTransformerBuilder extends PageTransformer { class PageTransformerBuilder extends PageTransformer {
final PageTransformerBuilderCallback builder; final PageTransformerBuilderCallback builder;
PageTransformerBuilder({bool reverse = false, @required this.builder}) PageTransformerBuilder({bool reverse = false, required this.builder})
: assert(builder != null), : super(reverse: reverse);
super(reverse: reverse);
@override @override
Widget transform(Widget child, TransformInfo info) { Widget transform(Widget child, TransformInfo info) {
@ -288,11 +285,11 @@ class PageTransformerBuilder extends PageTransformer {
class TransformerPageController extends PageController { class TransformerPageController extends PageController {
final bool loop; final bool loop;
final int itemCount; final int? itemCount;
final bool reverse; final bool reverse;
TransformerPageController({ TransformerPageController({
int initialPage = 0, int? initialPage = 0,
bool keepPage = true, bool keepPage = true,
double viewportFraction = 1.0, double viewportFraction = 1.0,
this.loop = false, this.loop = false,
@ -300,26 +297,26 @@ class TransformerPageController extends PageController {
this.reverse = false, this.reverse = false,
}) : super( }) : super(
initialPage: TransformerPageController._getRealIndexFromRenderIndex( initialPage: TransformerPageController._getRealIndexFromRenderIndex(
initialPage ?? 0, loop, itemCount, reverse), initialPage ?? 0, loop, itemCount, reverse)!,
keepPage: keepPage, keepPage: keepPage,
viewportFraction: viewportFraction); viewportFraction: viewportFraction);
int getRenderIndexFromRealIndex(int index) { int getRenderIndexFromRealIndex(int? index) {
return _getRenderIndexFromRealIndex(index, loop, itemCount, reverse); return _getRenderIndexFromRealIndex(index, loop, itemCount, reverse);
} }
int getRealItemCount() { int? getRealItemCount() {
if (itemCount == 0) return 0; if (itemCount == 0) return 0;
return loop ? itemCount + kMaxValue : itemCount; return loop ? itemCount! + kMaxValue : itemCount;
} }
static int _getRenderIndexFromRealIndex( static int _getRenderIndexFromRealIndex(
int index, bool loop, int itemCount, bool reverse) { int? index, bool loop, int? itemCount, bool reverse) {
if (itemCount == 0) return 0; if (itemCount == 0) return 0;
int renderIndex; int? renderIndex;
if (loop) { if (loop) {
renderIndex = index - kMiddleValue; renderIndex = index! - kMiddleValue;
renderIndex = renderIndex % itemCount; renderIndex = renderIndex % itemCount!;
if (renderIndex < 0) { if (renderIndex < 0) {
renderIndex += itemCount; renderIndex += itemCount;
} }
@ -327,29 +324,26 @@ class TransformerPageController extends PageController {
renderIndex = index; renderIndex = index;
} }
if (reverse) { if (reverse) {
renderIndex = itemCount - renderIndex - 1; renderIndex = itemCount! - renderIndex! - 1;
} }
return renderIndex; return renderIndex!;
} }
double get realPage { double? get realPage {
double page; double? page;
if (position.maxScrollExtent == null || position.minScrollExtent == null) {
page = 0.0; page = super.page;
} else {
page = super.page;
}
return page; return page;
} }
static double _getRenderPageFromRealPage( static double _getRenderPageFromRealPage(
double page, bool loop, int itemCount, bool reverse) { double? page, bool loop, int? itemCount, bool reverse) {
double renderPage; double? renderPage;
if (loop) { if (loop) {
renderPage = page - kMiddleValue; renderPage = page! - kMiddleValue;
renderPage = renderPage % itemCount; renderPage = renderPage % itemCount!;
if (renderPage < 0) { if (renderPage < 0) {
renderPage += itemCount; renderPage += itemCount;
} }
@ -357,28 +351,28 @@ class TransformerPageController extends PageController {
renderPage = page; renderPage = page;
} }
if (reverse) { if (reverse) {
renderPage = itemCount - renderPage - 1; renderPage = itemCount! - renderPage! - 1;
} }
return renderPage; return renderPage!;
} }
@override @override
double get page { double? get page {
return loop return loop
? _getRenderPageFromRealPage(realPage, loop, itemCount, reverse) ? _getRenderPageFromRealPage(realPage, loop, itemCount, reverse)
: realPage; : realPage;
} }
int getRealIndexFromRenderIndex(int index) { int? getRealIndexFromRenderIndex(int? index) {
return _getRealIndexFromRenderIndex(index, loop, itemCount, reverse); return _getRealIndexFromRenderIndex(index, loop, itemCount, reverse);
} }
static int _getRealIndexFromRenderIndex( static int? _getRealIndexFromRenderIndex(
int index, bool loop, int itemCount, bool reverse) { int? index, bool loop, int? itemCount, bool reverse) {
int result = reverse ? (itemCount - index - 1) : index; int? result = reverse ? (itemCount! - index! - 1) : index;
if (loop) { if (loop) {
result += kMiddleValue; result = result! + kMiddleValue;
} }
return result; return result;
} }
@ -388,7 +382,7 @@ class TransformerPageView extends StatefulWidget {
/// Create a `transformed` widget base on the widget that has been passed to the [PageTransformer.transform]. /// Create a `transformed` widget base on the widget that has been passed to the [PageTransformer.transform].
/// See [TransformInfo] /// See [TransformInfo]
/// ///
final PageTransformer transformer; final PageTransformer? transformer;
/// Same as [PageView.scrollDirection] /// Same as [PageView.scrollDirection]
/// ///
@ -396,7 +390,7 @@ class TransformerPageView extends StatefulWidget {
final Axis scrollDirection; final Axis scrollDirection;
/// Same as [PageView.physics] /// Same as [PageView.physics]
final ScrollPhysics physics; final ScrollPhysics? physics;
/// Set to false to disable page snapping, useful for custom scroll behavior. /// Set to false to disable page snapping, useful for custom scroll behavior.
/// Same as [PageView.pageSnapping] /// Same as [PageView.pageSnapping]
@ -404,20 +398,20 @@ class TransformerPageView extends StatefulWidget {
/// Called whenever the page in the center of the viewport changes. /// Called whenever the page in the center of the viewport changes.
/// Same as [PageView.onPageChanged] /// Same as [PageView.onPageChanged]
final ValueChanged<int> onPageChanged; final ValueChanged<int>? onPageChanged;
final IndexedWidgetBuilder itemBuilder; final IndexedWidgetBuilder? itemBuilder;
// See [IndexController.mode],[IndexController.next],[IndexController.previous] // See [IndexController.mode],[IndexController.next],[IndexController.previous]
final IndexController controller; final IndexController? controller;
/// Animation duration /// Animation duration
final Duration duration; final Duration duration;
/// Animation curve /// Animation curve
final Curve curve; final Curve? curve;
final TransformerPageController pageController; final TransformerPageController? pageController;
/// Set true to open infinity loop mode. /// Set true to open infinity loop mode.
final bool loop; final bool loop;
@ -429,7 +423,7 @@ class TransformerPageView extends StatefulWidget {
final double viewportFraction; final double viewportFraction;
/// If not set, it is controlled by this widget. /// If not set, it is controlled by this widget.
final int index; final int? index;
/// Creates a scrollable list that works page by page using widgets that are /// Creates a scrollable list that works page by page using widgets that are
/// created on demand. /// created on demand.
@ -444,9 +438,9 @@ class TransformerPageView extends StatefulWidget {
/// [itemBuilder] will be called only with indices greater than or equal to /// [itemBuilder] will be called only with indices greater than or equal to
/// zero and less than [itemCount]. /// zero and less than [itemCount].
const TransformerPageView({ const TransformerPageView({
Key key, Key? key,
this.index, this.index,
Duration duration, Duration? duration,
this.curve = Curves.ease, this.curve = Curves.ease,
this.viewportFraction = 1.0, this.viewportFraction = 1.0,
this.loop = false, this.loop = false,
@ -458,29 +452,27 @@ class TransformerPageView extends StatefulWidget {
this.transformer, this.transformer,
this.itemBuilder, this.itemBuilder,
this.pageController, this.pageController,
@required this.itemCount, required this.itemCount,
}) : assert(itemCount != null), }) : assert(itemCount == 0 || itemBuilder != null || transformer != null),
assert(itemCount == 0 || itemBuilder != null || transformer != null),
duration = duration ?? duration = duration ??
const Duration(milliseconds: kDefaultTransactionDuration), const Duration(milliseconds: kDefaultTransactionDuration),
super(key: key); super(key: key);
factory TransformerPageView.children( factory TransformerPageView.children(
{Key key, {Key? key,
int index, int? index,
Duration duration, Duration? duration,
Curve curve = Curves.ease, Curve curve = Curves.ease,
double viewportFraction = 1.0, double viewportFraction = 1.0,
bool loop = false, bool loop = false,
Axis scrollDirection = Axis.horizontal, Axis scrollDirection = Axis.horizontal,
ScrollPhysics physics, ScrollPhysics? physics,
bool pageSnapping = true, bool pageSnapping = true,
ValueChanged<int> onPageChanged, ValueChanged<int>? onPageChanged,
IndexController controller, IndexController? controller,
PageTransformer transformer, PageTransformer? transformer,
@required List<Widget> children, required List<Widget> children,
TransformerPageController pageController}) { TransformerPageController? pageController}) {
assert(children != null);
return TransformerPageView( return TransformerPageView(
itemCount: children.length, itemCount: children.length,
itemBuilder: (context, index) { itemBuilder: (context, index) {
@ -506,92 +498,93 @@ class TransformerPageView extends StatefulWidget {
return _TransformerPageViewState(); return _TransformerPageViewState();
} }
static int getRealIndexFromRenderIndex( static int? getRealIndexFromRenderIndex(
{bool reverse, int index, int itemCount, bool loop}) { {required bool reverse, int? index, int? itemCount, required bool loop}) {
int initPage = reverse ? (itemCount - index - 1) : index; int? initPage = reverse ? (itemCount! - index! - 1) : index;
if (loop) { if (loop) {
initPage += kMiddleValue; initPage = initPage! + kMiddleValue;
} }
return initPage; return initPage;
} }
static PageController createPageController( static PageController createPageController(
{bool reverse, {required bool reverse,
int index, int? index,
int itemCount, int? itemCount,
bool loop, required bool loop,
double viewportFraction}) { required double viewportFraction}) {
return PageController( return PageController(
initialPage: getRealIndexFromRenderIndex( initialPage: getRealIndexFromRenderIndex(
reverse: reverse, index: index, itemCount: itemCount, loop: loop), reverse: reverse, index: index, itemCount: itemCount, loop: loop)!,
viewportFraction: viewportFraction); viewportFraction: viewportFraction);
} }
} }
class _TransformerPageViewState extends State<TransformerPageView> { class _TransformerPageViewState extends State<TransformerPageView> {
Size _size; Size? _size;
int _activeIndex; int? _activeIndex;
double _currentPixels; double? _currentPixels;
bool _done = false; bool _done = false;
///This value will not change until user end drag. ///This value will not change until user end drag.
int _fromIndex; int? _fromIndex;
PageTransformer _transformer; PageTransformer? _transformer;
TransformerPageController _pageController; TransformerPageController? _pageController;
Widget _buildItemNormal(BuildContext context, int index) { Widget _buildItemNormal(BuildContext context, int index) {
int renderIndex = _pageController.getRenderIndexFromRealIndex(index); int renderIndex = _pageController!.getRenderIndexFromRealIndex(index);
Widget child = widget.itemBuilder(context, renderIndex); Widget child = widget.itemBuilder!(context, renderIndex);
return child; return child;
} }
Widget _buildItem(BuildContext context, int index) { Widget _buildItem(BuildContext context, int index) {
return AnimatedBuilder( return AnimatedBuilder(
animation: _pageController, animation: _pageController!,
builder: (c, w) { builder: (c, w) {
int renderIndex = _pageController.getRenderIndexFromRealIndex(index); int renderIndex = _pageController!.getRenderIndexFromRealIndex(index);
Widget child; Widget? child;
if (widget.itemBuilder != null) { if (widget.itemBuilder != null) {
child = widget.itemBuilder(context, renderIndex); child = widget.itemBuilder!(context, renderIndex);
} }
child ??= Container(); child ??= Container();
if (_size == null) { if (_size == null) {
return child ?? Container(); return child;
} }
double position; double position;
double page = _pageController.realPage; double? page = _pageController!.realPage;
if (_transformer.reverse) { if (_transformer!.reverse) {
position = page - index; position = page! - index;
} else { } else {
position = index - page; position = index - page!;
} }
position *= widget.viewportFraction; position *= widget.viewportFraction;
TransformInfo info = TransformInfo( TransformInfo info = TransformInfo(
index: renderIndex, index: renderIndex,
width: _size.width, width: _size!.width,
height: _size.height, height: _size!.height,
position: position.clamp(-1.0, 1.0) as double, position: position.clamp(-1.0, 1.0),
activeIndex: activeIndex:
_pageController.getRenderIndexFromRealIndex(_activeIndex), _pageController!.getRenderIndexFromRealIndex(_activeIndex),
fromIndex: _fromIndex, fromIndex: _fromIndex,
forward: _pageController.position.pixels - _currentPixels >= 0, forward: _pageController!.position.pixels - _currentPixels! >= 0,
done: _done, done: _done,
scrollDirection: widget.scrollDirection, scrollDirection: widget.scrollDirection,
viewportFraction: widget.viewportFraction); viewportFraction: widget.viewportFraction);
return _transformer.transform(child, info); return _transformer!.transform(child, info);
}); });
} }
double _calcCurrentPixels() { double? _calcCurrentPixels() {
_currentPixels = _pageController.getRenderIndexFromRealIndex(_activeIndex) * _currentPixels =
_pageController.position.viewportDimension * _pageController!.getRenderIndexFromRealIndex(_activeIndex) *
widget.viewportFraction; _pageController!.position.viewportDimension *
widget.viewportFraction;
// print("activeIndex:$_activeIndex , pix:$_currentPixels"); // print("activeIndex:$_activeIndex , pix:$_currentPixels");
@ -604,13 +597,13 @@ class _TransformerPageViewState extends State<TransformerPageView> {
_transformer == null ? _buildItemNormal : _buildItem; _transformer == null ? _buildItemNormal : _buildItem;
Widget child = PageView.builder( Widget child = PageView.builder(
itemBuilder: builder, itemBuilder: builder,
itemCount: _pageController.getRealItemCount(), itemCount: _pageController!.getRealItemCount(),
onPageChanged: _onIndexChanged, onPageChanged: _onIndexChanged,
controller: _pageController, controller: _pageController,
scrollDirection: widget.scrollDirection, scrollDirection: widget.scrollDirection,
physics: widget.physics, physics: widget.physics,
pageSnapping: widget.pageSnapping, pageSnapping: widget.pageSnapping,
reverse: _pageController.reverse, reverse: _pageController!.reverse,
); );
if (_transformer == null) { if (_transformer == null) {
return child; return child;
@ -636,28 +629,23 @@ class _TransformerPageViewState extends State<TransformerPageView> {
void _onIndexChanged(int index) { void _onIndexChanged(int index) {
_activeIndex = index; _activeIndex = index;
if (widget.onPageChanged != null) { if (widget.onPageChanged != null) {
widget.onPageChanged(_pageController.getRenderIndexFromRealIndex(index)); widget
.onPageChanged!(_pageController!.getRenderIndexFromRealIndex(index));
} }
} }
void _onGetSize(dynamic _) { void _onGetSize(dynamic _) {
Size size; Size? size;
if (context == null) { RenderObject? renderObject = context.findRenderObject();
onGetSize(size);
return;
}
RenderObject renderObject = context.findRenderObject();
if (renderObject != null) { if (renderObject != null) {
Rect bounds = renderObject.paintBounds; Rect bounds = renderObject.paintBounds;
if (bounds != null) { size = bounds.size;
size = bounds.size;
}
} }
_calcCurrentPixels(); _calcCurrentPixels();
onGetSize(size); onGetSize(size);
} }
void onGetSize(Size size) { void onGetSize(Size? size) {
if (mounted) { if (mounted) {
setState(() { setState(() {
_size = size; _size = size;
@ -675,14 +663,14 @@ class _TransformerPageViewState extends State<TransformerPageView> {
itemCount: widget.itemCount, itemCount: widget.itemCount,
loop: widget.loop, loop: widget.loop,
reverse: reverse:
widget.transformer == null ? false : widget.transformer.reverse); widget.transformer == null ? false : widget.transformer!.reverse);
// int initPage = _getRealIndexFromRenderIndex(index); // int initPage = _getRealIndexFromRenderIndex(index);
// _pageController = new PageController(initialPage: initPage,viewportFraction: widget.viewportFraction); // _pageController = new PageController(initialPage: initPage,viewportFraction: widget.viewportFraction);
_fromIndex = _activeIndex = _pageController.initialPage; _fromIndex = _activeIndex = _pageController!.initialPage;
_controller = getNotifier(); _controller = getNotifier();
if (_controller != null) { if (_controller != null) {
_controller.addListener(onChangeNotifier); _controller!.addListener(onChangeNotifier);
} }
super.initState(); super.initState();
} }
@ -703,29 +691,29 @@ class _TransformerPageViewState extends State<TransformerPageView> {
loop: widget.loop, loop: widget.loop,
reverse: widget.transformer == null reverse: widget.transformer == null
? false ? false
: widget.transformer.reverse); : widget.transformer!.reverse);
} }
} }
if (_pageController.getRenderIndexFromRealIndex(_activeIndex) != index) { if (_pageController!.getRenderIndexFromRealIndex(_activeIndex) != index) {
_fromIndex = _activeIndex = _pageController.initialPage; _fromIndex = _activeIndex = _pageController!.initialPage;
if (!created) { if (!created) {
int initPage = _pageController.getRealIndexFromRenderIndex(index); int initPage = _pageController!.getRealIndexFromRenderIndex(index)!;
_pageController.animateToPage(initPage, _pageController!.animateToPage(initPage,
duration: widget.duration, curve: widget.curve); duration: widget.duration, curve: widget.curve!);
} }
} }
if (_transformer != null) { if (_transformer != null) {
WidgetsBinding.instance.addPostFrameCallback(_onGetSize); WidgetsBinding.instance!.addPostFrameCallback(_onGetSize);
} }
if (_controller != getNotifier()) { if (_controller != getNotifier()) {
if (_controller != null) { if (_controller != null) {
_controller.removeListener(onChangeNotifier); _controller!.removeListener(onChangeNotifier);
} }
_controller = getNotifier(); _controller = getNotifier();
if (_controller != null) { if (_controller != null) {
_controller.addListener(onChangeNotifier); _controller!.addListener(onChangeNotifier);
} }
} }
super.didUpdateWidget(oldWidget); super.didUpdateWidget(oldWidget);
@ -734,36 +722,36 @@ class _TransformerPageViewState extends State<TransformerPageView> {
@override @override
void didChangeDependencies() { void didChangeDependencies() {
if (_transformer != null) { if (_transformer != null) {
WidgetsBinding.instance.addPostFrameCallback(_onGetSize); WidgetsBinding.instance!.addPostFrameCallback(_onGetSize);
} }
super.didChangeDependencies(); super.didChangeDependencies();
} }
ChangeNotifier getNotifier() { ChangeNotifier? getNotifier() {
return widget.controller; return widget.controller;
} }
int _calcNextIndex(bool next) { int _calcNextIndex(bool next) {
int currentIndex = _activeIndex; int? currentIndex = _activeIndex;
if (_pageController.reverse) { if (_pageController!.reverse) {
if (next) { if (next) {
currentIndex--; currentIndex = currentIndex! - 1;
} else { } else {
currentIndex++; currentIndex = currentIndex! + 1;
} }
} else { } else {
if (next) { if (next) {
currentIndex++; currentIndex = currentIndex! + 1;
} else { } else {
currentIndex--; currentIndex = currentIndex! - 1;
} }
} }
if (!_pageController.loop) { if (!_pageController!.loop) {
if (currentIndex >= _pageController.itemCount) { if (currentIndex >= _pageController!.itemCount!) {
currentIndex = 0; currentIndex = 0;
} else if (currentIndex < 0) { } else if (currentIndex < 0) {
currentIndex = _pageController.itemCount - 1; currentIndex = _pageController!.itemCount! - 1;
} }
} }
@ -771,13 +759,13 @@ class _TransformerPageViewState extends State<TransformerPageView> {
} }
void onChangeNotifier() { void onChangeNotifier() {
int event = widget.controller.event; int? event = widget.controller!.event;
int index; int? index;
switch (event) { switch (event) {
case IndexController.MOVE: case IndexController.MOVE:
{ {
index = _pageController index = _pageController!
.getRealIndexFromRenderIndex(widget.controller.index); .getRealIndexFromRenderIndex(widget.controller!.index);
} }
break; break;
case IndexController.PREVIOUS: case IndexController.PREVIOUS:
@ -790,24 +778,24 @@ class _TransformerPageViewState extends State<TransformerPageView> {
//ignore this event //ignore this event
return; return;
} }
if (widget.controller.animation) { if (widget.controller!.animation!) {
_pageController _pageController!
.animateToPage(index, .animateToPage(index!,
duration: widget.duration, curve: widget.curve ?? Curves.ease) duration: widget.duration, curve: widget.curve ?? Curves.ease)
.whenComplete(widget.controller.complete); .whenComplete(widget.controller!.complete);
} else { } else {
_pageController.jumpToPage(index); _pageController!.jumpToPage(index!);
widget.controller.complete(); widget.controller!.complete();
} }
} }
ChangeNotifier _controller; ChangeNotifier? _controller;
@override @override
void dispose() { void dispose() {
super.dispose(); super.dispose();
if (_controller != null) { if (_controller != null) {
_controller.removeListener(onChangeNotifier); _controller!.removeListener(onChangeNotifier);
} }
} }
} }

@ -1,6 +1,13 @@
# Generated by pub # Generated by pub
# See https://dart.dev/tools/pub/glossary#lockfile # See https://dart.dev/tools/pub/glossary#lockfile
packages: packages:
async:
dependency: transitive
description:
name: async
url: "https://pub.dartlang.org"
source: hosted
version: "2.8.2"
characters: characters:
dependency: transitive dependency: transitive
description: description:
@ -54,14 +61,14 @@ packages:
name: http name: http
url: "https://pub.dartlang.org" url: "https://pub.dartlang.org"
source: hosted source: hosted
version: "0.12.2" version: "0.13.4"
http_parser: http_parser:
dependency: transitive dependency: transitive
description: description:
name: http_parser name: http_parser
url: "https://pub.dartlang.org" url: "https://pub.dartlang.org"
source: hosted source: hosted
version: "3.1.4" version: "4.0.0"
lints: lints:
dependency: transitive dependency: transitive
description: description:
@ -83,13 +90,6 @@ packages:
url: "https://pub.dartlang.org" url: "https://pub.dartlang.org"
source: hosted source: hosted
version: "1.8.0" version: "1.8.0"
pedantic:
dependency: transitive
description:
name: pedantic
url: "https://pub.dartlang.org"
source: hosted
version: "1.11.1"
sky_engine: sky_engine:
dependency: transitive dependency: transitive
description: flutter description: flutter
@ -138,5 +138,5 @@ packages:
source: hosted source: hosted
version: "2.1.0" version: "2.1.0"
sdks: sdks:
dart: ">=2.12.0 <3.0.0" dart: ">=2.14.0 <3.0.0"
flutter: ">=0.1.4" flutter: ">=0.1.4"

@ -1,13 +1,13 @@
name: filipino_cuisine name: filipino_cuisine
environment: environment:
sdk: ">=2.2.0 <3.0.0" sdk: '>=2.12.0 <3.0.0'
dependencies: dependencies:
flutter: flutter:
sdk: flutter sdk: flutter
flutter_swiper: ^1.1.6 flutter_swiper: ^1.1.6
http: ^0.12.0 http: ^0.13.4
dev_dependencies: dev_dependencies:
flutter_lints: ^1.0.0 flutter_lints: ^1.0.0

Loading…
Cancel
Save