diff --git a/web/filipino_cuisine/lib/cook.dart b/web/filipino_cuisine/lib/cook.dart index b121f0df8..8c4093e44 100644 --- a/web/filipino_cuisine/lib/cook.dart +++ b/web/filipino_cuisine/lib/cook.dart @@ -2,8 +2,8 @@ import 'package:flutter/material.dart'; class Cook extends StatefulWidget { final List dr; - final String img; - final String nme; + final String? img; + final String? nme; const Cook(this.dr, this.img, this.nme); @override @@ -11,7 +11,7 @@ class Cook extends StatefulWidget { } class CState extends State { - List cb; + late List cb; @override initState() { @@ -34,13 +34,13 @@ class CState extends State { leading: ClipRRect( borderRadius: BorderRadius.circular(50), child: Hero( - tag: widget.nme, - child: Image.asset(widget.img, + tag: widget.nme!, + child: Image.asset(widget.img!, fit: BoxFit.cover, width: 100, height: 100))), - title: Text(widget.nme, + title: Text(widget.nme!, style: Theme.of(context) .textTheme - .headline3 + .headline3! .copyWith(fontFamily: 'ark', color: Colors.black))), margin: const EdgeInsets.only(top: 40, bottom: 30, left: 20)), Expanded( diff --git a/web/filipino_cuisine/lib/flutter_page_indicator.dart b/web/filipino_cuisine/lib/flutter_page_indicator.dart index 1273f9a12..8cc53f8a2 100644 --- a/web/filipino_cuisine/lib/flutter_page_indicator.dart +++ b/web/filipino_cuisine/lib/flutter_page_indicator.dart @@ -123,12 +123,12 @@ class ScalePainter extends BasePainter { : radius + ((index + 1) * (size + space)); double progress = page - index; - _paint.color = Color.lerp(widget.activeColor, widget.color, progress); + _paint.color = Color.lerp(widget.activeColor, widget.color, progress)!; //last canvas.drawCircle(Offset(radius + (index * (size + space)), radius), lerp(radius, radius * widget.scale, progress), _paint); //first - _paint.color = Color.lerp(widget.color, widget.activeColor, progress); + _paint.color = Color.lerp(widget.color, widget.activeColor, progress)!; canvas.drawCircle(Offset(secondOffset, radius), lerp(radius * widget.scale, radius, progress), _paint); } @@ -154,12 +154,12 @@ class ColorPainter extends BasePainter { ? radius : radius + ((index + 1) * (size + space)); - _paint.color = Color.lerp(widget.activeColor, widget.color, progress); + _paint.color = Color.lerp(widget.activeColor, widget.color, progress)!; //left canvas.drawCircle( Offset(radius + (index * (size + space)), radius), radius, _paint); //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); } } @@ -311,7 +311,7 @@ class PageIndicator extends StatefulWidget { final Color color; /// layout of the dots,default is [PageIndicatorLayout.SLIDE] - final PageIndicatorLayout layout; + final PageIndicatorLayout? layout; // Only valid when layout==PageIndicatorLayout.scale final double scale; @@ -324,20 +324,18 @@ class PageIndicator extends StatefulWidget { final double activeSize; const PageIndicator( - {Key key, + {Key? key, this.size = 20.0, this.space = 5.0, - @required this.count, + required this.count, this.activeSize = 20.0, - @required this.controller, + required this.controller, this.color = Colors.white30, this.layout = PageIndicatorLayout.SLIDE, this.activeColor = Colors.white, this.scale = 0.6, this.dropHeight = 20.0}) - : assert(count != null), - assert(controller != null), - super(key: key); + : super(key: key); @override State createState() { diff --git a/web/filipino_cuisine/lib/flutter_swiper.dart b/web/filipino_cuisine/lib/flutter_swiper.dart index 8344e0fdb..9fee58e5b 100644 --- a/web/filipino_cuisine/lib/flutter_swiper.dart +++ b/web/filipino_cuisine/lib/flutter_swiper.dart @@ -31,27 +31,27 @@ class Swiper extends StatefulWidget { final bool outer; /// Inner item height, this property is valid if layout=STACK or layout=TINDER or LAYOUT=CUSTOM, - final double itemHeight; + final double? itemHeight; /// Inner item width, this property is valid if layout=STACK or layout=TINDER or LAYOUT=CUSTOM, - final double itemWidth; + final double? itemWidth; // height of the inside container,this property is valid when outer=true,otherwise the inside container size is controlled by parent widget - final double containerHeight; + final double? containerHeight; // width of the inside container,this property is valid when outer=true,otherwise the inside container size is controlled by parent widget - final double containerWidth; + final double? containerWidth; /// Build item on index - final IndexedWidgetBuilder itemBuilder; + final IndexedWidgetBuilder? itemBuilder; /// Support transform like Android PageView did /// `itemBuilder` and `transformItemBuilder` must have one not null - final PageTransformer transformer; + final PageTransformer? transformer; /// count of the display items final int itemCount; - final ValueChanged onIndexChanged; + final ValueChanged? onIndexChanged; ///auto play config final bool autoplay; @@ -77,24 +77,24 @@ class Swiper extends StatefulWidget { ///Index number of initial slide. ///If not set , the `Swiper` is 'uncontrolled', which means manage index by itself ///If set , the `Swiper` is 'controlled', which means the index is fully managed by parent widget. - final int index; + final int? index; ///Called when tap - final SwiperOnTap onTap; + final SwiperOnTap? onTap; ///The swiper pagination plugin - final SwiperPlugin pagination; + final SwiperPlugin? pagination; ///the swiper control button plugin - final SwiperPlugin control; + final SwiperPlugin? control; ///other plugins, you can custom your own plugin - final List plugins; + final List? plugins; /// - final SwiperController controller; + final SwiperController? controller; - final ScrollPhysics physics; + final ScrollPhysics? physics; /// final double viewportFraction; @@ -103,13 +103,13 @@ class Swiper extends StatefulWidget { final SwiperLayout layout; /// this value is valid when layout == SwiperLayout.CUSTOM - final CustomLayoutOption customLayoutOption; + final CustomLayoutOption? customLayoutOption; // This value is valid when viewportFraction is set and < 1.0 - final double scale; + final double? scale; // This value is valid when viewportFraction is set and < 1.0 - final double fade; + final double? fade; final PageIndicatorLayout indicatorLayout; @@ -119,7 +119,7 @@ class Swiper extends StatefulWidget { /// this.transformer, - @required this.itemCount, + required this.itemCount, this.autoplay = false, this.layout = SwiperLayout.DEFAULT, this.autoplayDelay = kDefaultAutoplayDelayMs, @@ -135,7 +135,7 @@ class Swiper extends StatefulWidget { this.pagination, this.plugins, this.physics, - Key key, + Key? key, this.controller, this.customLayoutOption, @@ -162,36 +162,34 @@ class Swiper extends StatefulWidget { super(key: key); factory Swiper.children({ - @required List children, + required List children, bool autoplay = false, - PageTransformer transformer, + PageTransformer? transformer, int autoplayDelay = kDefaultAutoplayDelayMs, bool reverse = false, bool autoplayDisableOnInteraction = true, int duration = kDefaultAutoplayTransactionDuration, - ValueChanged onIndexChanged, - int index, - SwiperOnTap onTap, + ValueChanged? onIndexChanged, + int? index, + SwiperOnTap? onTap, bool loop = true, Curve curve = Curves.ease, Axis scrollDirection = Axis.horizontal, - SwiperPlugin pagination, - SwiperPlugin control, - List plugins, - SwiperController controller, - Key key, - CustomLayoutOption customLayoutOption, - ScrollPhysics physics, - double containerHeight, - double containerWidth, + SwiperPlugin? pagination, + SwiperPlugin? control, + List? plugins, + SwiperController? controller, + Key? key, + CustomLayoutOption? customLayoutOption, + ScrollPhysics? physics, + double? containerHeight, + double? containerWidth, double viewportFraction = 1.0, - double itemHeight, - double itemWidth, + double? itemHeight, + double? itemWidth, bool outer = false, double scale = 1.0, }) { - assert(children != null, "children must not be null"); - return Swiper( transformer: transformer, customLayoutOption: customLayoutOption, @@ -225,32 +223,32 @@ class Swiper extends StatefulWidget { } factory Swiper.list({ - PageTransformer transformer, - List list, - CustomLayoutOption customLayoutOption, - SwiperDataBuilder builder, + PageTransformer? transformer, + required List list, + CustomLayoutOption? customLayoutOption, + SwiperDataBuilder? builder, bool autoplay = false, int autoplayDelay = kDefaultAutoplayDelayMs, bool reverse = false, bool autoplayDisableOnInteraction = true, int duration = kDefaultAutoplayTransactionDuration, - ValueChanged onIndexChanged, - int index, - SwiperOnTap onTap, + ValueChanged? onIndexChanged, + int? index, + SwiperOnTap? onTap, bool loop = true, Curve curve = Curves.ease, Axis scrollDirection = Axis.horizontal, - SwiperPlugin pagination, - SwiperPlugin control, - List plugins, - SwiperController controller, - Key key, - ScrollPhysics physics, - double containerHeight, - double containerWidth, + SwiperPlugin? pagination, + SwiperPlugin? control, + List? plugins, + SwiperController? controller, + Key? key, + ScrollPhysics? physics, + double? containerHeight, + double? containerWidth, double viewportFraction = 1.0, - double itemHeight, - double itemWidth, + double? itemHeight, + double? itemWidth, bool outer = false, double scale = 1.0, }) { @@ -281,7 +279,7 @@ class Swiper extends StatefulWidget { plugins: plugins, physics: physics, itemBuilder: (context, index) { - return builder(context, list[index], index); + return builder!(context, list[index], index); }, itemCount: list.length); } @@ -293,21 +291,21 @@ class Swiper extends StatefulWidget { } abstract class _SwiperTimerMixin extends State { - Timer _timer; + Timer? _timer; - SwiperController _controller; + SwiperController? _controller; @override void initState() { _controller = widget.controller; _controller ??= SwiperController(); - _controller.addListener(_onController); + _controller!.addListener(_onController); _handleAutoplay(); super.initState(); } void _onController() { - switch (_controller.event) { + switch (_controller!.event) { case SwiperController.START_AUTOPLAY: { if (_timer == null) { @@ -329,9 +327,9 @@ abstract class _SwiperTimerMixin extends State { void didUpdateWidget(Swiper oldWidget) { if (_controller != oldWidget.controller) { if (oldWidget.controller != null) { - oldWidget.controller.removeListener(_onController); + oldWidget.controller!.removeListener(_onController); _controller = oldWidget.controller; - _controller.addListener(_onController); + _controller!.addListener(_onController); } } _handleAutoplay(); @@ -341,7 +339,7 @@ abstract class _SwiperTimerMixin extends State { @override void dispose() { if (_controller != null) { - _controller.removeListener(_onController); + _controller!.removeListener(_onController); // _controller.dispose(); } @@ -350,7 +348,7 @@ abstract class _SwiperTimerMixin extends State { } bool _autoplayEnabled() { - return _controller.autoplay ?? widget.autoplay; + return _controller!.autoplay ?? widget.autoplay; } void _handleAutoplay() { @@ -368,29 +366,29 @@ abstract class _SwiperTimerMixin extends State { } void _onTimer(Timer timer) { - _controller.next(animation: true); + _controller!.next(animation: true); } void _stopAutoplay() { if (_timer != null) { - _timer.cancel(); + _timer!.cancel(); _timer = null; } } } class _SwiperState extends _SwiperTimerMixin { - int _activeIndex; + int? _activeIndex; - TransformerPageController _pageController; + TransformerPageController? _pageController; Widget _wrapTap(BuildContext context, int index) { return GestureDetector( behavior: HitTestBehavior.opaque, onTap: () { - widget.onTap(index); + widget.onTap!(index); }, - child: widget.itemBuilder(context, index), + child: widget.itemBuilder!(context, index), ); } @@ -403,14 +401,14 @@ class _SwiperState extends _SwiperTimerMixin { loop: widget.loop, itemCount: widget.itemCount, reverse: - widget.transformer == null ? false : widget.transformer.reverse, + widget.transformer == null ? false : widget.transformer!.reverse, viewportFraction: widget.viewportFraction); } super.initState(); } bool _isPageViewLayout() { - return widget.layout == null || widget.layout == SwiperLayout.DEFAULT; + return widget.layout == SwiperLayout.DEFAULT; } @override @@ -419,7 +417,7 @@ class _SwiperState extends _SwiperTimerMixin { } bool _getReverse(Swiper widget) => - widget.transformer == null ? false : widget.transformer.reverse; + widget.transformer == null ? false : widget.transformer!.reverse; @override void didUpdateWidget(Swiper oldWidget) { @@ -442,7 +440,7 @@ class _SwiperState extends _SwiperTimerMixin { scheduleMicrotask(() { // So that we have a chance to do `removeListener` in child widgets. if (_pageController != null) { - _pageController.dispose(); + _pageController!.dispose(); _pageController = null; } }); @@ -457,12 +455,12 @@ class _SwiperState extends _SwiperTimerMixin { _activeIndex = index; }); if (widget.onIndexChanged != null) { - widget.onIndexChanged(index); + widget.onIndexChanged!(index); } } Widget _buildSwiper() { - IndexedWidgetBuilder itemBuilder; + IndexedWidgetBuilder? itemBuilder; if (widget.onTap != null) { itemBuilder = _wrapTap; } else { @@ -484,7 +482,7 @@ class _SwiperState extends _SwiperTimerMixin { scrollDirection: widget.scrollDirection, ); } else if (_isPageViewLayout()) { - PageTransformer transformer = widget.transformer; + PageTransformer? transformer = widget.transformer; if (widget.scale != null || widget.fade != null) { transformer = ScaleAndFadeTransformer(scale: widget.scale, fade: widget.fade); @@ -541,7 +539,7 @@ class _SwiperState extends _SwiperTimerMixin { } else if (widget.layout == SwiperLayout.CUSTOM) { return _CustomLayoutSwiper( loop: widget.loop, - option: widget.customLayoutOption, + option: widget.customLayoutOption!, itemWidth: widget.itemWidth, itemHeight: widget.itemHeight, itemCount: widget.itemCount, @@ -558,7 +556,7 @@ class _SwiperState extends _SwiperTimerMixin { } } - SwiperPluginConfig _ensureConfig(SwiperPluginConfig config) { + SwiperPluginConfig? _ensureConfig(SwiperPluginConfig? config) { config ??= SwiperPluginConfig( outer: widget.outer, itemCount: widget.itemCount, @@ -567,13 +565,13 @@ class _SwiperState extends _SwiperTimerMixin { pageController: _pageController, activeIndex: _activeIndex, scrollDirection: widget.scrollDirection, - controller: _controller, + controller: _controller!, loop: widget.loop); return config; } - List _ensureListForStack( - Widget swiper, List listForStack, Widget widget) { + List? _ensureListForStack( + Widget swiper, List? listForStack, Widget widget) { if (listForStack == null) { listForStack = [swiper, widget]; } else { @@ -585,18 +583,18 @@ class _SwiperState extends _SwiperTimerMixin { @override Widget build(BuildContext context) { Widget swiper = _buildSwiper(); - List listForStack; - SwiperPluginConfig config; + List? listForStack; + SwiperPluginConfig? config; if (widget.control != null) { //Stack config = _ensureConfig(config); listForStack = _ensureListForStack( - swiper, listForStack, widget.control.build(context, config)); + swiper, listForStack, widget.control!.build(context, config)); } if (widget.plugins != null) { config = _ensureConfig(config); - for (SwiperPlugin plugin in widget.plugins) { + for (SwiperPlugin plugin in widget.plugins!) { listForStack = _ensureListForStack( swiper, listForStack, plugin.build(context, config)); } @@ -607,10 +605,10 @@ class _SwiperState extends _SwiperTimerMixin { return _buildOuterPagination( widget.pagination as SwiperPagination, listForStack == null ? swiper : Stack(children: listForStack), - config); + config!); } else { listForStack = _ensureListForStack( - swiper, listForStack, widget.pagination.build(context, config)); + swiper, listForStack, widget.pagination!.build(context, config)); } } @@ -647,20 +645,20 @@ class _SwiperState extends _SwiperTimerMixin { } abstract class _SubSwiper extends StatefulWidget { - final IndexedWidgetBuilder itemBuilder; - final int itemCount; - final int index; - final ValueChanged onIndexChanged; - final SwiperController controller; - final int duration; - final Curve curve; - final double itemWidth; - final double itemHeight; - final bool loop; - final Axis scrollDirection; + final IndexedWidgetBuilder? itemBuilder; + final int? itemCount; + final int? index; + final ValueChanged? onIndexChanged; + final SwiperController? controller; + final int? duration; + final Curve? curve; + final double? itemWidth; + final double? itemHeight; + final bool? loop; + final Axis? scrollDirection; const _SubSwiper( - {Key key, + {Key? key, this.loop, this.itemHeight, this.itemWidth, @@ -676,9 +674,9 @@ abstract class _SubSwiper extends StatefulWidget { int getCorrectIndex(int indexNeedsFix) { if (itemCount == 0) return 0; - int value = indexNeedsFix % itemCount; + int value = indexNeedsFix % itemCount!; if (value < 0) { - value += itemCount; + value += itemCount!; } return value; } @@ -686,18 +684,18 @@ abstract class _SubSwiper extends StatefulWidget { class _TinderSwiper extends _SubSwiper { const _TinderSwiper({ - Key key, - Curve curve, - int duration, - SwiperController controller, - ValueChanged onIndexChanged, - @required double itemHeight, - @required double itemWidth, - IndexedWidgetBuilder itemBuilder, - int index, - bool loop, - int itemCount, - Axis scrollDirection, + Key? key, + Curve? curve, + int? duration, + SwiperController? controller, + ValueChanged? onIndexChanged, + required double? itemHeight, + required double? itemWidth, + IndexedWidgetBuilder? itemBuilder, + int? index, + bool? loop, + int? itemCount, + Axis? scrollDirection, }) : assert(itemWidth != null && itemHeight != null), super( loop: loop, @@ -721,18 +719,18 @@ class _TinderSwiper extends _SubSwiper { class _StackSwiper extends _SubSwiper { const _StackSwiper({ - Key key, - Curve curve, - int duration, - SwiperController controller, - ValueChanged onIndexChanged, - double itemHeight, - double itemWidth, - IndexedWidgetBuilder itemBuilder, - int index, - bool loop, - int itemCount, - Axis scrollDirection, + Key? key, + Curve? curve, + int? duration, + SwiperController? controller, + ValueChanged? onIndexChanged, + double? itemHeight, + double? itemWidth, + IndexedWidgetBuilder? itemBuilder, + int? index, + bool? loop, + int? itemCount, + Axis? scrollDirection, }) : super( loop: loop, key: key, @@ -754,14 +752,14 @@ class _StackSwiper extends _SubSwiper { } class _TinderState extends _CustomLayoutStateBase<_TinderSwiper> { - List scales; - List offsetsX; - List offsetsY; - List opacity; - List rotates; + late List scales; + late List offsetsX; + late List offsetsY; + late List opacity; + late List rotates; double getOffsetY(double scale) { - return widget.itemHeight - widget.itemHeight * scale; + return widget.itemHeight! - widget.itemHeight! * scale; } @override @@ -814,11 +812,11 @@ class _TinderState extends _CustomLayoutStateBase<_TinderSwiper> { @override Widget _buildItem(int i, int realIndex, double animationValue) { - double s = _getValue(scales, animationValue, i); - double f = _getValue(offsetsX, animationValue, i); - double fy = _getValue(offsetsY, animationValue, i); - double o = _getValue(opacity, animationValue, i); - double a = _getValue(rotates, animationValue, i); + double s = _getValue(scales, animationValue, i)!; + double f = _getValue(offsetsX, animationValue, i)!; + double fy = _getValue(offsetsY, animationValue, i)!; + double o = _getValue(opacity, animationValue, i)!; + double a = _getValue(rotates, animationValue, i)!; Alignment alignment = widget.scrollDirection == Axis.horizontal ? Alignment.bottomCenter @@ -837,7 +835,7 @@ class _TinderState extends _CustomLayoutStateBase<_TinderSwiper> { child: SizedBox( width: widget.itemWidth ?? double.infinity, height: widget.itemHeight ?? double.infinity, - child: widget.itemBuilder(context, realIndex), + child: widget.itemBuilder!(context, realIndex), ), ), ), @@ -847,9 +845,9 @@ class _TinderState extends _CustomLayoutStateBase<_TinderSwiper> { } class _StackViewState extends _CustomLayoutStateBase<_StackSwiper> { - List scales; - List offsets; - List opacity; + late List scales; + late List offsets; + late List opacity; @override void didChangeDependencies() { super.didChangeDependencies(); @@ -857,10 +855,10 @@ class _StackViewState extends _CustomLayoutStateBase<_StackSwiper> { void _updateValues() { if (widget.scrollDirection == Axis.horizontal) { - double space = (_swiperWidth - widget.itemWidth) / 2; + double space = (_swiperWidth! - widget.itemWidth!) / 2; offsets = [-space, -space / 3 * 2, -space / 3, 0.0, _swiperWidth]; } else { - double space = (_swiperHeight - widget.itemHeight) / 2; + double space = (_swiperHeight! - widget.itemHeight!) / 2; offsets = [-space, -space / 3 * 2, -space / 3, 0.0, _swiperHeight]; } } @@ -888,13 +886,13 @@ class _StackViewState extends _CustomLayoutStateBase<_StackSwiper> { @override Widget _buildItem(int i, int realIndex, double animationValue) { - double s = _getValue(scales, animationValue, i); - double f = _getValue(offsets, animationValue, i); - double o = _getValue(opacity, animationValue, i); + double s = _getValue(scales, animationValue, i)!; + double? f = _getValue(offsets, animationValue, i); + double o = _getValue(opacity, animationValue, i)!; Offset offset = widget.scrollDirection == Axis.horizontal - ? Offset(f, 0.0) - : Offset(0.0, f); + ? Offset(f!, 0.0) + : Offset(0.0, f!); Alignment alignment = widget.scrollDirection == Axis.horizontal ? Alignment.centerLeft @@ -911,7 +909,7 @@ class _StackViewState extends _CustomLayoutStateBase<_StackSwiper> { child: SizedBox( width: widget.itemWidth ?? double.infinity, height: widget.itemHeight ?? double.infinity, - child: widget.itemBuilder(context, realIndex), + child: widget.itemBuilder!(context, realIndex), ), ), ), @@ -920,21 +918,21 @@ class _StackViewState extends _CustomLayoutStateBase<_StackSwiper> { } class ScaleAndFadeTransformer extends PageTransformer { - final double _scale; - final double _fade; + final double? _scale; + final double? _fade; - ScaleAndFadeTransformer({double fade = 0.3, double scale = 0.8}) + ScaleAndFadeTransformer({double? fade = 0.3, double? scale = 0.8}) : _fade = fade, _scale = scale; @override // ignore: avoid_renaming_method_parameters Widget transform(Widget item, TransformInfo info) { - double position = info.position; + double? position = info.position; Widget child = item; if (_scale != null) { - double scaleFactor = (1 - position.abs()) * (1 - _scale); - double scale = _scale + scaleFactor; + double scaleFactor = (1 - position!.abs()) * (1 - _scale!); + double scale = _scale! + scaleFactor; child = Transform.scale( scale: scale, @@ -943,8 +941,8 @@ class ScaleAndFadeTransformer extends PageTransformer { } if (_fade != null) { - double fadeFactor = (1 - position.abs()) * (1 - _fade); - double opacity = _fade + fadeFactor; + double fadeFactor = (1 - position!.abs()) * (1 - _fade!); + double opacity = _fade! + fadeFactor; child = Opacity( opacity: opacity, child: child, @@ -966,15 +964,15 @@ class SwiperControl extends SwiperPlugin { final double size; ///Icon normal color, The theme's [ThemeData.primaryColor] by default. - final Color color; + final Color? color; ///if set loop=false on Swiper, this color will be used when swiper goto the last slide. ///The theme's [ThemeData.disabledColor] by default. - final Color disableColor; + final Color? disableColor; final EdgeInsetsGeometry padding; - final Key key; + final Key? key; const SwiperControl( {this.iconPrevious = Icons.arrow_back_ios, @@ -985,15 +983,15 @@ class SwiperControl extends SwiperPlugin { this.size = 30.0, this.padding = const EdgeInsets.all(5.0)}); - Widget buildButton(SwiperPluginConfig config, Color color, IconData iconDaga, + Widget buildButton(SwiperPluginConfig? config, Color color, IconData iconDaga, int quarterTurns, bool previous) { return GestureDetector( behavior: HitTestBehavior.opaque, onTap: () { if (previous) { - config.controller.previous(animation: true); + config!.controller.previous(animation: true); } else { - config.controller.next(animation: true); + config!.controller.next(animation: true); } }, child: Padding( @@ -1010,7 +1008,7 @@ class SwiperControl extends SwiperPlugin { } @override - Widget build(BuildContext context, SwiperPluginConfig config) { + Widget build(BuildContext context, SwiperPluginConfig? config) { ThemeData themeData = Theme.of(context); Color color = this.color ?? themeData.primaryColor; @@ -1018,11 +1016,11 @@ class SwiperControl extends SwiperPlugin { Color prevColor; Color nextColor; - if (config.loop) { + if (config!.loop!) { prevColor = nextColor = color; } else { - bool next = config.activeIndex < config.itemCount - 1; - bool prev = config.activeIndex > 0; + bool next = config.activeIndex! < config.itemCount! - 1; + bool prev = config.activeIndex! > 0; prevColor = prev ? color : disableColor; nextColor = next ? color : disableColor; } @@ -1071,17 +1069,17 @@ class SwiperController extends IndexController { static const int BUILD = 5; // available when `event` == SwiperController.BUILD - SwiperPluginConfig config; + SwiperPluginConfig? config; // available when `event` == SwiperController.SWIPE // this value is PageViewController.pos - double pos; + double? pos; // ignore: overridden_fields, annotate_overrides - int index; + int? index; // ignore: overridden_fields, annotate_overrides - bool animation; - bool autoplay; + bool? animation; + bool? autoplay; SwiperController(); @@ -1100,10 +1098,10 @@ class SwiperController extends IndexController { class FractionPaginationBuilder extends SwiperPlugin { ///color ,if set null , will be Theme.of(context).scaffoldBackgroundColor - final Color color; + final Color? color; ///color when active,if set null , will be Theme.of(context).primaryColor - final Color activeColor; + final Color? activeColor; ////font size final double fontSize; @@ -1111,7 +1109,7 @@ class FractionPaginationBuilder extends SwiperPlugin { ///font size when active final double activeFontSize; - final Key key; + final Key? key; const FractionPaginationBuilder( {this.color, @@ -1121,18 +1119,18 @@ class FractionPaginationBuilder extends SwiperPlugin { this.activeFontSize = 35.0}); @override - Widget build(BuildContext context, SwiperPluginConfig config) { + Widget build(BuildContext context, SwiperPluginConfig? config) { ThemeData themeData = Theme.of(context); Color activeColor = this.activeColor ?? themeData.primaryColor; Color color = this.color ?? themeData.scaffoldBackgroundColor; - if (Axis.vertical == config.scrollDirection) { + if (Axis.vertical == config!.scrollDirection) { return Column( key: key, mainAxisSize: MainAxisSize.min, children: [ Text( - "${config.activeIndex + 1}", + "${config.activeIndex! + 1}", style: TextStyle(color: activeColor, fontSize: activeFontSize), ), Text( @@ -1151,7 +1149,7 @@ class FractionPaginationBuilder extends SwiperPlugin { mainAxisSize: MainAxisSize.min, children: [ Text( - "${config.activeIndex + 1}", + "${config.activeIndex! + 1}", style: TextStyle(color: activeColor, fontSize: activeFontSize), ), Text( @@ -1166,10 +1164,10 @@ class FractionPaginationBuilder extends SwiperPlugin { class RectSwiperPaginationBuilder extends SwiperPlugin { ///color when current index,if set null , will be Theme.of(context).primaryColor - final Color activeColor; + final Color? activeColor; ///,if set null , will be Theme.of(context).scaffoldBackgroundColor - final Color color; + final Color? color; ///Size of the rect when activate final Size activeSize; @@ -1180,7 +1178,7 @@ class RectSwiperPaginationBuilder extends SwiperPlugin { /// Space between rects final double space; - final Key key; + final Key? key; const RectSwiperPaginationBuilder( {this.activeColor, @@ -1191,21 +1189,21 @@ class RectSwiperPaginationBuilder extends SwiperPlugin { this.space = 3.0}); @override - Widget build(BuildContext context, SwiperPluginConfig config) { + Widget build(BuildContext context, SwiperPluginConfig? config) { ThemeData themeData = Theme.of(context); Color activeColor = this.activeColor ?? themeData.primaryColor; Color color = this.color ?? themeData.scaffoldBackgroundColor; List list = []; - if (config.itemCount > 20) { + if (config!.itemCount! > 20) { // ignore: avoid_print print( "The itemCount is too big, we suggest use FractionPaginationBuilder instead of DotSwiperPaginationBuilder in this sitituation"); } - int itemCount = config.itemCount; - int activeIndex = config.activeIndex; + int itemCount = config.itemCount!; + int? activeIndex = config.activeIndex; for (int i = 0; i < itemCount; ++i) { bool active = i == activeIndex; @@ -1239,10 +1237,10 @@ class RectSwiperPaginationBuilder extends SwiperPlugin { class DotSwiperPaginationBuilder extends SwiperPlugin { ///color when current index,if set null , will be Theme.of(context).primaryColor - final Color activeColor; + final Color? activeColor; ///,if set null , will be Theme.of(context).scaffoldBackgroundColor - final Color color; + final Color? color; ///Size of the dot when activate final double activeSize; @@ -1253,7 +1251,7 @@ class DotSwiperPaginationBuilder extends SwiperPlugin { /// Space between dots final double space; - final Key key; + final Key? key; const DotSwiperPaginationBuilder( {this.activeColor, @@ -1264,14 +1262,14 @@ class DotSwiperPaginationBuilder extends SwiperPlugin { this.space = 3.0}); @override - Widget build(BuildContext context, SwiperPluginConfig config) { - if (config.itemCount > 20) { + Widget build(BuildContext context, SwiperPluginConfig? config) { + if (config!.itemCount! > 20) { // ignore: avoid_print print( "The itemCount is too big, we suggest use FractionPaginationBuilder instead of DotSwiperPaginationBuilder in this sitituation"); } - Color activeColor = this.activeColor; - Color color = this.color; + Color? activeColor = this.activeColor; + Color? color = this.color; if (activeColor == null || color == null) { ThemeData themeData = Theme.of(context); @@ -1282,8 +1280,8 @@ class DotSwiperPaginationBuilder extends SwiperPlugin { if (config.indicatorLayout != PageIndicatorLayout.NONE && config.layout == SwiperLayout.DEFAULT) { return PageIndicator( - count: config.itemCount, - controller: config.pageController, + count: config.itemCount!, + controller: config.pageController!, layout: config.indicatorLayout, size: size, activeColor: activeColor, @@ -1294,8 +1292,8 @@ class DotSwiperPaginationBuilder extends SwiperPlugin { List list = []; - int itemCount = config.itemCount; - int activeIndex = config.activeIndex; + int itemCount = config.itemCount!; + int? activeIndex = config.activeIndex; for (int i = 0; i < itemCount; ++i) { bool active = i == activeIndex; @@ -1329,15 +1327,15 @@ class DotSwiperPaginationBuilder extends SwiperPlugin { } typedef SwiperPaginationBuilder = Widget Function( - BuildContext context, SwiperPluginConfig config); + BuildContext context, SwiperPluginConfig? config); class SwiperCustomPagination extends SwiperPlugin { final SwiperPaginationBuilder builder; - SwiperCustomPagination({@required this.builder}) : assert(builder != null); + SwiperCustomPagination({required this.builder}); @override - Widget build(BuildContext context, SwiperPluginConfig config) { + Widget build(BuildContext context, SwiperPluginConfig? config) { return builder(context, config); } } @@ -1353,7 +1351,7 @@ class SwiperPagination extends SwiperPlugin { /// Alignment.bottomCenter by default when scrollDirection== Axis.horizontal /// Alignment.centerRight by default when scrollDirection== Axis.vertical - final Alignment alignment; + final Alignment? alignment; /// Distance between pagination and the container final EdgeInsetsGeometry margin; @@ -1361,7 +1359,7 @@ class SwiperPagination extends SwiperPlugin { /// Build the widet final SwiperPlugin builder; - final Key key; + final Key? key; const SwiperPagination( {this.alignment, @@ -1370,16 +1368,16 @@ class SwiperPagination extends SwiperPlugin { this.builder = SwiperPagination.dots}); @override - Widget build(BuildContext context, SwiperPluginConfig config) { + Widget build(BuildContext context, SwiperPluginConfig? config) { Alignment alignment = this.alignment ?? - (config.scrollDirection == Axis.horizontal + (config!.scrollDirection == Axis.horizontal ? Alignment.bottomCenter : Alignment.centerRight); Widget child = Container( margin: margin, child: builder.build(context, config), ); - if (!config.outer) { + if (!config!.outer!) { child = Align( key: key, alignment: alignment, @@ -1395,32 +1393,30 @@ class SwiperPagination extends SwiperPlugin { abstract class SwiperPlugin { const SwiperPlugin(); - Widget build(BuildContext context, SwiperPluginConfig config); + Widget build(BuildContext context, SwiperPluginConfig? config); } class SwiperPluginConfig { - final int activeIndex; - final int itemCount; - final PageIndicatorLayout indicatorLayout; + final int? activeIndex; + final int? itemCount; + final PageIndicatorLayout? indicatorLayout; final Axis scrollDirection; - final bool loop; - final bool outer; - final PageController pageController; + final bool? loop; + final bool? outer; + final PageController? pageController; final SwiperController controller; - final SwiperLayout layout; + final SwiperLayout? layout; const SwiperPluginConfig( {this.activeIndex, this.itemCount, this.indicatorLayout, this.outer, - @required this.scrollDirection, - @required this.controller, + required this.scrollDirection, + required this.controller, this.pageController, this.layout, - this.loop}) - : assert(scrollDirection != null), - assert(controller != null); + this.loop}); } class SwiperPluginView extends StatelessWidget { @@ -1437,12 +1433,12 @@ class SwiperPluginView extends StatelessWidget { abstract class _CustomLayoutStateBase extends State with SingleTickerProviderStateMixin { - double _swiperWidth; - double _swiperHeight; - Animation _animation; - AnimationController _animationController; - int _startIndex; - int _animationCount; + double? _swiperWidth; + double? _swiperHeight; + late Animation _animation; + AnimationController? _animationController; + late int _startIndex; + int? _animationCount; @override void initState() { @@ -1452,19 +1448,19 @@ abstract class _CustomLayoutStateBase extends State } _createAnimationController(); - widget.controller.addListener(_onController); + widget.controller!.addListener(_onController); super.initState(); } void _createAnimationController() { _animationController = AnimationController(vsync: this, value: 0.5); Tween tween = Tween(begin: 0.0, end: 1.0); - _animation = tween.animate(_animationController); + _animation = tween.animate(_animationController!); } @override void didChangeDependencies() { - WidgetsBinding.instance.addPostFrameCallback(_getSize); + WidgetsBinding.instance!.addPostFrameCallback(_getSize); super.didChangeDependencies(); } @@ -1474,7 +1470,7 @@ abstract class _CustomLayoutStateBase extends State @mustCallSuper void afterRender() { - RenderObject renderObject = context.findRenderObject(); + RenderObject renderObject = context.findRenderObject()!; Size size = renderObject.paintBounds.size; _swiperWidth = size.width; _swiperHeight = size.height; @@ -1484,12 +1480,12 @@ abstract class _CustomLayoutStateBase extends State @override void didUpdateWidget(T oldWidget) { if (widget.controller != oldWidget.controller) { - oldWidget.controller.removeListener(_onController); - widget.controller.addListener(_onController); + oldWidget.controller!.removeListener(_onController); + widget.controller!.addListener(_onController); } if (widget.loop != oldWidget.loop) { - if (!widget.loop) { + if (!widget.loop!) { _currentIndex = _ensureIndex(_currentIndex); } } @@ -1498,16 +1494,16 @@ abstract class _CustomLayoutStateBase extends State } int _ensureIndex(int index) { - index = index % widget.itemCount; + index = index % widget.itemCount!; if (index < 0) { - index += widget.itemCount; + index += widget.itemCount!; } return index; } @override void dispose() { - widget.controller.removeListener(_onController); + widget.controller!.removeListener(_onController); _animationController?.dispose(); super.dispose(); } @@ -1520,16 +1516,16 @@ abstract class _CustomLayoutStateBase extends State ); } - Widget _buildAnimation(BuildContext context, Widget w) { + Widget _buildAnimation(BuildContext context, Widget? w) { List list = []; double animationValue = _animation.value; - for (int i = 0; i < _animationCount; ++i) { + for (int i = 0; i < _animationCount!; ++i) { int realIndex = _currentIndex + i + _startIndex; - realIndex = realIndex % widget.itemCount; + realIndex = realIndex % widget.itemCount!; if (realIndex < 0) { - realIndex += widget.itemCount; + realIndex += widget.itemCount!; } list.add(_buildItem(i, realIndex, animationValue)); @@ -1554,23 +1550,23 @@ abstract class _CustomLayoutStateBase extends State return Container(); } return AnimatedBuilder( - animation: _animationController, builder: _buildAnimation); + animation: _animationController!, builder: _buildAnimation); } - double _currentValue; - double _currentPos; + late double _currentValue; + late double _currentPos; bool _lockScroll = false; - Future _move(double position, {int nextIndex}) async { + Future _move(double position, {int? nextIndex}) async { if (_lockScroll) return; try { _lockScroll = true; - await _animationController.animateTo(position, - duration: Duration(milliseconds: widget.duration), - curve: widget.curve); + await _animationController!.animateTo(position, + duration: Duration(milliseconds: widget.duration!), + curve: widget.curve!); if (nextIndex != null) { - widget.onIndexChanged(widget.getCorrectIndex(nextIndex)); + widget.onIndexChanged!(widget.getCorrectIndex(nextIndex)); } } catch (e) { // ignore: avoid_print @@ -1578,7 +1574,7 @@ abstract class _CustomLayoutStateBase extends State } finally { if (nextIndex != null) { try { - _animationController.value = 0.5; + _animationController!.value = 0.5; } catch (e) { // ignore: avoid_print print(e); @@ -1592,22 +1588,22 @@ abstract class _CustomLayoutStateBase extends State int _nextIndex() { int index = _currentIndex + 1; - if (!widget.loop && index >= widget.itemCount - 1) { - return widget.itemCount - 1; + if (!widget.loop! && index >= widget.itemCount! - 1) { + return widget.itemCount! - 1; } return index; } int _prevIndex() { int index = _currentIndex - 1; - if (!widget.loop && index < 0) { + if (!widget.loop! && index < 0) { return 0; } return index; } void _onController() { - switch (widget.controller.event) { + switch (widget.controller!.event) { case IndexController.PREVIOUS: int prevIndex = _prevIndex(); if (prevIndex == _currentIndex) return; @@ -1634,13 +1630,13 @@ abstract class _CustomLayoutStateBase extends State ? details.velocity.pixelsPerSecond.dx : details.velocity.pixelsPerSecond.dy; - if (_animationController.value >= 0.75 || velocity > 500.0) { - if (_currentIndex <= 0 && !widget.loop) { + if (_animationController!.value >= 0.75 || velocity > 500.0) { + if (_currentIndex <= 0 && !widget.loop!) { return; } _move(1.0, nextIndex: _currentIndex - 1); - } else if (_animationController.value < 0.25 || velocity < -500.0) { - if (_currentIndex >= widget.itemCount - 1 && !widget.loop) { + } else if (_animationController!.value < 0.25 || velocity < -500.0) { + if (_currentIndex >= widget.itemCount! - 1 && !widget.loop!) { return; } _move(0.0, nextIndex: _currentIndex + 1); @@ -1651,7 +1647,7 @@ abstract class _CustomLayoutStateBase extends State void _onPanStart(DragStartDetails details) { if (_lockScroll) return; - _currentValue = _animationController.value; + _currentValue = _animationController!.value; _currentPos = widget.scrollDirection == Axis.horizontal ? details.globalPosition.dx : details.globalPosition.dy; @@ -1664,11 +1660,11 @@ abstract class _CustomLayoutStateBase extends State ? details.globalPosition.dx : details.globalPosition.dy) - _currentPos) / - _swiperWidth / + _swiperWidth! / 2; // no loop ? - if (!widget.loop) { - if (_currentIndex >= widget.itemCount - 1) { + if (!widget.loop!) { + if (_currentIndex >= widget.itemCount! - 1) { if (value < 0.5) { value = 0.5; } @@ -1679,21 +1675,21 @@ abstract class _CustomLayoutStateBase extends State } } - _animationController.value = value; + _animationController!.value = value; } int _currentIndex = 0; } -double _getValue(List values, double animationValue, int index) { - double s = values[index]; +double? _getValue(List values, double animationValue, int index) { + double? s = values[index]; if (animationValue >= 0.5) { if (index < values.length - 1) { - s = s + (values[index + 1] - s) * (animationValue - 0.5) * 2.0; + s = s! + (values[index + 1]! - s) * (animationValue - 0.5) * 2.0; } } else { if (index != 0) { - s = s - (s - values[index - 1]) * (0.5 - animationValue) * 2.0; + s = s! - (s - values[index - 1]!) * (0.5 - animationValue) * 2.0; } } return s; @@ -1718,7 +1714,7 @@ Offset _getOffsetValue(List values, double animationValue, int index) { } abstract class TransformBuilder { - List values; + List? values; TransformBuilder({this.values}); Widget build(int i, double animationValue, Widget widget); } @@ -1726,22 +1722,22 @@ abstract class TransformBuilder { class ScaleTransformBuilder extends TransformBuilder { final Alignment alignment; ScaleTransformBuilder( - {List values, this.alignment = Alignment.center}) + {List? values, this.alignment = Alignment.center}) : super(values: values); @override Widget build(int i, double animationValue, Widget widget) { - double s = _getValue(values, animationValue, i); + double s = _getValue(values!, animationValue, i)!; return Transform.scale(scale: s, child: widget); } } class OpacityTransformBuilder extends TransformBuilder { - OpacityTransformBuilder({List values}) : super(values: values); + OpacityTransformBuilder({List? values}) : super(values: values); @override Widget build(int i, double animationValue, Widget widget) { - double v = _getValue(values, animationValue, i); + double v = _getValue(values!, animationValue, i)!; return Opacity( opacity: v, child: widget, @@ -1750,11 +1746,11 @@ class OpacityTransformBuilder extends TransformBuilder { } class RotateTransformBuilder extends TransformBuilder { - RotateTransformBuilder({List values}) : super(values: values); + RotateTransformBuilder({List? values}) : super(values: values); @override Widget build(int i, double animationValue, Widget widget) { - double v = _getValue(values, animationValue, i); + double v = _getValue(values!, animationValue, i)!; return Transform.rotate( angle: v, child: widget, @@ -1763,11 +1759,11 @@ class RotateTransformBuilder extends TransformBuilder { } class TranslateTransformBuilder extends TransformBuilder { - TranslateTransformBuilder({List values}) : super(values: values); + TranslateTransformBuilder({List? values}) : super(values: values); @override Widget build(int i, double animationValue, Widget widget) { - Offset s = _getOffsetValue(values, animationValue, i); + Offset s = _getOffsetValue(values!, animationValue, i); return Transform.translate( offset: s, child: widget, @@ -1778,10 +1774,9 @@ class TranslateTransformBuilder extends TransformBuilder { class CustomLayoutOption { final List builders = []; final int startIndex; - final int stateCount; + final int? stateCount; - CustomLayoutOption({this.stateCount, @required this.startIndex}) - : assert(startIndex != null, stateCount != null); + CustomLayoutOption({this.stateCount, required this.startIndex}); CustomLayoutOption addOpacity(List values) { builders.add(OpacityTransformBuilder(values: values)); @@ -1808,21 +1803,20 @@ class _CustomLayoutSwiper extends _SubSwiper { final CustomLayoutOption option; const _CustomLayoutSwiper( - {@required this.option, - double itemWidth, - bool loop, - double itemHeight, - ValueChanged onIndexChanged, - Key key, - IndexedWidgetBuilder itemBuilder, - Curve curve, - int duration, - int index, - int itemCount, - Axis scrollDirection, - SwiperController controller}) - : assert(option != null), - super( + {required this.option, + double? itemWidth, + bool? loop, + double? itemHeight, + ValueChanged? onIndexChanged, + Key? key, + IndexedWidgetBuilder? itemBuilder, + Curve? curve, + int? duration, + int? index, + int? itemCount, + Axis? scrollDirection, + SwiperController? controller}) + : super( loop: loop, onIndexChanged: onIndexChanged, itemWidth: itemWidth, @@ -1864,7 +1858,7 @@ class _CustomLayoutState extends _CustomLayoutStateBase<_CustomLayoutSwiper> { Widget child = SizedBox( width: widget.itemWidth ?? double.infinity, height: widget.itemHeight ?? double.infinity, - child: widget.itemBuilder(context, realIndex)); + child: widget.itemBuilder!(context, realIndex)); for (int i = builders.length - 1; i >= 0; --i) { TransformBuilder builder = builders[i]; diff --git a/web/filipino_cuisine/lib/main.dart b/web/filipino_cuisine/lib/main.dart index 4cb26058d..2876cf847 100644 --- a/web/filipino_cuisine/lib/main.dart +++ b/web/filipino_cuisine/lib/main.dart @@ -32,8 +32,8 @@ class Home extends StatefulWidget { } class HState extends State { - Map fd; - Map fi; + Map? fd; + Map? fi; @override void initState() { @@ -42,10 +42,10 @@ class HState extends State { } Future getData() async { - http.Response r = await http.get( - 'https://flutter.github.io/samples/web/filipino_cuisine/data.json'); - fd = json.decode(r.body) as Map; - setState(() => fi = fd['0'] as Map); + http.Response r = await http.get(Uri.parse( + 'https://flutter.github.io/samples/web/filipino_cuisine/data.json')); + fd = json.decode(r.body) as Map?; + setState(() => fi = fd!['0'] as Map?); } @override @@ -66,58 +66,59 @@ class HState extends State { flex: 5, child: Swiper( onIndexChanged: (n) => - setState(() => fi = fd['$n'] as Map), + setState(() => fi = fd!['$n'] as Map?), itemCount: - fd.keys.where((key) => int.tryParse(key) != null).length, + fd!.keys.where((key) => int.tryParse(key) != null).length, itemBuilder: (cx, i) { return Container( margin: const EdgeInsets.only(top: 40, bottom: 24), child: ClipRRect( borderRadius: BorderRadius.circular(20), child: Hero( - tag: fd['$i']['fn'], - child: Image.asset(fd['$i']['pf'] as String, + tag: fd!['$i']['fn'] as Object, + child: Image.asset(fd!['$i']['pf'] as String, fit: BoxFit.cover)), )); }, viewportFraction: .85, scale: .9)), - Text(fi['fn'] as String, - style: - t.headline2.copyWith(fontFamily: 'ark', color: Colors.black)), + Text(fi!['fn'] as String, + style: t.headline2! + .copyWith(fontFamily: 'ark', color: Colors.black)), Container( - child: Text(fi['cn'] as String, - style: t.subtitle1.apply(color: Colors.red, fontFamily: 'opb')), + child: Text(fi!['cn'] as String, + style: + t.subtitle1!.apply(color: Colors.red, fontFamily: 'opb')), margin: const EdgeInsets.only(top: 10, bottom: 30), ), Container( - child: Text(fi['dc'] as String, + child: Text(fi!['dc'] as String, textAlign: TextAlign.center, - style: t.subtitle1.copyWith(fontFamily: 'opr')), + style: t.subtitle1!.copyWith(fontFamily: 'opr')), margin: const EdgeInsets.only(left: 10, right: 10)), Expanded( flex: 2, child: ListView.builder( scrollDirection: Axis.horizontal, - itemCount: fi['ig'].length as int, + itemCount: fi!['ig'].length as int?, itemBuilder: (cx, i) { return Row(children: [ Container( margin: const EdgeInsets.only(left: 10), height: 60, - child: Image.asset(fi['ig'][i]['p'] as String, + child: Image.asset(fi!['ig'][i]['p'] as String, fit: BoxFit.contain)), Container( margin: const EdgeInsets.only(left: 5, right: 10), child: Column( mainAxisAlignment: MainAxisAlignment.center, children: [ - Text(fi['ig'][i]['n'] as String, - style: t.subtitle2 + Text(fi!['ig'][i]['n'] as String, + style: t.subtitle2! .copyWith(fontFamily: 'opb')), - Text(fi['ig'][i]['c'] as String, + Text(fi!['ig'][i]['c'] as String, style: - t.caption.copyWith(fontFamily: 'opr')) + t.caption!.copyWith(fontFamily: 'opr')) ])) ]); })) @@ -130,9 +131,9 @@ class HState extends State { context, MaterialPageRoute( builder: (cx) => Cook( - (fi['in'] as List).cast(), - fi['pf'] as String, - fi['fn'] as String, + (fi!['in'] as List).cast(), + fi!['pf'] as String?, + fi!['fn'] as String?, ))), ), bottomNavigationBar: BottomAppBar( @@ -142,11 +143,11 @@ class HState extends State { mainAxisAlignment: MainAxisAlignment.spaceAround, children: [ IconButton( - icon: Icon(fi['fv'] as bool + icon: Icon(fi!['fv'] as bool ? Icons.favorite : Icons.favorite_border), onPressed: () => - setState(() => fi['fv'] = !(fi['fv'] as bool))), + setState(() => fi!['fv'] = !(fi!['fv'] as bool))), IconButton(icon: const Icon(Icons.share), onPressed: () {}) ])), ); diff --git a/web/filipino_cuisine/lib/transformer_page_view.dart b/web/filipino_cuisine/lib/transformer_page_view.dart index 4ce370a77..e697ddbcb 100644 --- a/web/filipino_cuisine/lib/transformer_page_view.dart +++ b/web/filipino_cuisine/lib/transformer_page_view.dart @@ -14,13 +14,13 @@ class IndexController extends ChangeNotifier { // ignore: constant_identifier_names static const int MOVE = 0; - Completer _completer; + late Completer _completer; - int index; - bool animation; - int event; + int? index; + bool? animation; + int? event; - Future move(int index, {bool animation = true}) { + Future move(int index, {bool? animation = true}) { this.animation = animation ?? true; this.index = index; event = MOVE; @@ -29,7 +29,7 @@ class IndexController extends ChangeNotifier { return _completer.future; } - Future next({bool animation = true}) { + Future next({bool? animation = true}) { event = NEXT; this.animation = animation ?? true; _completer = Completer(); @@ -37,7 +37,7 @@ class IndexController extends ChangeNotifier { return _completer.future; } - Future previous({bool animation = true}) { + Future previous({bool? animation = true}) { event = PREVIOUS; this.animation = animation ?? true; _completer = Completer(); @@ -63,22 +63,22 @@ class ColorPainter extends CustomPainter { @override void paint(Canvas canvas, Size size) { - int index = info.fromIndex; + int index = info.fromIndex!; _paint.color = colors[index]; canvas.drawRect(Rect.fromLTWH(0.0, 0.0, size.width, size.height), _paint); - if (info.done) { + if (info.done!) { return; } int alpha; int color; double opacity; - double position = info.position; - if (info.forward) { + double? position = info.position; + if (info.forward!) { if (index < colors.length - 1) { color = colors[index + 1].value & 0x00ffffff; - opacity = (position <= 0 - ? (-position / info.viewportFraction) - : 1 - position / info.viewportFraction); + opacity = (position! <= 0 + ? (-position / info.viewportFraction!) + : 1 - position / info.viewportFraction!); if (opacity > 1) { opacity -= 1.0; } @@ -94,9 +94,9 @@ class ColorPainter extends CustomPainter { } else { if (index > 0) { color = colors[index - 1].value & 0x00ffffff; - opacity = (position > 0 - ? position / info.viewportFraction - : (1 + position / info.viewportFraction)); + opacity = (position! > 0 + ? position / info.viewportFraction! + : (1 + position / info.viewportFraction!)); if (opacity > 1) { opacity -= 1.0; } @@ -138,9 +138,9 @@ class ParallaxColor extends StatefulWidget { final TransformInfo info; const ParallaxColor({ - @required this.colors, - @required this.info, - @required this.child, + required this.colors, + required this.info, + required this.child, }); @override @@ -156,17 +156,15 @@ class ParallaxContainer extends StatelessWidget { final double opacityFactor; const ParallaxContainer( - {@required this.child, - @required this.position, + {required this.child, + required this.position, this.translationFactor = 100.0, - this.opacityFactor = 1.0}) - : assert(position != null), - assert(translationFactor != null); + this.opacityFactor = 1.0}); @override Widget build(BuildContext context) { 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( offset: Offset(position * translationFactor, 0.0), child: child, @@ -179,9 +177,9 @@ class ParallaxImage extends StatelessWidget { final Image image; final double imageFactor; - ParallaxImage.asset(String name, {double position, this.imageFactor = 0.3}) - : assert(imageFactor != null), - image = Image.asset(name, + ParallaxImage.asset(String name, + {required double position, this.imageFactor = 0.3}) + : image = Image.asset(name, fit: BoxFit.cover, alignment: FractionalOffset( 0.5 + position * imageFactor, @@ -211,10 +209,10 @@ const int kDefaultTransactionDuration = 300; class TransformInfo { /// The `width` of the `TransformerPageView` - final double width; + final double? width; /// The `height` of the `TransformerPageView` - final double height; + final double? height; /// The `position` of the widget pass to [PageTransformer.transform] /// 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 /// /// - final double position; + final double? position; /// The `index` of the widget pass to [PageTransformer.transform] - final int index; + final int? index; /// The `activeIndex` of the PageView - final int activeIndex; + final int? activeIndex; /// The `activeIndex` of the PageView, from user start to swipe /// It will change when user end drag - final int fromIndex; + final int? fromIndex; /// Next `index` is greater than this `index` - final bool forward; + final bool? forward; /// User drag is done. - final bool done; + final bool? done; /// Same as [TransformerPageView.viewportFraction] - final double viewportFraction; + final double? viewportFraction; /// Copy from [TransformerPageView.scrollDirection] - final Axis scrollDirection; + final Axis? scrollDirection; TransformInfo( {this.index, @@ -276,9 +274,8 @@ typedef PageTransformerBuilderCallback = Widget Function( class PageTransformerBuilder extends PageTransformer { final PageTransformerBuilderCallback builder; - PageTransformerBuilder({bool reverse = false, @required this.builder}) - : assert(builder != null), - super(reverse: reverse); + PageTransformerBuilder({bool reverse = false, required this.builder}) + : super(reverse: reverse); @override Widget transform(Widget child, TransformInfo info) { @@ -288,11 +285,11 @@ class PageTransformerBuilder extends PageTransformer { class TransformerPageController extends PageController { final bool loop; - final int itemCount; + final int? itemCount; final bool reverse; TransformerPageController({ - int initialPage = 0, + int? initialPage = 0, bool keepPage = true, double viewportFraction = 1.0, this.loop = false, @@ -300,26 +297,26 @@ class TransformerPageController extends PageController { this.reverse = false, }) : super( initialPage: TransformerPageController._getRealIndexFromRenderIndex( - initialPage ?? 0, loop, itemCount, reverse), + initialPage ?? 0, loop, itemCount, reverse)!, keepPage: keepPage, viewportFraction: viewportFraction); - int getRenderIndexFromRealIndex(int index) { + int getRenderIndexFromRealIndex(int? index) { return _getRenderIndexFromRealIndex(index, loop, itemCount, reverse); } - int getRealItemCount() { + int? getRealItemCount() { if (itemCount == 0) return 0; - return loop ? itemCount + kMaxValue : itemCount; + return loop ? itemCount! + kMaxValue : itemCount; } static int _getRenderIndexFromRealIndex( - int index, bool loop, int itemCount, bool reverse) { + int? index, bool loop, int? itemCount, bool reverse) { if (itemCount == 0) return 0; - int renderIndex; + int? renderIndex; if (loop) { - renderIndex = index - kMiddleValue; - renderIndex = renderIndex % itemCount; + renderIndex = index! - kMiddleValue; + renderIndex = renderIndex % itemCount!; if (renderIndex < 0) { renderIndex += itemCount; } @@ -327,29 +324,26 @@ class TransformerPageController extends PageController { renderIndex = index; } if (reverse) { - renderIndex = itemCount - renderIndex - 1; + renderIndex = itemCount! - renderIndex! - 1; } - return renderIndex; + return renderIndex!; } - double get realPage { - double page; - if (position.maxScrollExtent == null || position.minScrollExtent == null) { - page = 0.0; - } else { - page = super.page; - } + double? get realPage { + double? page; + + page = super.page; return page; } static double _getRenderPageFromRealPage( - double page, bool loop, int itemCount, bool reverse) { - double renderPage; + double? page, bool loop, int? itemCount, bool reverse) { + double? renderPage; if (loop) { - renderPage = page - kMiddleValue; - renderPage = renderPage % itemCount; + renderPage = page! - kMiddleValue; + renderPage = renderPage % itemCount!; if (renderPage < 0) { renderPage += itemCount; } @@ -357,28 +351,28 @@ class TransformerPageController extends PageController { renderPage = page; } if (reverse) { - renderPage = itemCount - renderPage - 1; + renderPage = itemCount! - renderPage! - 1; } - return renderPage; + return renderPage!; } @override - double get page { + double? get page { return loop ? _getRenderPageFromRealPage(realPage, loop, itemCount, reverse) : realPage; } - int getRealIndexFromRenderIndex(int index) { + int? getRealIndexFromRenderIndex(int? index) { return _getRealIndexFromRenderIndex(index, loop, itemCount, reverse); } - static int _getRealIndexFromRenderIndex( - int index, bool loop, int itemCount, bool reverse) { - int result = reverse ? (itemCount - index - 1) : index; + static int? _getRealIndexFromRenderIndex( + int? index, bool loop, int? itemCount, bool reverse) { + int? result = reverse ? (itemCount! - index! - 1) : index; if (loop) { - result += kMiddleValue; + result = result! + kMiddleValue; } 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]. /// See [TransformInfo] /// - final PageTransformer transformer; + final PageTransformer? transformer; /// Same as [PageView.scrollDirection] /// @@ -396,7 +390,7 @@ class TransformerPageView extends StatefulWidget { final Axis scrollDirection; /// Same as [PageView.physics] - final ScrollPhysics physics; + final ScrollPhysics? physics; /// Set to false to disable page snapping, useful for custom scroll behavior. /// Same as [PageView.pageSnapping] @@ -404,20 +398,20 @@ class TransformerPageView extends StatefulWidget { /// Called whenever the page in the center of the viewport changes. /// Same as [PageView.onPageChanged] - final ValueChanged onPageChanged; + final ValueChanged? onPageChanged; - final IndexedWidgetBuilder itemBuilder; + final IndexedWidgetBuilder? itemBuilder; // See [IndexController.mode],[IndexController.next],[IndexController.previous] - final IndexController controller; + final IndexController? controller; /// Animation duration final Duration duration; /// Animation curve - final Curve curve; + final Curve? curve; - final TransformerPageController pageController; + final TransformerPageController? pageController; /// Set true to open infinity loop mode. final bool loop; @@ -429,7 +423,7 @@ class TransformerPageView extends StatefulWidget { final double viewportFraction; /// 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 /// created on demand. @@ -444,9 +438,9 @@ class TransformerPageView extends StatefulWidget { /// [itemBuilder] will be called only with indices greater than or equal to /// zero and less than [itemCount]. const TransformerPageView({ - Key key, + Key? key, this.index, - Duration duration, + Duration? duration, this.curve = Curves.ease, this.viewportFraction = 1.0, this.loop = false, @@ -458,29 +452,27 @@ class TransformerPageView extends StatefulWidget { this.transformer, this.itemBuilder, this.pageController, - @required this.itemCount, - }) : assert(itemCount != null), - assert(itemCount == 0 || itemBuilder != null || transformer != null), + required this.itemCount, + }) : assert(itemCount == 0 || itemBuilder != null || transformer != null), duration = duration ?? const Duration(milliseconds: kDefaultTransactionDuration), super(key: key); factory TransformerPageView.children( - {Key key, - int index, - Duration duration, + {Key? key, + int? index, + Duration? duration, Curve curve = Curves.ease, double viewportFraction = 1.0, bool loop = false, Axis scrollDirection = Axis.horizontal, - ScrollPhysics physics, + ScrollPhysics? physics, bool pageSnapping = true, - ValueChanged onPageChanged, - IndexController controller, - PageTransformer transformer, - @required List children, - TransformerPageController pageController}) { - assert(children != null); + ValueChanged? onPageChanged, + IndexController? controller, + PageTransformer? transformer, + required List children, + TransformerPageController? pageController}) { return TransformerPageView( itemCount: children.length, itemBuilder: (context, index) { @@ -506,92 +498,93 @@ class TransformerPageView extends StatefulWidget { return _TransformerPageViewState(); } - static int getRealIndexFromRenderIndex( - {bool reverse, int index, int itemCount, bool loop}) { - int initPage = reverse ? (itemCount - index - 1) : index; + static int? getRealIndexFromRenderIndex( + {required bool reverse, int? index, int? itemCount, required bool loop}) { + int? initPage = reverse ? (itemCount! - index! - 1) : index; if (loop) { - initPage += kMiddleValue; + initPage = initPage! + kMiddleValue; } return initPage; } static PageController createPageController( - {bool reverse, - int index, - int itemCount, - bool loop, - double viewportFraction}) { + {required bool reverse, + int? index, + int? itemCount, + required bool loop, + required double viewportFraction}) { return PageController( initialPage: getRealIndexFromRenderIndex( - reverse: reverse, index: index, itemCount: itemCount, loop: loop), + reverse: reverse, index: index, itemCount: itemCount, loop: loop)!, viewportFraction: viewportFraction); } } class _TransformerPageViewState extends State { - Size _size; - int _activeIndex; - double _currentPixels; + Size? _size; + int? _activeIndex; + double? _currentPixels; bool _done = false; ///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) { - int renderIndex = _pageController.getRenderIndexFromRealIndex(index); - Widget child = widget.itemBuilder(context, renderIndex); + int renderIndex = _pageController!.getRenderIndexFromRealIndex(index); + Widget child = widget.itemBuilder!(context, renderIndex); return child; } Widget _buildItem(BuildContext context, int index) { return AnimatedBuilder( - animation: _pageController, + animation: _pageController!, builder: (c, w) { - int renderIndex = _pageController.getRenderIndexFromRealIndex(index); - Widget child; + int renderIndex = _pageController!.getRenderIndexFromRealIndex(index); + Widget? child; if (widget.itemBuilder != null) { - child = widget.itemBuilder(context, renderIndex); + child = widget.itemBuilder!(context, renderIndex); } child ??= Container(); if (_size == null) { - return child ?? Container(); + return child; } double position; - double page = _pageController.realPage; + double? page = _pageController!.realPage; - if (_transformer.reverse) { - position = page - index; + if (_transformer!.reverse) { + position = page! - index; } else { - position = index - page; + position = index - page!; } position *= widget.viewportFraction; TransformInfo info = TransformInfo( index: renderIndex, - width: _size.width, - height: _size.height, - position: position.clamp(-1.0, 1.0) as double, + width: _size!.width, + height: _size!.height, + position: position.clamp(-1.0, 1.0), activeIndex: - _pageController.getRenderIndexFromRealIndex(_activeIndex), + _pageController!.getRenderIndexFromRealIndex(_activeIndex), fromIndex: _fromIndex, - forward: _pageController.position.pixels - _currentPixels >= 0, + forward: _pageController!.position.pixels - _currentPixels! >= 0, done: _done, scrollDirection: widget.scrollDirection, viewportFraction: widget.viewportFraction); - return _transformer.transform(child, info); + return _transformer!.transform(child, info); }); } - double _calcCurrentPixels() { - _currentPixels = _pageController.getRenderIndexFromRealIndex(_activeIndex) * - _pageController.position.viewportDimension * - widget.viewportFraction; + double? _calcCurrentPixels() { + _currentPixels = + _pageController!.getRenderIndexFromRealIndex(_activeIndex) * + _pageController!.position.viewportDimension * + widget.viewportFraction; // print("activeIndex:$_activeIndex , pix:$_currentPixels"); @@ -604,13 +597,13 @@ class _TransformerPageViewState extends State { _transformer == null ? _buildItemNormal : _buildItem; Widget child = PageView.builder( itemBuilder: builder, - itemCount: _pageController.getRealItemCount(), + itemCount: _pageController!.getRealItemCount(), onPageChanged: _onIndexChanged, controller: _pageController, scrollDirection: widget.scrollDirection, physics: widget.physics, pageSnapping: widget.pageSnapping, - reverse: _pageController.reverse, + reverse: _pageController!.reverse, ); if (_transformer == null) { return child; @@ -636,28 +629,23 @@ class _TransformerPageViewState extends State { void _onIndexChanged(int index) { _activeIndex = index; if (widget.onPageChanged != null) { - widget.onPageChanged(_pageController.getRenderIndexFromRealIndex(index)); + widget + .onPageChanged!(_pageController!.getRenderIndexFromRealIndex(index)); } } void _onGetSize(dynamic _) { - Size size; - if (context == null) { - onGetSize(size); - return; - } - RenderObject renderObject = context.findRenderObject(); + Size? size; + RenderObject? renderObject = context.findRenderObject(); if (renderObject != null) { Rect bounds = renderObject.paintBounds; - if (bounds != null) { - size = bounds.size; - } + size = bounds.size; } _calcCurrentPixels(); onGetSize(size); } - void onGetSize(Size size) { + void onGetSize(Size? size) { if (mounted) { setState(() { _size = size; @@ -675,14 +663,14 @@ class _TransformerPageViewState extends State { itemCount: widget.itemCount, loop: widget.loop, reverse: - widget.transformer == null ? false : widget.transformer.reverse); + widget.transformer == null ? false : widget.transformer!.reverse); // int initPage = _getRealIndexFromRenderIndex(index); // _pageController = new PageController(initialPage: initPage,viewportFraction: widget.viewportFraction); - _fromIndex = _activeIndex = _pageController.initialPage; + _fromIndex = _activeIndex = _pageController!.initialPage; _controller = getNotifier(); if (_controller != null) { - _controller.addListener(onChangeNotifier); + _controller!.addListener(onChangeNotifier); } super.initState(); } @@ -703,29 +691,29 @@ class _TransformerPageViewState extends State { loop: widget.loop, reverse: widget.transformer == null ? false - : widget.transformer.reverse); + : widget.transformer!.reverse); } } - if (_pageController.getRenderIndexFromRealIndex(_activeIndex) != index) { - _fromIndex = _activeIndex = _pageController.initialPage; + if (_pageController!.getRenderIndexFromRealIndex(_activeIndex) != index) { + _fromIndex = _activeIndex = _pageController!.initialPage; if (!created) { - int initPage = _pageController.getRealIndexFromRenderIndex(index); - _pageController.animateToPage(initPage, - duration: widget.duration, curve: widget.curve); + int initPage = _pageController!.getRealIndexFromRenderIndex(index)!; + _pageController!.animateToPage(initPage, + duration: widget.duration, curve: widget.curve!); } } if (_transformer != null) { - WidgetsBinding.instance.addPostFrameCallback(_onGetSize); + WidgetsBinding.instance!.addPostFrameCallback(_onGetSize); } if (_controller != getNotifier()) { if (_controller != null) { - _controller.removeListener(onChangeNotifier); + _controller!.removeListener(onChangeNotifier); } _controller = getNotifier(); if (_controller != null) { - _controller.addListener(onChangeNotifier); + _controller!.addListener(onChangeNotifier); } } super.didUpdateWidget(oldWidget); @@ -734,36 +722,36 @@ class _TransformerPageViewState extends State { @override void didChangeDependencies() { if (_transformer != null) { - WidgetsBinding.instance.addPostFrameCallback(_onGetSize); + WidgetsBinding.instance!.addPostFrameCallback(_onGetSize); } super.didChangeDependencies(); } - ChangeNotifier getNotifier() { + ChangeNotifier? getNotifier() { return widget.controller; } int _calcNextIndex(bool next) { - int currentIndex = _activeIndex; - if (_pageController.reverse) { + int? currentIndex = _activeIndex; + if (_pageController!.reverse) { if (next) { - currentIndex--; + currentIndex = currentIndex! - 1; } else { - currentIndex++; + currentIndex = currentIndex! + 1; } } else { if (next) { - currentIndex++; + currentIndex = currentIndex! + 1; } else { - currentIndex--; + currentIndex = currentIndex! - 1; } } - if (!_pageController.loop) { - if (currentIndex >= _pageController.itemCount) { + if (!_pageController!.loop) { + if (currentIndex >= _pageController!.itemCount!) { currentIndex = 0; } else if (currentIndex < 0) { - currentIndex = _pageController.itemCount - 1; + currentIndex = _pageController!.itemCount! - 1; } } @@ -771,13 +759,13 @@ class _TransformerPageViewState extends State { } void onChangeNotifier() { - int event = widget.controller.event; - int index; + int? event = widget.controller!.event; + int? index; switch (event) { case IndexController.MOVE: { - index = _pageController - .getRealIndexFromRenderIndex(widget.controller.index); + index = _pageController! + .getRealIndexFromRenderIndex(widget.controller!.index); } break; case IndexController.PREVIOUS: @@ -790,24 +778,24 @@ class _TransformerPageViewState extends State { //ignore this event return; } - if (widget.controller.animation) { - _pageController - .animateToPage(index, + if (widget.controller!.animation!) { + _pageController! + .animateToPage(index!, duration: widget.duration, curve: widget.curve ?? Curves.ease) - .whenComplete(widget.controller.complete); + .whenComplete(widget.controller!.complete); } else { - _pageController.jumpToPage(index); - widget.controller.complete(); + _pageController!.jumpToPage(index!); + widget.controller!.complete(); } } - ChangeNotifier _controller; + ChangeNotifier? _controller; @override void dispose() { super.dispose(); if (_controller != null) { - _controller.removeListener(onChangeNotifier); + _controller!.removeListener(onChangeNotifier); } } } diff --git a/web/filipino_cuisine/pubspec.lock b/web/filipino_cuisine/pubspec.lock index db23532d3..2d2fd37e3 100644 --- a/web/filipino_cuisine/pubspec.lock +++ b/web/filipino_cuisine/pubspec.lock @@ -1,6 +1,13 @@ # Generated by pub # See https://dart.dev/tools/pub/glossary#lockfile packages: + async: + dependency: transitive + description: + name: async + url: "https://pub.dartlang.org" + source: hosted + version: "2.8.2" characters: dependency: transitive description: @@ -54,14 +61,14 @@ packages: name: http url: "https://pub.dartlang.org" source: hosted - version: "0.12.2" + version: "0.13.4" http_parser: dependency: transitive description: name: http_parser url: "https://pub.dartlang.org" source: hosted - version: "3.1.4" + version: "4.0.0" lints: dependency: transitive description: @@ -83,13 +90,6 @@ packages: url: "https://pub.dartlang.org" source: hosted version: "1.8.0" - pedantic: - dependency: transitive - description: - name: pedantic - url: "https://pub.dartlang.org" - source: hosted - version: "1.11.1" sky_engine: dependency: transitive description: flutter @@ -138,5 +138,5 @@ packages: source: hosted version: "2.1.0" sdks: - dart: ">=2.12.0 <3.0.0" + dart: ">=2.14.0 <3.0.0" flutter: ">=0.1.4" diff --git a/web/filipino_cuisine/pubspec.yaml b/web/filipino_cuisine/pubspec.yaml index 70538afd5..fbd68d55d 100644 --- a/web/filipino_cuisine/pubspec.yaml +++ b/web/filipino_cuisine/pubspec.yaml @@ -1,13 +1,13 @@ name: filipino_cuisine environment: - sdk: ">=2.2.0 <3.0.0" + sdk: '>=2.12.0 <3.0.0' dependencies: flutter: sdk: flutter flutter_swiper: ^1.1.6 - http: ^0.12.0 + http: ^0.13.4 dev_dependencies: flutter_lints: ^1.0.0