mirror of
https://github.com/flutter/samples.git
synced 2025-11-08 13:58:47 +00:00
Upgrading samples to flutter_lints, part 1 of n (#804)
This commit is contained in:
1
web/_tool/analysis_options.yaml
Normal file
1
web/_tool/analysis_options.yaml
Normal file
@@ -0,0 +1 @@
|
||||
include: package:lints/recommended.yaml
|
||||
@@ -10,7 +10,7 @@ const ansiMagenta = 35;
|
||||
|
||||
Future<bool> run(
|
||||
String workingDir, String commandName, List<String> args) async {
|
||||
var commandDescription = '`${([commandName]..addAll(args)).join(' ')}`';
|
||||
var commandDescription = '`${([commandName, ...args]).join(' ')}`';
|
||||
|
||||
logWrapped(ansiMagenta, ' Running $commandDescription');
|
||||
|
||||
|
||||
@@ -7,34 +7,41 @@ packages:
|
||||
name: args
|
||||
url: "https://pub.dartlang.org"
|
||||
source: hosted
|
||||
version: "1.6.0"
|
||||
version: "2.1.1"
|
||||
charcode:
|
||||
dependency: transitive
|
||||
description:
|
||||
name: charcode
|
||||
url: "https://pub.dartlang.org"
|
||||
source: hosted
|
||||
version: "1.2.0-nullsafety.3"
|
||||
version: "1.2.0"
|
||||
lints:
|
||||
dependency: "direct dev"
|
||||
description:
|
||||
name: lints
|
||||
url: "https://pub.dartlang.org"
|
||||
source: hosted
|
||||
version: "1.0.1"
|
||||
markdown:
|
||||
dependency: "direct main"
|
||||
description:
|
||||
name: markdown
|
||||
url: "https://pub.dartlang.org"
|
||||
source: hosted
|
||||
version: "4.0.0-nullsafety.0"
|
||||
version: "4.0.0"
|
||||
meta:
|
||||
dependency: transitive
|
||||
description:
|
||||
name: meta
|
||||
url: "https://pub.dartlang.org"
|
||||
source: hosted
|
||||
version: "1.3.0-nullsafety.6"
|
||||
version: "1.4.0"
|
||||
path:
|
||||
dependency: "direct main"
|
||||
description:
|
||||
name: path
|
||||
url: "https://pub.dartlang.org"
|
||||
source: hosted
|
||||
version: "1.8.0-nullsafety.3"
|
||||
version: "1.8.0"
|
||||
sdks:
|
||||
dart: ">=2.12.0-0 <3.0.0"
|
||||
dart: ">=2.12.0 <3.0.0"
|
||||
|
||||
@@ -1,9 +1,12 @@
|
||||
name: tool
|
||||
publish_to: none
|
||||
|
||||
environment:
|
||||
sdk: '>=2.10.0 <3.0.0'
|
||||
environment:
|
||||
sdk: '>=2.12.0 <3.0.0'
|
||||
|
||||
dependencies:
|
||||
markdown: ^4.0.0-nullsafety.0
|
||||
path: ^1.8.0-nullsafety.3
|
||||
markdown: ^4.0.0
|
||||
path: ^1.8.0
|
||||
|
||||
dev_dependencies:
|
||||
lints: ^1.0.0
|
||||
|
||||
@@ -27,8 +27,8 @@ void main() async {
|
||||
]));
|
||||
results.add(await run(
|
||||
dir,
|
||||
'dartanalyzer',
|
||||
['--fatal-infos', '--fatal-warnings', '.'],
|
||||
'flutter',
|
||||
['analyze', '--fatal-infos', '--fatal-warnings', '.'],
|
||||
));
|
||||
_printStatus(results);
|
||||
}
|
||||
|
||||
20
web/filipino_cuisine/analysis_options.yaml
Normal file
20
web/filipino_cuisine/analysis_options.yaml
Normal file
@@ -0,0 +1,20 @@
|
||||
include: package:flutter_lints/flutter.yaml
|
||||
|
||||
analyzer:
|
||||
strong-mode:
|
||||
implicit-casts: false
|
||||
implicit-dynamic: false
|
||||
|
||||
linter:
|
||||
rules:
|
||||
avoid_types_on_closure_parameters: true
|
||||
avoid_void_async: true
|
||||
cancel_subscriptions: true
|
||||
close_sinks: true
|
||||
directives_ordering: true
|
||||
package_api_docs: true
|
||||
package_prefixed_library_names: true
|
||||
test_types_in_equals: true
|
||||
throw_in_finally: true
|
||||
unnecessary_statements: true
|
||||
use_key_in_widget_constructors: false
|
||||
@@ -1,30 +1,34 @@
|
||||
import 'package:flutter/material.dart';
|
||||
|
||||
class Cook extends StatefulWidget {
|
||||
final List dr;
|
||||
final img;
|
||||
final nme;
|
||||
final List<String> dr;
|
||||
final String img;
|
||||
final String nme;
|
||||
|
||||
Cook(this.dr, this.img, this.nme);
|
||||
const Cook(this.dr, this.img, this.nme);
|
||||
@override
|
||||
CState createState() => CState();
|
||||
}
|
||||
|
||||
class CState extends State<Cook> {
|
||||
List cb;
|
||||
List<bool> cb;
|
||||
|
||||
@override
|
||||
initState() {
|
||||
super.initState();
|
||||
cb = [];
|
||||
}
|
||||
|
||||
Widget build(ct) {
|
||||
List dr = widget.dr;
|
||||
@override
|
||||
Widget build(context) {
|
||||
List<String> dr = widget.dr;
|
||||
return Scaffold(
|
||||
appBar: AppBar(
|
||||
backgroundColor: Colors.red,
|
||||
title: Text("INSTRUCTIONS"),
|
||||
centerTitle: true),
|
||||
body: Column(children: <Widget>[
|
||||
appBar: AppBar(
|
||||
backgroundColor: Colors.red,
|
||||
title: const Text("INSTRUCTIONS"),
|
||||
centerTitle: true),
|
||||
body: Column(
|
||||
children: <Widget>[
|
||||
Container(
|
||||
child: ListTile(
|
||||
leading: ClipRRect(
|
||||
@@ -34,23 +38,27 @@ class CState extends State<Cook> {
|
||||
child: Image.asset(widget.img,
|
||||
fit: BoxFit.cover, width: 100, height: 100))),
|
||||
title: Text(widget.nme,
|
||||
style: Theme.of(ct)
|
||||
style: Theme.of(context)
|
||||
.textTheme
|
||||
.headline3
|
||||
.copyWith(fontFamily: 'ark', color: Colors.black))),
|
||||
margin: EdgeInsets.only(top: 40, bottom: 30, left: 20)),
|
||||
margin: const EdgeInsets.only(top: 40, bottom: 30, left: 20)),
|
||||
Expanded(
|
||||
child: ListView.builder(
|
||||
itemCount: dr.length,
|
||||
padding: EdgeInsets.all(10),
|
||||
itemBuilder: (ct, i) {
|
||||
cb.add(false);
|
||||
return ListTile(
|
||||
title: Text(dr[i]),
|
||||
trailing: Checkbox(
|
||||
value: cb[i],
|
||||
onChanged: (v) => setState(() => cb[i] = v)));
|
||||
})),
|
||||
]));
|
||||
child: ListView.builder(
|
||||
itemCount: dr.length,
|
||||
padding: const EdgeInsets.all(10),
|
||||
itemBuilder: (ct, i) {
|
||||
cb.add(false);
|
||||
return ListTile(
|
||||
title: Text(dr[i]),
|
||||
trailing: Checkbox(
|
||||
value: cb[i],
|
||||
onChanged: (v) => setState(() => cb[i] = v)));
|
||||
},
|
||||
),
|
||||
),
|
||||
],
|
||||
),
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -8,6 +8,7 @@ class WarmPainter extends BasePainter {
|
||||
WarmPainter(PageIndicator widget, double page, int index, Paint paint)
|
||||
: super(widget, page, index, paint);
|
||||
|
||||
@override
|
||||
void draw(Canvas canvas, double space, double size, double radius) {
|
||||
double progress = page - index;
|
||||
double distance = size + space;
|
||||
@@ -20,15 +21,13 @@ class WarmPainter extends BasePainter {
|
||||
|
||||
double left = index * distance + distance * (progress - 0.5) * 2;
|
||||
canvas.drawRRect(
|
||||
new RRect.fromLTRBR(
|
||||
left, 0.0, right, size, new Radius.circular(radius)),
|
||||
RRect.fromLTRBR(left, 0.0, right, size, Radius.circular(radius)),
|
||||
_paint);
|
||||
} else {
|
||||
double right = start + size + distance * progress * 2;
|
||||
|
||||
canvas.drawRRect(
|
||||
new RRect.fromLTRBR(
|
||||
start, 0.0, right, size, new Radius.circular(radius)),
|
||||
RRect.fromLTRBR(start, 0.0, right, size, Radius.circular(radius)),
|
||||
_paint);
|
||||
}
|
||||
}
|
||||
@@ -48,7 +47,7 @@ class DropPainter extends BasePainter {
|
||||
//lerp(begin, end, progress)
|
||||
|
||||
canvas.drawCircle(
|
||||
new Offset(radius + ((page) * (size + space)),
|
||||
Offset(radius + ((page) * (size + space)),
|
||||
radius - dropHeight * (1 - rate)),
|
||||
radius * (scale + rate * (1.0 - scale)),
|
||||
_paint);
|
||||
@@ -67,10 +66,10 @@ class NonePainter extends BasePainter {
|
||||
: radius + ((index + 1) * (size + space));
|
||||
|
||||
if (progress > 0.5) {
|
||||
canvas.drawCircle(new Offset(secondOffset, radius), radius, _paint);
|
||||
canvas.drawCircle(Offset(secondOffset, radius), radius, _paint);
|
||||
} else {
|
||||
canvas.drawCircle(new Offset(radius + (index * (size + space)), radius),
|
||||
radius, _paint);
|
||||
canvas.drawCircle(
|
||||
Offset(radius + (index * (size + space)), radius), radius, _paint);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -82,7 +81,7 @@ class SlidePainter extends BasePainter {
|
||||
@override
|
||||
void draw(Canvas canvas, double space, double size, double radius) {
|
||||
canvas.drawCircle(
|
||||
new Offset(radius + (page * (size + space)), radius), radius, _paint);
|
||||
Offset(radius + (page * (size + space)), radius), radius, _paint);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -92,11 +91,11 @@ class ScalePainter extends BasePainter {
|
||||
|
||||
// 连续的两个点,含有最后一个和第一个
|
||||
@override
|
||||
bool _shouldSkip(int i) {
|
||||
if (index == widget.count - 1) {
|
||||
return i == 0 || i == index;
|
||||
bool _shouldSkip(int index) {
|
||||
if (super.index == widget.count - 1) {
|
||||
return index == 0 || index == super.index;
|
||||
}
|
||||
return (i == index || i == index + 1);
|
||||
return (index == super.index || index == super.index + 1);
|
||||
}
|
||||
|
||||
@override
|
||||
@@ -109,7 +108,7 @@ class ScalePainter extends BasePainter {
|
||||
if (_shouldSkip(i)) {
|
||||
continue;
|
||||
}
|
||||
canvas.drawCircle(new Offset(i * (size + space) + radius, radius),
|
||||
canvas.drawCircle(Offset(i * (size + space) + radius, radius),
|
||||
radius * widget.scale, _paint);
|
||||
}
|
||||
|
||||
@@ -126,11 +125,11 @@ class ScalePainter extends BasePainter {
|
||||
double progress = page - index;
|
||||
_paint.color = Color.lerp(widget.activeColor, widget.color, progress);
|
||||
//last
|
||||
canvas.drawCircle(new Offset(radius + (index * (size + space)), radius),
|
||||
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);
|
||||
canvas.drawCircle(new Offset(secondOffset, radius),
|
||||
canvas.drawCircle(Offset(secondOffset, radius),
|
||||
lerp(radius * widget.scale, radius, progress), _paint);
|
||||
}
|
||||
}
|
||||
@@ -141,11 +140,11 @@ class ColorPainter extends BasePainter {
|
||||
|
||||
// 连续的两个点,含有最后一个和第一个
|
||||
@override
|
||||
bool _shouldSkip(int i) {
|
||||
if (index == widget.count - 1) {
|
||||
return i == 0 || i == index;
|
||||
bool _shouldSkip(int index) {
|
||||
if (super.index == widget.count - 1) {
|
||||
return index == 0 || index == super.index;
|
||||
}
|
||||
return (i == index || i == index + 1);
|
||||
return (index == super.index || index == super.index + 1);
|
||||
}
|
||||
|
||||
@override
|
||||
@@ -158,10 +157,10 @@ class ColorPainter extends BasePainter {
|
||||
_paint.color = Color.lerp(widget.activeColor, widget.color, progress);
|
||||
//left
|
||||
canvas.drawCircle(
|
||||
new Offset(radius + (index * (size + space)), radius), radius, _paint);
|
||||
Offset(radius + (index * (size + space)), radius), radius, _paint);
|
||||
//right
|
||||
_paint.color = Color.lerp(widget.color, widget.activeColor, progress);
|
||||
canvas.drawCircle(new Offset(secondOffset, radius), radius, _paint);
|
||||
canvas.drawCircle(Offset(secondOffset, radius), radius, _paint);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -195,7 +194,7 @@ abstract class BasePainter extends CustomPainter {
|
||||
continue;
|
||||
}
|
||||
canvas.drawCircle(
|
||||
new Offset(i * (size + space) + radius, radius), radius, _paint);
|
||||
Offset(i * (size + space) + radius, radius), radius, _paint);
|
||||
}
|
||||
|
||||
double page = this.page;
|
||||
@@ -214,51 +213,51 @@ abstract class BasePainter extends CustomPainter {
|
||||
|
||||
class _PageIndicatorState extends State<PageIndicator> {
|
||||
int index = 0;
|
||||
Paint _paint = new Paint();
|
||||
final Paint _paint = Paint();
|
||||
|
||||
BasePainter _createPainer() {
|
||||
switch (widget.layout) {
|
||||
case PageIndicatorLayout.NONE:
|
||||
return new NonePainter(
|
||||
return NonePainter(
|
||||
widget, widget.controller.page ?? 0.0, index, _paint);
|
||||
case PageIndicatorLayout.SLIDE:
|
||||
return new SlidePainter(
|
||||
return SlidePainter(
|
||||
widget, widget.controller.page ?? 0.0, index, _paint);
|
||||
case PageIndicatorLayout.WARM:
|
||||
return new WarmPainter(
|
||||
return WarmPainter(
|
||||
widget, widget.controller.page ?? 0.0, index, _paint);
|
||||
case PageIndicatorLayout.COLOR:
|
||||
return new ColorPainter(
|
||||
return ColorPainter(
|
||||
widget, widget.controller.page ?? 0.0, index, _paint);
|
||||
case PageIndicatorLayout.SCALE:
|
||||
return new ScalePainter(
|
||||
return ScalePainter(
|
||||
widget, widget.controller.page ?? 0.0, index, _paint);
|
||||
case PageIndicatorLayout.DROP:
|
||||
return new DropPainter(
|
||||
return DropPainter(
|
||||
widget, widget.controller.page ?? 0.0, index, _paint);
|
||||
default:
|
||||
throw new Exception("Not a valid layout");
|
||||
throw Exception("Not a valid layout");
|
||||
}
|
||||
}
|
||||
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
Widget child = new SizedBox(
|
||||
Widget child = SizedBox(
|
||||
width: widget.count * widget.size + (widget.count - 1) * widget.space,
|
||||
height: widget.size,
|
||||
child: new CustomPaint(
|
||||
child: CustomPaint(
|
||||
painter: _createPainer(),
|
||||
),
|
||||
);
|
||||
|
||||
if (widget.layout == PageIndicatorLayout.SCALE ||
|
||||
widget.layout == PageIndicatorLayout.COLOR) {
|
||||
child = new ClipRect(
|
||||
child = ClipRect(
|
||||
child: child,
|
||||
);
|
||||
}
|
||||
|
||||
return new IgnorePointer(
|
||||
return IgnorePointer(
|
||||
child: child,
|
||||
);
|
||||
}
|
||||
@@ -292,14 +291,8 @@ class _PageIndicatorState extends State<PageIndicator> {
|
||||
}
|
||||
}
|
||||
|
||||
enum PageIndicatorLayout {
|
||||
NONE,
|
||||
SLIDE,
|
||||
WARM,
|
||||
COLOR,
|
||||
SCALE,
|
||||
DROP,
|
||||
}
|
||||
// ignore: constant_identifier_names
|
||||
enum PageIndicatorLayout { NONE, SLIDE, WARM, COLOR, SCALE, DROP }
|
||||
|
||||
class PageIndicator extends StatefulWidget {
|
||||
/// size of the dots
|
||||
@@ -330,24 +323,24 @@ class PageIndicator extends StatefulWidget {
|
||||
|
||||
final double activeSize;
|
||||
|
||||
PageIndicator(
|
||||
const PageIndicator(
|
||||
{Key key,
|
||||
this.size: 20.0,
|
||||
this.space: 5.0,
|
||||
this.count,
|
||||
this.activeSize: 20.0,
|
||||
this.controller,
|
||||
this.color: Colors.white30,
|
||||
this.layout: PageIndicatorLayout.SLIDE,
|
||||
this.activeColor: Colors.white,
|
||||
this.scale: 0.6,
|
||||
this.dropHeight: 20.0})
|
||||
this.size = 20.0,
|
||||
this.space = 5.0,
|
||||
@required this.count,
|
||||
this.activeSize = 20.0,
|
||||
@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);
|
||||
|
||||
@override
|
||||
State<StatefulWidget> createState() {
|
||||
return new _PageIndicatorState();
|
||||
return _PageIndicatorState();
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,17 +1,18 @@
|
||||
// Package flutter_swiper:
|
||||
// https://pub.dartlang.org/packages/flutter_swiper
|
||||
|
||||
import 'dart:async';
|
||||
|
||||
import 'package:flutter/material.dart';
|
||||
import 'package:flutter/foundation.dart';
|
||||
|
||||
import 'dart:async';
|
||||
|
||||
import 'flutter_page_indicator.dart';
|
||||
import 'transformer_page_view.dart';
|
||||
|
||||
typedef void SwiperOnTap(int index);
|
||||
typedef SwiperOnTap = void Function(int index);
|
||||
|
||||
typedef Widget SwiperDataBuilder(BuildContext context, dynamic data, int index);
|
||||
typedef SwiperDataBuilder = Widget Function(
|
||||
BuildContext context, dynamic data, int index);
|
||||
|
||||
/// default auto play delay
|
||||
const int kDefaultAutoplayDelayMs = 3000;
|
||||
@@ -22,6 +23,7 @@ const int kDefaultAutoplayTransactionDuration = 300;
|
||||
const int kMaxValue = 2000000000;
|
||||
const int kMiddleValue = 1000000000;
|
||||
|
||||
// ignore_for_file: constant_identifier_names
|
||||
enum SwiperLayout { DEFAULT, STACK, TINDER, CUSTOM }
|
||||
|
||||
class Swiper extends StatefulWidget {
|
||||
@@ -111,25 +113,25 @@ class Swiper extends StatefulWidget {
|
||||
|
||||
final PageIndicatorLayout indicatorLayout;
|
||||
|
||||
Swiper({
|
||||
const Swiper({
|
||||
this.itemBuilder,
|
||||
this.indicatorLayout: PageIndicatorLayout.NONE,
|
||||
this.indicatorLayout = PageIndicatorLayout.NONE,
|
||||
|
||||
///
|
||||
this.transformer,
|
||||
@required this.itemCount,
|
||||
this.autoplay: false,
|
||||
this.layout: SwiperLayout.DEFAULT,
|
||||
this.autoplayDelay: kDefaultAutoplayDelayMs,
|
||||
this.autoplayDisableOnInteraction: true,
|
||||
this.duration: kDefaultAutoplayTransactionDuration,
|
||||
this.autoplay = false,
|
||||
this.layout = SwiperLayout.DEFAULT,
|
||||
this.autoplayDelay = kDefaultAutoplayDelayMs,
|
||||
this.autoplayDisableOnInteraction = true,
|
||||
this.duration = kDefaultAutoplayTransactionDuration,
|
||||
this.onIndexChanged,
|
||||
this.index,
|
||||
this.onTap,
|
||||
this.control,
|
||||
this.loop: true,
|
||||
this.curve: Curves.ease,
|
||||
this.scrollDirection: Axis.horizontal,
|
||||
this.loop = true,
|
||||
this.curve = Curves.ease,
|
||||
this.scrollDirection = Axis.horizontal,
|
||||
this.pagination,
|
||||
this.plugins,
|
||||
this.physics,
|
||||
@@ -140,10 +142,10 @@ class Swiper extends StatefulWidget {
|
||||
/// since v1.0.0
|
||||
this.containerHeight,
|
||||
this.containerWidth,
|
||||
this.viewportFraction: 1.0,
|
||||
this.viewportFraction = 1.0,
|
||||
this.itemHeight,
|
||||
this.itemWidth,
|
||||
this.outer: false,
|
||||
this.outer = false,
|
||||
this.scale,
|
||||
this.fade,
|
||||
}) : assert(itemBuilder != null || transformer != null,
|
||||
@@ -160,19 +162,19 @@ class Swiper extends StatefulWidget {
|
||||
super(key: key);
|
||||
|
||||
factory Swiper.children({
|
||||
List<Widget> children,
|
||||
bool autoplay: false,
|
||||
@required List<Widget> children,
|
||||
bool autoplay = false,
|
||||
PageTransformer transformer,
|
||||
int autoplayDelay: kDefaultAutoplayDelayMs,
|
||||
bool reverse: false,
|
||||
bool autoplayDisableOnInteraction: true,
|
||||
int duration: kDefaultAutoplayTransactionDuration,
|
||||
int autoplayDelay = kDefaultAutoplayDelayMs,
|
||||
bool reverse = false,
|
||||
bool autoplayDisableOnInteraction = true,
|
||||
int duration = kDefaultAutoplayTransactionDuration,
|
||||
ValueChanged<int> onIndexChanged,
|
||||
int index,
|
||||
SwiperOnTap onTap,
|
||||
bool loop: true,
|
||||
Curve curve: Curves.ease,
|
||||
Axis scrollDirection: Axis.horizontal,
|
||||
bool loop = true,
|
||||
Curve curve = Curves.ease,
|
||||
Axis scrollDirection = Axis.horizontal,
|
||||
SwiperPlugin pagination,
|
||||
SwiperPlugin control,
|
||||
List<SwiperPlugin> plugins,
|
||||
@@ -182,15 +184,15 @@ class Swiper extends StatefulWidget {
|
||||
ScrollPhysics physics,
|
||||
double containerHeight,
|
||||
double containerWidth,
|
||||
double viewportFraction: 1.0,
|
||||
double viewportFraction = 1.0,
|
||||
double itemHeight,
|
||||
double itemWidth,
|
||||
bool outer: false,
|
||||
double scale: 1.0,
|
||||
bool outer = false,
|
||||
double scale = 1.0,
|
||||
}) {
|
||||
assert(children != null, "children must not be null");
|
||||
|
||||
return new Swiper(
|
||||
return Swiper(
|
||||
transformer: transformer,
|
||||
customLayoutOption: customLayoutOption,
|
||||
containerHeight: containerHeight,
|
||||
@@ -216,7 +218,7 @@ class Swiper extends StatefulWidget {
|
||||
plugins: plugins,
|
||||
physics: physics,
|
||||
key: key,
|
||||
itemBuilder: (BuildContext context, int index) {
|
||||
itemBuilder: (context, index) {
|
||||
return children[index];
|
||||
},
|
||||
itemCount: children.length);
|
||||
@@ -227,17 +229,17 @@ class Swiper extends StatefulWidget {
|
||||
List list,
|
||||
CustomLayoutOption customLayoutOption,
|
||||
SwiperDataBuilder builder,
|
||||
bool autoplay: false,
|
||||
int autoplayDelay: kDefaultAutoplayDelayMs,
|
||||
bool reverse: false,
|
||||
bool autoplayDisableOnInteraction: true,
|
||||
int duration: kDefaultAutoplayTransactionDuration,
|
||||
bool autoplay = false,
|
||||
int autoplayDelay = kDefaultAutoplayDelayMs,
|
||||
bool reverse = false,
|
||||
bool autoplayDisableOnInteraction = true,
|
||||
int duration = kDefaultAutoplayTransactionDuration,
|
||||
ValueChanged<int> onIndexChanged,
|
||||
int index,
|
||||
SwiperOnTap onTap,
|
||||
bool loop: true,
|
||||
Curve curve: Curves.ease,
|
||||
Axis scrollDirection: Axis.horizontal,
|
||||
bool loop = true,
|
||||
Curve curve = Curves.ease,
|
||||
Axis scrollDirection = Axis.horizontal,
|
||||
SwiperPlugin pagination,
|
||||
SwiperPlugin control,
|
||||
List<SwiperPlugin> plugins,
|
||||
@@ -246,13 +248,13 @@ class Swiper extends StatefulWidget {
|
||||
ScrollPhysics physics,
|
||||
double containerHeight,
|
||||
double containerWidth,
|
||||
double viewportFraction: 1.0,
|
||||
double viewportFraction = 1.0,
|
||||
double itemHeight,
|
||||
double itemWidth,
|
||||
bool outer: false,
|
||||
double scale: 1.0,
|
||||
bool outer = false,
|
||||
double scale = 1.0,
|
||||
}) {
|
||||
return new Swiper(
|
||||
return Swiper(
|
||||
transformer: transformer,
|
||||
customLayoutOption: customLayoutOption,
|
||||
containerHeight: containerHeight,
|
||||
@@ -278,7 +280,7 @@ class Swiper extends StatefulWidget {
|
||||
loop: loop,
|
||||
plugins: plugins,
|
||||
physics: physics,
|
||||
itemBuilder: (BuildContext context, int index) {
|
||||
itemBuilder: (context, index) {
|
||||
return builder(context, list[index], index);
|
||||
},
|
||||
itemCount: list.length);
|
||||
@@ -286,7 +288,7 @@ class Swiper extends StatefulWidget {
|
||||
|
||||
@override
|
||||
State<StatefulWidget> createState() {
|
||||
return new _SwiperState();
|
||||
return _SwiperState();
|
||||
}
|
||||
}
|
||||
|
||||
@@ -298,9 +300,7 @@ abstract class _SwiperTimerMixin extends State<Swiper> {
|
||||
@override
|
||||
void initState() {
|
||||
_controller = widget.controller;
|
||||
if (_controller == null) {
|
||||
_controller = new SwiperController();
|
||||
}
|
||||
_controller ??= SwiperController();
|
||||
_controller.addListener(_onController);
|
||||
_handleAutoplay();
|
||||
super.initState();
|
||||
@@ -385,10 +385,10 @@ class _SwiperState extends _SwiperTimerMixin {
|
||||
TransformerPageController _pageController;
|
||||
|
||||
Widget _wrapTap(BuildContext context, int index) {
|
||||
return new GestureDetector(
|
||||
return GestureDetector(
|
||||
behavior: HitTestBehavior.opaque,
|
||||
onTap: () {
|
||||
this.widget.onTap(index);
|
||||
widget.onTap(index);
|
||||
},
|
||||
child: widget.itemBuilder(context, index),
|
||||
);
|
||||
@@ -398,7 +398,7 @@ class _SwiperState extends _SwiperTimerMixin {
|
||||
void initState() {
|
||||
_activeIndex = widget.index ?? 0;
|
||||
if (_isPageViewLayout()) {
|
||||
_pageController = new TransformerPageController(
|
||||
_pageController = TransformerPageController(
|
||||
initialPage: widget.index,
|
||||
loop: widget.loop,
|
||||
itemCount: widget.itemCount,
|
||||
@@ -431,7 +431,7 @@ class _SwiperState extends _SwiperTimerMixin {
|
||||
widget.itemCount != oldWidget.itemCount ||
|
||||
widget.viewportFraction != oldWidget.viewportFraction ||
|
||||
_getReverse(widget) != _getReverse(oldWidget))) {
|
||||
_pageController = new TransformerPageController(
|
||||
_pageController = TransformerPageController(
|
||||
initialPage: widget.index,
|
||||
loop: widget.loop,
|
||||
itemCount: widget.itemCount,
|
||||
@@ -470,7 +470,7 @@ class _SwiperState extends _SwiperTimerMixin {
|
||||
}
|
||||
|
||||
if (widget.layout == SwiperLayout.STACK) {
|
||||
return new _StackSwiper(
|
||||
return _StackSwiper(
|
||||
loop: widget.loop,
|
||||
itemWidth: widget.itemWidth,
|
||||
itemHeight: widget.itemHeight,
|
||||
@@ -487,10 +487,10 @@ class _SwiperState extends _SwiperTimerMixin {
|
||||
PageTransformer transformer = widget.transformer;
|
||||
if (widget.scale != null || widget.fade != null) {
|
||||
transformer =
|
||||
new ScaleAndFadeTransformer(scale: widget.scale, fade: widget.fade);
|
||||
ScaleAndFadeTransformer(scale: widget.scale, fade: widget.fade);
|
||||
}
|
||||
|
||||
Widget child = new TransformerPageView(
|
||||
Widget child = TransformerPageView(
|
||||
pageController: _pageController,
|
||||
loop: widget.loop,
|
||||
itemCount: widget.itemCount,
|
||||
@@ -498,7 +498,7 @@ class _SwiperState extends _SwiperTimerMixin {
|
||||
transformer: transformer,
|
||||
viewportFraction: widget.viewportFraction,
|
||||
index: _activeIndex,
|
||||
duration: new Duration(milliseconds: widget.duration),
|
||||
duration: Duration(milliseconds: widget.duration),
|
||||
scrollDirection: widget.scrollDirection,
|
||||
onPageChanged: _onIndexChanged,
|
||||
curve: widget.curve,
|
||||
@@ -506,9 +506,9 @@ class _SwiperState extends _SwiperTimerMixin {
|
||||
controller: _controller,
|
||||
);
|
||||
if (widget.autoplayDisableOnInteraction && widget.autoplay) {
|
||||
return new NotificationListener(
|
||||
return NotificationListener(
|
||||
child: child,
|
||||
onNotification: (ScrollNotification notification) {
|
||||
onNotification: (dynamic notification) {
|
||||
if (notification is ScrollStartNotification) {
|
||||
if (notification.dragDetails != null) {
|
||||
//by human
|
||||
@@ -525,7 +525,7 @@ class _SwiperState extends _SwiperTimerMixin {
|
||||
|
||||
return child;
|
||||
} else if (widget.layout == SwiperLayout.TINDER) {
|
||||
return new _TinderSwiper(
|
||||
return _TinderSwiper(
|
||||
loop: widget.loop,
|
||||
itemWidth: widget.itemWidth,
|
||||
itemHeight: widget.itemHeight,
|
||||
@@ -539,7 +539,7 @@ class _SwiperState extends _SwiperTimerMixin {
|
||||
scrollDirection: widget.scrollDirection,
|
||||
);
|
||||
} else if (widget.layout == SwiperLayout.CUSTOM) {
|
||||
return new _CustomLayoutSwiper(
|
||||
return _CustomLayoutSwiper(
|
||||
loop: widget.loop,
|
||||
option: widget.customLayoutOption,
|
||||
itemWidth: widget.itemWidth,
|
||||
@@ -554,23 +554,21 @@ class _SwiperState extends _SwiperTimerMixin {
|
||||
scrollDirection: widget.scrollDirection,
|
||||
);
|
||||
} else {
|
||||
return new Container();
|
||||
return Container();
|
||||
}
|
||||
}
|
||||
|
||||
SwiperPluginConfig _ensureConfig(SwiperPluginConfig config) {
|
||||
if (config == null) {
|
||||
config = new SwiperPluginConfig(
|
||||
outer: widget.outer,
|
||||
itemCount: widget.itemCount,
|
||||
layout: widget.layout,
|
||||
indicatorLayout: widget.indicatorLayout,
|
||||
pageController: _pageController,
|
||||
activeIndex: _activeIndex,
|
||||
scrollDirection: widget.scrollDirection,
|
||||
controller: _controller,
|
||||
loop: widget.loop);
|
||||
}
|
||||
config ??= SwiperPluginConfig(
|
||||
outer: widget.outer,
|
||||
itemCount: widget.itemCount,
|
||||
layout: widget.layout,
|
||||
indicatorLayout: widget.indicatorLayout,
|
||||
pageController: _pageController,
|
||||
activeIndex: _activeIndex,
|
||||
scrollDirection: widget.scrollDirection,
|
||||
controller: _controller,
|
||||
loop: widget.loop);
|
||||
return config;
|
||||
}
|
||||
|
||||
@@ -607,8 +605,8 @@ class _SwiperState extends _SwiperTimerMixin {
|
||||
config = _ensureConfig(config);
|
||||
if (widget.outer) {
|
||||
return _buildOuterPagination(
|
||||
widget.pagination,
|
||||
listForStack == null ? swiper : new Stack(children: listForStack),
|
||||
widget.pagination as SwiperPagination,
|
||||
listForStack == null ? swiper : Stack(children: listForStack),
|
||||
config);
|
||||
} else {
|
||||
listForStack = _ensureListForStack(
|
||||
@@ -617,7 +615,7 @@ class _SwiperState extends _SwiperTimerMixin {
|
||||
}
|
||||
|
||||
if (listForStack != null) {
|
||||
return new Stack(
|
||||
return Stack(
|
||||
children: listForStack,
|
||||
);
|
||||
}
|
||||
@@ -632,15 +630,15 @@ class _SwiperState extends _SwiperTimerMixin {
|
||||
if (widget.containerHeight != null || widget.containerWidth != null) {
|
||||
list.add(swiper);
|
||||
} else {
|
||||
list.add(new Expanded(child: swiper));
|
||||
list.add(Expanded(child: swiper));
|
||||
}
|
||||
|
||||
list.add(new Align(
|
||||
list.add(Align(
|
||||
alignment: Alignment.center,
|
||||
child: pagination.build(context, config),
|
||||
));
|
||||
|
||||
return new Column(
|
||||
return Column(
|
||||
children: list,
|
||||
crossAxisAlignment: CrossAxisAlignment.stretch,
|
||||
mainAxisSize: MainAxisSize.min,
|
||||
@@ -661,7 +659,7 @@ abstract class _SubSwiper extends StatefulWidget {
|
||||
final bool loop;
|
||||
final Axis scrollDirection;
|
||||
|
||||
_SubSwiper(
|
||||
const _SubSwiper(
|
||||
{Key key,
|
||||
this.loop,
|
||||
this.itemHeight,
|
||||
@@ -672,13 +670,10 @@ abstract class _SubSwiper extends StatefulWidget {
|
||||
this.controller,
|
||||
this.index,
|
||||
this.itemCount,
|
||||
this.scrollDirection: Axis.horizontal,
|
||||
this.scrollDirection = Axis.horizontal,
|
||||
this.onIndexChanged})
|
||||
: super(key: key);
|
||||
|
||||
@override
|
||||
State<StatefulWidget> createState();
|
||||
|
||||
int getCorrectIndex(int indexNeedsFix) {
|
||||
if (itemCount == 0) return 0;
|
||||
int value = indexNeedsFix % itemCount;
|
||||
@@ -690,14 +685,14 @@ abstract class _SubSwiper extends StatefulWidget {
|
||||
}
|
||||
|
||||
class _TinderSwiper extends _SubSwiper {
|
||||
_TinderSwiper({
|
||||
const _TinderSwiper({
|
||||
Key key,
|
||||
Curve curve,
|
||||
int duration,
|
||||
SwiperController controller,
|
||||
ValueChanged<int> onIndexChanged,
|
||||
double itemHeight,
|
||||
double itemWidth,
|
||||
@required double itemHeight,
|
||||
@required double itemWidth,
|
||||
IndexedWidgetBuilder itemBuilder,
|
||||
int index,
|
||||
bool loop,
|
||||
@@ -720,12 +715,12 @@ class _TinderSwiper extends _SubSwiper {
|
||||
|
||||
@override
|
||||
State<StatefulWidget> createState() {
|
||||
return new _TinderState();
|
||||
return _TinderState();
|
||||
}
|
||||
}
|
||||
|
||||
class _StackSwiper extends _SubSwiper {
|
||||
_StackSwiper({
|
||||
const _StackSwiper({
|
||||
Key key,
|
||||
Curve curve,
|
||||
int duration,
|
||||
@@ -754,7 +749,7 @@ class _StackSwiper extends _SubSwiper {
|
||||
|
||||
@override
|
||||
State<StatefulWidget> createState() {
|
||||
return new _StackViewState();
|
||||
return _StackViewState();
|
||||
}
|
||||
}
|
||||
|
||||
@@ -829,17 +824,17 @@ class _TinderState extends _CustomLayoutStateBase<_TinderSwiper> {
|
||||
? Alignment.bottomCenter
|
||||
: Alignment.centerLeft;
|
||||
|
||||
return new Opacity(
|
||||
return Opacity(
|
||||
opacity: o,
|
||||
child: new Transform.rotate(
|
||||
child: Transform.rotate(
|
||||
angle: a / 180.0,
|
||||
child: new Transform.translate(
|
||||
key: new ValueKey<int>(_currentIndex + i),
|
||||
offset: new Offset(f, fy),
|
||||
child: new Transform.scale(
|
||||
child: Transform.translate(
|
||||
key: ValueKey<int>(_currentIndex + i),
|
||||
offset: Offset(f, fy),
|
||||
child: Transform.scale(
|
||||
scale: s,
|
||||
alignment: alignment,
|
||||
child: new SizedBox(
|
||||
child: SizedBox(
|
||||
width: widget.itemWidth ?? double.infinity,
|
||||
height: widget.itemHeight ?? double.infinity,
|
||||
child: widget.itemBuilder(context, realIndex),
|
||||
@@ -898,22 +893,22 @@ class _StackViewState extends _CustomLayoutStateBase<_StackSwiper> {
|
||||
double o = _getValue(opacity, animationValue, i);
|
||||
|
||||
Offset offset = widget.scrollDirection == Axis.horizontal
|
||||
? new Offset(f, 0.0)
|
||||
: new Offset(0.0, f);
|
||||
? Offset(f, 0.0)
|
||||
: Offset(0.0, f);
|
||||
|
||||
Alignment alignment = widget.scrollDirection == Axis.horizontal
|
||||
? Alignment.centerLeft
|
||||
: Alignment.topCenter;
|
||||
|
||||
return new Opacity(
|
||||
return Opacity(
|
||||
opacity: o,
|
||||
child: new Transform.translate(
|
||||
key: new ValueKey<int>(_currentIndex + i),
|
||||
child: Transform.translate(
|
||||
key: ValueKey<int>(_currentIndex + i),
|
||||
offset: offset,
|
||||
child: new Transform.scale(
|
||||
child: Transform.scale(
|
||||
scale: s,
|
||||
alignment: alignment,
|
||||
child: new SizedBox(
|
||||
child: SizedBox(
|
||||
width: widget.itemWidth ?? double.infinity,
|
||||
height: widget.itemHeight ?? double.infinity,
|
||||
child: widget.itemBuilder(context, realIndex),
|
||||
@@ -928,11 +923,12 @@ class ScaleAndFadeTransformer extends PageTransformer {
|
||||
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;
|
||||
Widget child = item;
|
||||
@@ -940,7 +936,7 @@ class ScaleAndFadeTransformer extends PageTransformer {
|
||||
double scaleFactor = (1 - position.abs()) * (1 - _scale);
|
||||
double scale = _scale + scaleFactor;
|
||||
|
||||
child = new Transform.scale(
|
||||
child = Transform.scale(
|
||||
scale: scale,
|
||||
child: item,
|
||||
);
|
||||
@@ -949,7 +945,7 @@ class ScaleAndFadeTransformer extends PageTransformer {
|
||||
if (_fade != null) {
|
||||
double fadeFactor = (1 - position.abs()) * (1 - _fade);
|
||||
double opacity = _fade + fadeFactor;
|
||||
child = new Opacity(
|
||||
child = Opacity(
|
||||
opacity: opacity,
|
||||
child: child,
|
||||
);
|
||||
@@ -981,17 +977,17 @@ class SwiperControl extends SwiperPlugin {
|
||||
final Key key;
|
||||
|
||||
const SwiperControl(
|
||||
{this.iconPrevious: Icons.arrow_back_ios,
|
||||
this.iconNext: Icons.arrow_forward_ios,
|
||||
{this.iconPrevious = Icons.arrow_back_ios,
|
||||
this.iconNext = Icons.arrow_forward_ios,
|
||||
this.color,
|
||||
this.disableColor,
|
||||
this.key,
|
||||
this.size: 30.0,
|
||||
this.padding: const EdgeInsets.all(5.0)});
|
||||
this.size = 30.0,
|
||||
this.padding = const EdgeInsets.all(5.0)});
|
||||
|
||||
Widget buildButton(SwiperPluginConfig config, Color color, IconData iconDaga,
|
||||
int quarterTurns, bool previous) {
|
||||
return new GestureDetector(
|
||||
return GestureDetector(
|
||||
behavior: HitTestBehavior.opaque,
|
||||
onTap: () {
|
||||
if (previous) {
|
||||
@@ -1052,7 +1048,7 @@ class SwiperControl extends SwiperPlugin {
|
||||
);
|
||||
}
|
||||
|
||||
return new Container(
|
||||
return SizedBox(
|
||||
height: double.infinity,
|
||||
child: child,
|
||||
width: double.infinity,
|
||||
@@ -1081,7 +1077,9 @@ class SwiperController extends IndexController {
|
||||
// this value is PageViewController.pos
|
||||
double pos;
|
||||
|
||||
// ignore: overridden_fields, annotate_overrides
|
||||
int index;
|
||||
// ignore: overridden_fields, annotate_overrides
|
||||
bool animation;
|
||||
bool autoplay;
|
||||
|
||||
@@ -1089,13 +1087,13 @@ class SwiperController extends IndexController {
|
||||
|
||||
void startAutoplay() {
|
||||
event = SwiperController.START_AUTOPLAY;
|
||||
this.autoplay = true;
|
||||
autoplay = true;
|
||||
notifyListeners();
|
||||
}
|
||||
|
||||
void stopAutoplay() {
|
||||
event = SwiperController.STOP_AUTOPLAY;
|
||||
this.autoplay = false;
|
||||
autoplay = false;
|
||||
notifyListeners();
|
||||
}
|
||||
}
|
||||
@@ -1117,10 +1115,10 @@ class FractionPaginationBuilder extends SwiperPlugin {
|
||||
|
||||
const FractionPaginationBuilder(
|
||||
{this.color,
|
||||
this.fontSize: 20.0,
|
||||
this.fontSize = 20.0,
|
||||
this.key,
|
||||
this.activeColor,
|
||||
this.activeFontSize: 35.0});
|
||||
this.activeFontSize = 35.0});
|
||||
|
||||
@override
|
||||
Widget build(BuildContext context, SwiperPluginConfig config) {
|
||||
@@ -1129,34 +1127,34 @@ class FractionPaginationBuilder extends SwiperPlugin {
|
||||
Color color = this.color ?? themeData.scaffoldBackgroundColor;
|
||||
|
||||
if (Axis.vertical == config.scrollDirection) {
|
||||
return new Column(
|
||||
return Column(
|
||||
key: key,
|
||||
mainAxisSize: MainAxisSize.min,
|
||||
children: <Widget>[
|
||||
new Text(
|
||||
Text(
|
||||
"${config.activeIndex + 1}",
|
||||
style: TextStyle(color: activeColor, fontSize: activeFontSize),
|
||||
),
|
||||
new Text(
|
||||
Text(
|
||||
"/",
|
||||
style: TextStyle(color: color, fontSize: fontSize),
|
||||
),
|
||||
new Text(
|
||||
Text(
|
||||
"${config.itemCount}",
|
||||
style: TextStyle(color: color, fontSize: fontSize),
|
||||
)
|
||||
],
|
||||
);
|
||||
} else {
|
||||
return new Row(
|
||||
return Row(
|
||||
key: key,
|
||||
mainAxisSize: MainAxisSize.min,
|
||||
children: <Widget>[
|
||||
new Text(
|
||||
Text(
|
||||
"${config.activeIndex + 1}",
|
||||
style: TextStyle(color: activeColor, fontSize: activeFontSize),
|
||||
),
|
||||
new Text(
|
||||
Text(
|
||||
" / ${config.itemCount}",
|
||||
style: TextStyle(color: color, fontSize: fontSize),
|
||||
)
|
||||
@@ -1188,9 +1186,9 @@ class RectSwiperPaginationBuilder extends SwiperPlugin {
|
||||
{this.activeColor,
|
||||
this.color,
|
||||
this.key,
|
||||
this.size: const Size(10.0, 2.0),
|
||||
this.activeSize: const Size(10.0, 2.0),
|
||||
this.space: 3.0});
|
||||
this.size = const Size(10.0, 2.0),
|
||||
this.activeSize = const Size(10.0, 2.0),
|
||||
this.space = 3.0});
|
||||
|
||||
@override
|
||||
Widget build(BuildContext context, SwiperPluginConfig config) {
|
||||
@@ -1201,6 +1199,7 @@ class RectSwiperPaginationBuilder extends SwiperPlugin {
|
||||
List<Widget> list = [];
|
||||
|
||||
if (config.itemCount > 20) {
|
||||
// ignore: avoid_print
|
||||
print(
|
||||
"The itemCount is too big, we suggest use FractionPaginationBuilder instead of DotSwiperPaginationBuilder in this sitituation");
|
||||
}
|
||||
@@ -1210,7 +1209,7 @@ class RectSwiperPaginationBuilder extends SwiperPlugin {
|
||||
|
||||
for (int i = 0; i < itemCount; ++i) {
|
||||
bool active = i == activeIndex;
|
||||
Size size = active ? this.activeSize : this.size;
|
||||
Size size = active ? activeSize : this.size;
|
||||
list.add(SizedBox(
|
||||
width: size.width,
|
||||
height: size.height,
|
||||
@@ -1223,13 +1222,13 @@ class RectSwiperPaginationBuilder extends SwiperPlugin {
|
||||
}
|
||||
|
||||
if (config.scrollDirection == Axis.vertical) {
|
||||
return new Column(
|
||||
return Column(
|
||||
key: key,
|
||||
mainAxisSize: MainAxisSize.min,
|
||||
children: list,
|
||||
);
|
||||
} else {
|
||||
return new Row(
|
||||
return Row(
|
||||
key: key,
|
||||
mainAxisSize: MainAxisSize.min,
|
||||
children: list,
|
||||
@@ -1260,13 +1259,14 @@ class DotSwiperPaginationBuilder extends SwiperPlugin {
|
||||
{this.activeColor,
|
||||
this.color,
|
||||
this.key,
|
||||
this.size: 10.0,
|
||||
this.activeSize: 10.0,
|
||||
this.space: 3.0});
|
||||
this.size = 10.0,
|
||||
this.activeSize = 10.0,
|
||||
this.space = 3.0});
|
||||
|
||||
@override
|
||||
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");
|
||||
}
|
||||
@@ -1281,7 +1281,7 @@ class DotSwiperPaginationBuilder extends SwiperPlugin {
|
||||
|
||||
if (config.indicatorLayout != PageIndicatorLayout.NONE &&
|
||||
config.layout == SwiperLayout.DEFAULT) {
|
||||
return new PageIndicator(
|
||||
return PageIndicator(
|
||||
count: config.itemCount,
|
||||
controller: config.pageController,
|
||||
layout: config.indicatorLayout,
|
||||
@@ -1313,13 +1313,13 @@ class DotSwiperPaginationBuilder extends SwiperPlugin {
|
||||
}
|
||||
|
||||
if (config.scrollDirection == Axis.vertical) {
|
||||
return new Column(
|
||||
return Column(
|
||||
key: key,
|
||||
mainAxisSize: MainAxisSize.min,
|
||||
children: list,
|
||||
);
|
||||
} else {
|
||||
return new Row(
|
||||
return Row(
|
||||
key: key,
|
||||
mainAxisSize: MainAxisSize.min,
|
||||
children: list,
|
||||
@@ -1328,7 +1328,7 @@ class DotSwiperPaginationBuilder extends SwiperPlugin {
|
||||
}
|
||||
}
|
||||
|
||||
typedef Widget SwiperPaginationBuilder(
|
||||
typedef SwiperPaginationBuilder = Widget Function(
|
||||
BuildContext context, SwiperPluginConfig config);
|
||||
|
||||
class SwiperCustomPagination extends SwiperPlugin {
|
||||
@@ -1344,12 +1344,12 @@ class SwiperCustomPagination extends SwiperPlugin {
|
||||
|
||||
class SwiperPagination extends SwiperPlugin {
|
||||
/// dot style pagination
|
||||
static const SwiperPlugin dots = const DotSwiperPaginationBuilder();
|
||||
static const SwiperPlugin dots = DotSwiperPaginationBuilder();
|
||||
|
||||
/// fraction style pagination
|
||||
static const SwiperPlugin fraction = const FractionPaginationBuilder();
|
||||
static const SwiperPlugin fraction = FractionPaginationBuilder();
|
||||
|
||||
static const SwiperPlugin rect = const RectSwiperPaginationBuilder();
|
||||
static const SwiperPlugin rect = RectSwiperPaginationBuilder();
|
||||
|
||||
/// Alignment.bottomCenter by default when scrollDirection== Axis.horizontal
|
||||
/// Alignment.centerRight by default when scrollDirection== Axis.vertical
|
||||
@@ -1366,9 +1366,10 @@ class SwiperPagination extends SwiperPlugin {
|
||||
const SwiperPagination(
|
||||
{this.alignment,
|
||||
this.key,
|
||||
this.margin: const EdgeInsets.all(10.0),
|
||||
this.builder: SwiperPagination.dots});
|
||||
this.margin = const EdgeInsets.all(10.0),
|
||||
this.builder = SwiperPagination.dots});
|
||||
|
||||
@override
|
||||
Widget build(BuildContext context, SwiperPluginConfig config) {
|
||||
Alignment alignment = this.alignment ??
|
||||
(config.scrollDirection == Axis.horizontal
|
||||
@@ -1376,10 +1377,10 @@ class SwiperPagination extends SwiperPlugin {
|
||||
: Alignment.centerRight);
|
||||
Widget child = Container(
|
||||
margin: margin,
|
||||
child: this.builder.build(context, config),
|
||||
child: builder.build(context, config),
|
||||
);
|
||||
if (!config.outer) {
|
||||
child = new Align(
|
||||
child = Align(
|
||||
key: key,
|
||||
alignment: alignment,
|
||||
child: child,
|
||||
@@ -1413,8 +1414,8 @@ class SwiperPluginConfig {
|
||||
this.itemCount,
|
||||
this.indicatorLayout,
|
||||
this.outer,
|
||||
this.scrollDirection,
|
||||
this.controller,
|
||||
@required this.scrollDirection,
|
||||
@required this.controller,
|
||||
this.pageController,
|
||||
this.layout,
|
||||
this.loop})
|
||||
@@ -1446,7 +1447,7 @@ abstract class _CustomLayoutStateBase<T extends _SubSwiper> extends State<T>
|
||||
@override
|
||||
void initState() {
|
||||
if (widget.itemWidth == null) {
|
||||
throw new Exception(
|
||||
throw Exception(
|
||||
"==============\n\nwidget.itemWith must not be null when use stack layout.\n========\n");
|
||||
}
|
||||
|
||||
@@ -1456,8 +1457,8 @@ abstract class _CustomLayoutStateBase<T extends _SubSwiper> extends State<T>
|
||||
}
|
||||
|
||||
void _createAnimationController() {
|
||||
_animationController = new AnimationController(vsync: this, value: 0.5);
|
||||
Tween<double> tween = new Tween(begin: 0.0, end: 1.0);
|
||||
_animationController = AnimationController(vsync: this, value: 0.5);
|
||||
Tween<double> tween = Tween(begin: 0.0, end: 1.0);
|
||||
_animation = tween.animate(_animationController);
|
||||
}
|
||||
|
||||
@@ -1467,7 +1468,7 @@ abstract class _CustomLayoutStateBase<T extends _SubSwiper> extends State<T>
|
||||
super.didChangeDependencies();
|
||||
}
|
||||
|
||||
void _getSize(_) {
|
||||
void _getSize(dynamic _) {
|
||||
afterRender();
|
||||
}
|
||||
|
||||
@@ -1514,7 +1515,7 @@ abstract class _CustomLayoutStateBase<T extends _SubSwiper> extends State<T>
|
||||
Widget _buildItem(int i, int realIndex, double animationValue);
|
||||
|
||||
Widget _buildContainer(List<Widget> list) {
|
||||
return new Stack(
|
||||
return Stack(
|
||||
children: list,
|
||||
);
|
||||
}
|
||||
@@ -1534,13 +1535,13 @@ abstract class _CustomLayoutStateBase<T extends _SubSwiper> extends State<T>
|
||||
list.add(_buildItem(i, realIndex, animationValue));
|
||||
}
|
||||
|
||||
return new GestureDetector(
|
||||
return GestureDetector(
|
||||
behavior: HitTestBehavior.opaque,
|
||||
onPanStart: _onPanStart,
|
||||
onPanEnd: _onPanEnd,
|
||||
onPanUpdate: _onPanUpdate,
|
||||
child: new ClipRect(
|
||||
child: new Center(
|
||||
child: ClipRect(
|
||||
child: Center(
|
||||
child: _buildContainer(list),
|
||||
),
|
||||
),
|
||||
@@ -1550,9 +1551,9 @@ abstract class _CustomLayoutStateBase<T extends _SubSwiper> extends State<T>
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
if (_animationCount == null) {
|
||||
return new Container();
|
||||
return Container();
|
||||
}
|
||||
return new AnimatedBuilder(
|
||||
return AnimatedBuilder(
|
||||
animation: _animationController, builder: _buildAnimation);
|
||||
}
|
||||
|
||||
@@ -1561,23 +1562,25 @@ abstract class _CustomLayoutStateBase<T extends _SubSwiper> extends State<T>
|
||||
|
||||
bool _lockScroll = false;
|
||||
|
||||
void _move(double position, {int nextIndex}) async {
|
||||
Future<void> _move(double position, {int nextIndex}) async {
|
||||
if (_lockScroll) return;
|
||||
try {
|
||||
_lockScroll = true;
|
||||
await _animationController.animateTo(position,
|
||||
duration: new Duration(milliseconds: widget.duration),
|
||||
duration: Duration(milliseconds: widget.duration),
|
||||
curve: widget.curve);
|
||||
if (nextIndex != null) {
|
||||
widget.onIndexChanged(widget.getCorrectIndex(nextIndex));
|
||||
}
|
||||
} catch (e) {
|
||||
// ignore: avoid_print
|
||||
print(e);
|
||||
} finally {
|
||||
if (nextIndex != null) {
|
||||
try {
|
||||
_animationController.value = 0.5;
|
||||
} catch (e) {
|
||||
// ignore: avoid_print
|
||||
print(e);
|
||||
}
|
||||
|
||||
@@ -1616,7 +1619,7 @@ abstract class _CustomLayoutStateBase<T extends _SubSwiper> extends State<T>
|
||||
_move(0.0, nextIndex: nextIndex);
|
||||
break;
|
||||
case IndexController.MOVE:
|
||||
throw new Exception(
|
||||
throw Exception(
|
||||
"Custom layout does not support SwiperControllerEvent.MOVE_INDEX yet!");
|
||||
case SwiperController.STOP_AUTOPLAY:
|
||||
case SwiperController.START_AUTOPLAY:
|
||||
@@ -1711,7 +1714,7 @@ Offset _getOffsetValue(List<Offset> values, double animationValue, int index) {
|
||||
dy = dy - (dy - values[index - 1].dy) * (0.5 - animationValue) * 2.0;
|
||||
}
|
||||
}
|
||||
return new Offset(dx, dy);
|
||||
return Offset(dx, dy);
|
||||
}
|
||||
|
||||
abstract class TransformBuilder<T> {
|
||||
@@ -1722,21 +1725,24 @@ abstract class TransformBuilder<T> {
|
||||
|
||||
class ScaleTransformBuilder extends TransformBuilder<double> {
|
||||
final Alignment alignment;
|
||||
ScaleTransformBuilder({List<double> values, this.alignment: Alignment.center})
|
||||
ScaleTransformBuilder(
|
||||
{List<double> values, this.alignment = Alignment.center})
|
||||
: super(values: values);
|
||||
|
||||
@override
|
||||
Widget build(int i, double animationValue, Widget widget) {
|
||||
double s = _getValue(values, animationValue, i);
|
||||
return new Transform.scale(scale: s, child: widget);
|
||||
return Transform.scale(scale: s, child: widget);
|
||||
}
|
||||
}
|
||||
|
||||
class OpacityTransformBuilder extends TransformBuilder<double> {
|
||||
OpacityTransformBuilder({List<double> values}) : super(values: values);
|
||||
|
||||
@override
|
||||
Widget build(int i, double animationValue, Widget widget) {
|
||||
double v = _getValue(values, animationValue, i);
|
||||
return new Opacity(
|
||||
return Opacity(
|
||||
opacity: v,
|
||||
child: widget,
|
||||
);
|
||||
@@ -1746,9 +1752,10 @@ class OpacityTransformBuilder extends TransformBuilder<double> {
|
||||
class RotateTransformBuilder extends TransformBuilder<double> {
|
||||
RotateTransformBuilder({List<double> values}) : super(values: values);
|
||||
|
||||
@override
|
||||
Widget build(int i, double animationValue, Widget widget) {
|
||||
double v = _getValue(values, animationValue, i);
|
||||
return new Transform.rotate(
|
||||
return Transform.rotate(
|
||||
angle: v,
|
||||
child: widget,
|
||||
);
|
||||
@@ -1761,7 +1768,7 @@ class TranslateTransformBuilder extends TransformBuilder<Offset> {
|
||||
@override
|
||||
Widget build(int i, double animationValue, Widget widget) {
|
||||
Offset s = _getOffsetValue(values, animationValue, i);
|
||||
return new Transform.translate(
|
||||
return Transform.translate(
|
||||
offset: s,
|
||||
child: widget,
|
||||
);
|
||||
@@ -1773,27 +1780,26 @@ class CustomLayoutOption {
|
||||
final int startIndex;
|
||||
final int stateCount;
|
||||
|
||||
CustomLayoutOption({this.stateCount, this.startIndex})
|
||||
CustomLayoutOption({this.stateCount, @required this.startIndex})
|
||||
: assert(startIndex != null, stateCount != null);
|
||||
|
||||
CustomLayoutOption addOpacity(List<double> values) {
|
||||
builders.add(new OpacityTransformBuilder(values: values));
|
||||
builders.add(OpacityTransformBuilder(values: values));
|
||||
return this;
|
||||
}
|
||||
|
||||
CustomLayoutOption addTranslate(List<Offset> values) {
|
||||
builders.add(new TranslateTransformBuilder(values: values));
|
||||
builders.add(TranslateTransformBuilder(values: values));
|
||||
return this;
|
||||
}
|
||||
|
||||
CustomLayoutOption addScale(List<double> values, Alignment alignment) {
|
||||
builders
|
||||
.add(new ScaleTransformBuilder(values: values, alignment: alignment));
|
||||
builders.add(ScaleTransformBuilder(values: values, alignment: alignment));
|
||||
return this;
|
||||
}
|
||||
|
||||
CustomLayoutOption addRotate(List<double> values) {
|
||||
builders.add(new RotateTransformBuilder(values: values));
|
||||
builders.add(RotateTransformBuilder(values: values));
|
||||
return this;
|
||||
}
|
||||
}
|
||||
@@ -1801,8 +1807,8 @@ class CustomLayoutOption {
|
||||
class _CustomLayoutSwiper extends _SubSwiper {
|
||||
final CustomLayoutOption option;
|
||||
|
||||
_CustomLayoutSwiper(
|
||||
{this.option,
|
||||
const _CustomLayoutSwiper(
|
||||
{@required this.option,
|
||||
double itemWidth,
|
||||
bool loop,
|
||||
double itemHeight,
|
||||
@@ -1832,7 +1838,7 @@ class _CustomLayoutSwiper extends _SubSwiper {
|
||||
|
||||
@override
|
||||
State<StatefulWidget> createState() {
|
||||
return new _CustomLayoutState();
|
||||
return _CustomLayoutState();
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1855,7 +1861,7 @@ class _CustomLayoutState extends _CustomLayoutStateBase<_CustomLayoutSwiper> {
|
||||
Widget _buildItem(int index, int realIndex, double animationValue) {
|
||||
List<TransformBuilder> builders = widget.option.builders;
|
||||
|
||||
Widget child = new SizedBox(
|
||||
Widget child = SizedBox(
|
||||
width: widget.itemWidth ?? double.infinity,
|
||||
height: widget.itemHeight ?? double.infinity,
|
||||
child: widget.itemBuilder(context, realIndex));
|
||||
|
||||
@@ -1,7 +1,6 @@
|
||||
import 'package:flutter/material.dart';
|
||||
|
||||
import 'package:http/http.dart' as http;
|
||||
import 'dart:convert';
|
||||
import 'package:flutter/material.dart';
|
||||
import 'package:http/http.dart' as http;
|
||||
|
||||
import 'cook.dart';
|
||||
import 'flutter_swiper.dart';
|
||||
@@ -9,101 +8,107 @@ import 'flutter_swiper.dart';
|
||||
void main() => runApp(MyApp());
|
||||
|
||||
class MyApp extends StatelessWidget {
|
||||
Widget build(ct) {
|
||||
@override
|
||||
Widget build(context) {
|
||||
return MaterialApp(
|
||||
theme: ThemeData(
|
||||
brightness: Brightness.light,
|
||||
accentColor: Colors.red,
|
||||
iconTheme: IconThemeData(color: Colors.red)),
|
||||
iconTheme: const IconThemeData(color: Colors.red)),
|
||||
title: "Filipino Cuisine",
|
||||
home: Home());
|
||||
}
|
||||
}
|
||||
|
||||
class Home extends StatefulWidget {
|
||||
@override
|
||||
HState createState() => HState();
|
||||
}
|
||||
|
||||
class HState extends State<Home> {
|
||||
Map fd;
|
||||
Map fi;
|
||||
Map<String, dynamic> fd;
|
||||
Map<String, dynamic> fi;
|
||||
|
||||
@override
|
||||
void initState() {
|
||||
super.initState();
|
||||
getData();
|
||||
}
|
||||
|
||||
getData() async {
|
||||
http.Response r =
|
||||
await http.get('/data.json');
|
||||
fd = json.decode(r.body);
|
||||
setState(() => fi = fd['0']);
|
||||
Future<void> getData() async {
|
||||
http.Response r = await http.get('/data.json');
|
||||
fd = json.decode(r.body) as Map<String, dynamic>;
|
||||
setState(() => fi = fd['0'] as Map<String, dynamic>);
|
||||
}
|
||||
|
||||
Widget build(ct) {
|
||||
if (fd == null)
|
||||
@override
|
||||
Widget build(context) {
|
||||
if (fd == null) {
|
||||
return Container(
|
||||
color: Colors.white,
|
||||
child: Center(
|
||||
child: CircularProgressIndicator(),
|
||||
));
|
||||
var t = Theme.of(ct).textTheme;
|
||||
color: Colors.white,
|
||||
child: const Center(
|
||||
child: CircularProgressIndicator(),
|
||||
),
|
||||
);
|
||||
}
|
||||
var t = Theme.of(context).textTheme;
|
||||
return Scaffold(
|
||||
body: Column(
|
||||
children: <Widget>[
|
||||
Expanded(
|
||||
flex: 5,
|
||||
child: Swiper(
|
||||
onIndexChanged: (n) => setState(() => fi = fd['$n']),
|
||||
onIndexChanged: (n) =>
|
||||
setState(() => fi = fd['$n'] as Map<String, dynamic>),
|
||||
itemCount:
|
||||
fd.keys.where((key) => int.tryParse(key) != null).length,
|
||||
itemBuilder: (cx, i) {
|
||||
return Container(
|
||||
margin: EdgeInsets.only(top: 40, bottom: 24),
|
||||
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'],
|
||||
child: Image.asset(fd['$i']['pf'] as String,
|
||||
fit: BoxFit.cover)),
|
||||
));
|
||||
},
|
||||
viewportFraction: .85,
|
||||
scale: .9)),
|
||||
Text(fi['fn'],
|
||||
Text(fi['fn'] as String,
|
||||
style:
|
||||
t.headline2.copyWith(fontFamily: 'ark', color: Colors.black)),
|
||||
Container(
|
||||
child: Text(fi['cn'],
|
||||
child: Text(fi['cn'] as String,
|
||||
style: t.subtitle1.apply(color: Colors.red, fontFamily: 'opb')),
|
||||
margin: EdgeInsets.only(top: 10, bottom: 30),
|
||||
margin: const EdgeInsets.only(top: 10, bottom: 30),
|
||||
),
|
||||
Container(
|
||||
child: Text(fi['dc'],
|
||||
child: Text(fi['dc'] as String,
|
||||
textAlign: TextAlign.center,
|
||||
style: t.subtitle1.copyWith(fontFamily: 'opr')),
|
||||
margin: EdgeInsets.only(left: 10, right: 10)),
|
||||
margin: const EdgeInsets.only(left: 10, right: 10)),
|
||||
Expanded(
|
||||
flex: 2,
|
||||
child: ListView.builder(
|
||||
scrollDirection: Axis.horizontal,
|
||||
itemCount: fi['ig'].length,
|
||||
itemCount: fi['ig'].length as int,
|
||||
itemBuilder: (cx, i) {
|
||||
return Row(children: <Widget>[
|
||||
Container(
|
||||
margin: EdgeInsets.only(left: 10),
|
||||
margin: const EdgeInsets.only(left: 10),
|
||||
height: 60,
|
||||
child: Image.asset(fi['ig'][i]['p'],
|
||||
child: Image.asset(fi['ig'][i]['p'] as String,
|
||||
fit: BoxFit.contain)),
|
||||
Container(
|
||||
margin: EdgeInsets.only(left: 5, right: 10),
|
||||
margin: const EdgeInsets.only(left: 5, right: 10),
|
||||
child: Column(
|
||||
mainAxisAlignment: MainAxisAlignment.center,
|
||||
children: <Widget>[
|
||||
Text(fi['ig'][i]['n'],
|
||||
Text(fi['ig'][i]['n'] as String,
|
||||
style: t.subtitle2
|
||||
.copyWith(fontFamily: 'opb')),
|
||||
Text(fi['ig'][i]['c'],
|
||||
Text(fi['ig'][i]['c'] as String,
|
||||
style:
|
||||
t.caption.copyWith(fontFamily: 'opr'))
|
||||
]))
|
||||
@@ -113,23 +118,29 @@ class HState extends State<Home> {
|
||||
),
|
||||
floatingActionButtonLocation: FloatingActionButtonLocation.centerDocked,
|
||||
floatingActionButton: FloatingActionButton(
|
||||
child: Icon(Icons.restaurant_menu),
|
||||
onPressed: () => Navigator.push(
|
||||
ct,
|
||||
child: const Icon(Icons.restaurant_menu),
|
||||
onPressed: () => Navigator.push<void>(
|
||||
context,
|
||||
MaterialPageRoute(
|
||||
builder: (cx) => Cook(fi['in'], fi['pf'], fi['fn']))),
|
||||
builder: (cx) => Cook(
|
||||
fi['in'] as List<String>,
|
||||
fi['pf'] as String,
|
||||
fi['fn'] as String,
|
||||
))),
|
||||
),
|
||||
bottomNavigationBar: BottomAppBar(
|
||||
shape: CircularNotchedRectangle(),
|
||||
shape: const CircularNotchedRectangle(),
|
||||
notchMargin: 4.0,
|
||||
child: Row(
|
||||
mainAxisAlignment: MainAxisAlignment.spaceAround,
|
||||
children: <Widget>[
|
||||
IconButton(
|
||||
icon:
|
||||
Icon(fi['fv'] ? Icons.favorite : Icons.favorite_border),
|
||||
onPressed: () => setState(() => fi['fv'] = !fi['fv'])),
|
||||
IconButton(icon: Icon(Icons.share), onPressed: () {})
|
||||
icon: Icon(fi['fv'] as bool
|
||||
? Icons.favorite
|
||||
: Icons.favorite_border),
|
||||
onPressed: () =>
|
||||
setState(() => fi['fv'] = !(fi['fv'] as bool))),
|
||||
IconButton(icon: const Icon(Icons.share), onPressed: () {})
|
||||
])),
|
||||
);
|
||||
}
|
||||
|
||||
@@ -7,37 +7,40 @@ import 'package:flutter/foundation.dart';
|
||||
import 'package:flutter/widgets.dart';
|
||||
|
||||
class IndexController extends ChangeNotifier {
|
||||
// ignore: constant_identifier_names
|
||||
static const int NEXT = 1;
|
||||
// ignore: constant_identifier_names
|
||||
static const int PREVIOUS = -1;
|
||||
// ignore: constant_identifier_names
|
||||
static const int MOVE = 0;
|
||||
|
||||
Completer _completer;
|
||||
Completer<void> _completer;
|
||||
|
||||
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;
|
||||
this.event = MOVE;
|
||||
_completer = new Completer();
|
||||
event = MOVE;
|
||||
_completer = Completer();
|
||||
notifyListeners();
|
||||
return _completer.future;
|
||||
}
|
||||
|
||||
Future next({bool animation: true}) {
|
||||
this.event = NEXT;
|
||||
Future next({bool animation = true}) {
|
||||
event = NEXT;
|
||||
this.animation = animation ?? true;
|
||||
_completer = new Completer();
|
||||
_completer = Completer();
|
||||
notifyListeners();
|
||||
return _completer.future;
|
||||
}
|
||||
|
||||
Future previous({bool animation: true}) {
|
||||
this.event = PREVIOUS;
|
||||
Future previous({bool animation = true}) {
|
||||
event = PREVIOUS;
|
||||
this.animation = animation ?? true;
|
||||
_completer = new Completer();
|
||||
_completer = Completer();
|
||||
notifyListeners();
|
||||
return _completer.future;
|
||||
}
|
||||
@@ -49,7 +52,7 @@ class IndexController extends ChangeNotifier {
|
||||
}
|
||||
}
|
||||
|
||||
typedef void PaintCallback(Canvas canvas, Size siz);
|
||||
typedef PaintCallback = void Function(Canvas canvas, Size siz);
|
||||
|
||||
class ColorPainter extends CustomPainter {
|
||||
final Paint _paint;
|
||||
@@ -62,8 +65,7 @@ class ColorPainter extends CustomPainter {
|
||||
void paint(Canvas canvas, Size size) {
|
||||
int index = info.fromIndex;
|
||||
_paint.color = colors[index];
|
||||
canvas.drawRect(
|
||||
new 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) {
|
||||
return;
|
||||
}
|
||||
@@ -85,9 +87,9 @@ class ColorPainter extends CustomPainter {
|
||||
}
|
||||
alpha = (0xff * opacity).toInt();
|
||||
|
||||
_paint.color = new Color((alpha << 24) | color);
|
||||
_paint.color = Color((alpha << 24) | color);
|
||||
canvas.drawRect(
|
||||
new Rect.fromLTWH(0.0, 0.0, size.width, size.height), _paint);
|
||||
Rect.fromLTWH(0.0, 0.0, size.width, size.height), _paint);
|
||||
}
|
||||
} else {
|
||||
if (index > 0) {
|
||||
@@ -103,9 +105,9 @@ class ColorPainter extends CustomPainter {
|
||||
}
|
||||
alpha = (0xff * opacity).toInt();
|
||||
|
||||
_paint.color = new Color((alpha << 24) | color);
|
||||
_paint.color = Color((alpha << 24) | color);
|
||||
canvas.drawRect(
|
||||
new Rect.fromLTWH(0.0, 0.0, size.width, size.height), _paint);
|
||||
Rect.fromLTWH(0.0, 0.0, size.width, size.height), _paint);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -117,12 +119,12 @@ class ColorPainter extends CustomPainter {
|
||||
}
|
||||
|
||||
class _ParallaxColorState extends State<ParallaxColor> {
|
||||
Paint paint = new Paint();
|
||||
Paint paint = Paint();
|
||||
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
return new CustomPaint(
|
||||
painter: new ColorPainter(paint, widget.info, widget.colors),
|
||||
return CustomPaint(
|
||||
painter: ColorPainter(paint, widget.info, widget.colors),
|
||||
child: widget.child,
|
||||
);
|
||||
}
|
||||
@@ -135,7 +137,7 @@ class ParallaxColor extends StatefulWidget {
|
||||
|
||||
final TransformInfo info;
|
||||
|
||||
ParallaxColor({
|
||||
const ParallaxColor({
|
||||
@required this.colors,
|
||||
@required this.info,
|
||||
@required this.child,
|
||||
@@ -143,7 +145,7 @@ class ParallaxColor extends StatefulWidget {
|
||||
|
||||
@override
|
||||
State<StatefulWidget> createState() {
|
||||
return new _ParallaxColorState();
|
||||
return _ParallaxColorState();
|
||||
}
|
||||
}
|
||||
|
||||
@@ -153,20 +155,20 @@ class ParallaxContainer extends StatelessWidget {
|
||||
final double translationFactor;
|
||||
final double opacityFactor;
|
||||
|
||||
ParallaxContainer(
|
||||
const ParallaxContainer(
|
||||
{@required this.child,
|
||||
@required this.position,
|
||||
this.translationFactor: 100.0,
|
||||
this.opacityFactor: 1.0})
|
||||
this.translationFactor = 100.0,
|
||||
this.opacityFactor = 1.0})
|
||||
: assert(position != null),
|
||||
assert(translationFactor != null);
|
||||
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
return Opacity(
|
||||
opacity: (1 - position.abs()).clamp(0.0, 1.0) * opacityFactor,
|
||||
child: new Transform.translate(
|
||||
offset: new Offset(position * translationFactor, 0.0),
|
||||
opacity: (1 - position.abs()).clamp(0.0, 1.0) * opacityFactor as double,
|
||||
child: Transform.translate(
|
||||
offset: Offset(position * translationFactor, 0.0),
|
||||
child: child,
|
||||
),
|
||||
);
|
||||
@@ -177,7 +179,7 @@ class ParallaxImage extends StatelessWidget {
|
||||
final Image image;
|
||||
final double imageFactor;
|
||||
|
||||
ParallaxImage.asset(String name, {double position, this.imageFactor: 0.3})
|
||||
ParallaxImage.asset(String name, {double position, this.imageFactor = 0.3})
|
||||
: assert(imageFactor != null),
|
||||
image = Image.asset(name,
|
||||
fit: BoxFit.cover,
|
||||
@@ -262,18 +264,19 @@ abstract class PageTransformer {
|
||||
///
|
||||
final bool reverse;
|
||||
|
||||
PageTransformer({this.reverse: false});
|
||||
PageTransformer({this.reverse = false});
|
||||
|
||||
/// Return a transformed widget, based on child and TransformInfo
|
||||
Widget transform(Widget child, TransformInfo info);
|
||||
}
|
||||
|
||||
typedef Widget PageTransformerBuilderCallback(Widget child, TransformInfo info);
|
||||
typedef PageTransformerBuilderCallback = Widget Function(
|
||||
Widget child, TransformInfo info);
|
||||
|
||||
class PageTransformerBuilder extends PageTransformer {
|
||||
final PageTransformerBuilderCallback builder;
|
||||
|
||||
PageTransformerBuilder({bool reverse: false, @required this.builder})
|
||||
PageTransformerBuilder({bool reverse = false, @required this.builder})
|
||||
: assert(builder != null),
|
||||
super(reverse: reverse);
|
||||
|
||||
@@ -292,16 +295,16 @@ class TransformerPageController extends PageController {
|
||||
int initialPage = 0,
|
||||
bool keepPage = true,
|
||||
double viewportFraction = 1.0,
|
||||
this.loop: false,
|
||||
this.loop = false,
|
||||
this.itemCount,
|
||||
this.reverse: false,
|
||||
this.reverse = false,
|
||||
}) : super(
|
||||
initialPage: TransformerPageController._getRealIndexFromRenderIndex(
|
||||
initialPage ?? 0, loop, itemCount, reverse),
|
||||
keepPage: keepPage,
|
||||
viewportFraction: viewportFraction);
|
||||
|
||||
int getRenderIndexFromRealIndex(num index) {
|
||||
int getRenderIndexFromRealIndex(int index) {
|
||||
return _getRenderIndexFromRealIndex(index, loop, itemCount, reverse);
|
||||
}
|
||||
|
||||
@@ -310,8 +313,8 @@ class TransformerPageController extends PageController {
|
||||
return loop ? itemCount + kMaxValue : itemCount;
|
||||
}
|
||||
|
||||
static _getRenderIndexFromRealIndex(
|
||||
num index, bool loop, int itemCount, bool reverse) {
|
||||
static int _getRenderIndexFromRealIndex(
|
||||
int index, bool loop, int itemCount, bool reverse) {
|
||||
if (itemCount == 0) return 0;
|
||||
int renderIndex;
|
||||
if (loop) {
|
||||
@@ -341,7 +344,7 @@ class TransformerPageController extends PageController {
|
||||
return page;
|
||||
}
|
||||
|
||||
static _getRenderPageFromRealPage(
|
||||
static double _getRenderPageFromRealPage(
|
||||
double page, bool loop, int itemCount, bool reverse) {
|
||||
double renderPage;
|
||||
if (loop) {
|
||||
@@ -360,18 +363,19 @@ class TransformerPageController extends PageController {
|
||||
return renderPage;
|
||||
}
|
||||
|
||||
@override
|
||||
double get page {
|
||||
return loop
|
||||
? _getRenderPageFromRealPage(realPage, loop, itemCount, reverse)
|
||||
: realPage;
|
||||
}
|
||||
|
||||
int getRealIndexFromRenderIndex(num index) {
|
||||
int getRealIndexFromRenderIndex(int index) {
|
||||
return _getRealIndexFromRenderIndex(index, loop, itemCount, reverse);
|
||||
}
|
||||
|
||||
static int _getRealIndexFromRenderIndex(
|
||||
num index, bool loop, int itemCount, bool reverse) {
|
||||
int index, bool loop, int itemCount, bool reverse) {
|
||||
int result = reverse ? (itemCount - index - 1) : index;
|
||||
if (loop) {
|
||||
result += kMiddleValue;
|
||||
@@ -439,13 +443,13 @@ class TransformerPageView extends StatefulWidget {
|
||||
///
|
||||
/// [itemBuilder] will be called only with indices greater than or equal to
|
||||
/// zero and less than [itemCount].
|
||||
TransformerPageView({
|
||||
const TransformerPageView({
|
||||
Key key,
|
||||
this.index,
|
||||
Duration duration,
|
||||
this.curve: Curves.ease,
|
||||
this.viewportFraction: 1.0,
|
||||
this.loop: false,
|
||||
this.curve = Curves.ease,
|
||||
this.viewportFraction = 1.0,
|
||||
this.loop = false,
|
||||
this.scrollDirection = Axis.horizontal,
|
||||
this.physics,
|
||||
this.pageSnapping = true,
|
||||
@@ -457,17 +461,17 @@ class TransformerPageView extends StatefulWidget {
|
||||
@required this.itemCount,
|
||||
}) : assert(itemCount != null),
|
||||
assert(itemCount == 0 || itemBuilder != null || transformer != null),
|
||||
this.duration =
|
||||
duration ?? new Duration(milliseconds: kDefaultTransactionDuration),
|
||||
duration = duration ??
|
||||
const Duration(milliseconds: kDefaultTransactionDuration),
|
||||
super(key: key);
|
||||
|
||||
factory TransformerPageView.children(
|
||||
{Key key,
|
||||
int index,
|
||||
Duration duration,
|
||||
Curve curve: Curves.ease,
|
||||
double viewportFraction: 1.0,
|
||||
bool loop: false,
|
||||
Curve curve = Curves.ease,
|
||||
double viewportFraction = 1.0,
|
||||
bool loop = false,
|
||||
Axis scrollDirection = Axis.horizontal,
|
||||
ScrollPhysics physics,
|
||||
bool pageSnapping = true,
|
||||
@@ -477,9 +481,9 @@ class TransformerPageView extends StatefulWidget {
|
||||
@required List<Widget> children,
|
||||
TransformerPageController pageController}) {
|
||||
assert(children != null);
|
||||
return new TransformerPageView(
|
||||
return TransformerPageView(
|
||||
itemCount: children.length,
|
||||
itemBuilder: (BuildContext context, int index) {
|
||||
itemBuilder: (context, index) {
|
||||
return children[index];
|
||||
},
|
||||
pageController: pageController,
|
||||
@@ -499,7 +503,7 @@ class TransformerPageView extends StatefulWidget {
|
||||
|
||||
@override
|
||||
State<StatefulWidget> createState() {
|
||||
return new _TransformerPageViewState();
|
||||
return _TransformerPageViewState();
|
||||
}
|
||||
|
||||
static int getRealIndexFromRenderIndex(
|
||||
@@ -517,7 +521,7 @@ class TransformerPageView extends StatefulWidget {
|
||||
int itemCount,
|
||||
bool loop,
|
||||
double viewportFraction}) {
|
||||
return new PageController(
|
||||
return PageController(
|
||||
initialPage: getRealIndexFromRenderIndex(
|
||||
reverse: reverse, index: index, itemCount: itemCount, loop: loop),
|
||||
viewportFraction: viewportFraction);
|
||||
@@ -544,19 +548,17 @@ class _TransformerPageViewState extends State<TransformerPageView> {
|
||||
}
|
||||
|
||||
Widget _buildItem(BuildContext context, int index) {
|
||||
return new AnimatedBuilder(
|
||||
return AnimatedBuilder(
|
||||
animation: _pageController,
|
||||
builder: (BuildContext c, Widget w) {
|
||||
builder: (c, w) {
|
||||
int renderIndex = _pageController.getRenderIndexFromRealIndex(index);
|
||||
Widget child;
|
||||
if (widget.itemBuilder != null) {
|
||||
child = widget.itemBuilder(context, renderIndex);
|
||||
}
|
||||
if (child == null) {
|
||||
child = new Container();
|
||||
}
|
||||
child ??= Container();
|
||||
if (_size == null) {
|
||||
return child ?? new Container();
|
||||
return child ?? Container();
|
||||
}
|
||||
|
||||
double position;
|
||||
@@ -570,11 +572,11 @@ class _TransformerPageViewState extends State<TransformerPageView> {
|
||||
}
|
||||
position *= widget.viewportFraction;
|
||||
|
||||
TransformInfo info = new TransformInfo(
|
||||
TransformInfo info = TransformInfo(
|
||||
index: renderIndex,
|
||||
width: _size.width,
|
||||
height: _size.height,
|
||||
position: position.clamp(-1.0, 1.0),
|
||||
position: position.clamp(-1.0, 1.0) as double,
|
||||
activeIndex:
|
||||
_pageController.getRenderIndexFromRealIndex(_activeIndex),
|
||||
fromIndex: _fromIndex,
|
||||
@@ -600,7 +602,7 @@ class _TransformerPageViewState extends State<TransformerPageView> {
|
||||
Widget build(BuildContext context) {
|
||||
IndexedWidgetBuilder builder =
|
||||
_transformer == null ? _buildItemNormal : _buildItem;
|
||||
Widget child = new PageView.builder(
|
||||
Widget child = PageView.builder(
|
||||
itemBuilder: builder,
|
||||
itemCount: _pageController.getRealItemCount(),
|
||||
onPageChanged: _onIndexChanged,
|
||||
@@ -613,7 +615,8 @@ class _TransformerPageViewState extends State<TransformerPageView> {
|
||||
if (_transformer == null) {
|
||||
return child;
|
||||
}
|
||||
return new NotificationListener(
|
||||
return NotificationListener(
|
||||
// ignore: avoid_types_on_closure_parameters
|
||||
onNotification: (ScrollNotification notification) {
|
||||
if (notification is ScrollStartNotification) {
|
||||
_calcCurrentPixels();
|
||||
@@ -637,7 +640,7 @@ class _TransformerPageViewState extends State<TransformerPageView> {
|
||||
}
|
||||
}
|
||||
|
||||
void _onGetSize(_) {
|
||||
void _onGetSize(dynamic _) {
|
||||
Size size;
|
||||
if (context == null) {
|
||||
onGetSize(size);
|
||||
@@ -667,14 +670,12 @@ class _TransformerPageViewState extends State<TransformerPageView> {
|
||||
_transformer = widget.transformer;
|
||||
// int index = widget.index ?? 0;
|
||||
_pageController = widget.pageController;
|
||||
if (_pageController == null) {
|
||||
_pageController = new TransformerPageController(
|
||||
initialPage: widget.index,
|
||||
itemCount: widget.itemCount,
|
||||
loop: widget.loop,
|
||||
reverse:
|
||||
widget.transformer == null ? false : widget.transformer.reverse);
|
||||
}
|
||||
_pageController ??= TransformerPageController(
|
||||
initialPage: widget.index,
|
||||
itemCount: widget.itemCount,
|
||||
loop: widget.loop,
|
||||
reverse:
|
||||
widget.transformer == null ? false : widget.transformer.reverse);
|
||||
// int initPage = _getRealIndexFromRenderIndex(index);
|
||||
// _pageController = new PageController(initialPage: initPage,viewportFraction: widget.viewportFraction);
|
||||
_fromIndex = _activeIndex = _pageController.initialPage;
|
||||
@@ -696,7 +697,7 @@ class _TransformerPageViewState extends State<TransformerPageView> {
|
||||
_pageController = widget.pageController;
|
||||
} else {
|
||||
created = true;
|
||||
_pageController = new TransformerPageController(
|
||||
_pageController = TransformerPageController(
|
||||
initialPage: widget.index,
|
||||
itemCount: widget.itemCount,
|
||||
loop: widget.loop,
|
||||
@@ -714,8 +715,9 @@ class _TransformerPageViewState extends State<TransformerPageView> {
|
||||
duration: widget.duration, curve: widget.curve);
|
||||
}
|
||||
}
|
||||
if (_transformer != null)
|
||||
if (_transformer != null) {
|
||||
WidgetsBinding.instance.addPostFrameCallback(_onGetSize);
|
||||
}
|
||||
|
||||
if (_controller != getNotifier()) {
|
||||
if (_controller != null) {
|
||||
@@ -731,8 +733,9 @@ class _TransformerPageViewState extends State<TransformerPageView> {
|
||||
|
||||
@override
|
||||
void didChangeDependencies() {
|
||||
if (_transformer != null)
|
||||
if (_transformer != null) {
|
||||
WidgetsBinding.instance.addPostFrameCallback(_onGetSize);
|
||||
}
|
||||
super.didChangeDependencies();
|
||||
}
|
||||
|
||||
@@ -800,6 +803,7 @@ class _TransformerPageViewState extends State<TransformerPageView> {
|
||||
|
||||
ChangeNotifier _controller;
|
||||
|
||||
@override
|
||||
void dispose() {
|
||||
super.dispose();
|
||||
if (_controller != null) {
|
||||
|
||||
@@ -7,7 +7,7 @@ packages:
|
||||
name: characters
|
||||
url: "https://pub.dartlang.org"
|
||||
source: hosted
|
||||
version: "1.1.0-nullsafety.5"
|
||||
version: "1.1.0"
|
||||
charcode:
|
||||
dependency: transitive
|
||||
description:
|
||||
@@ -21,12 +21,19 @@ packages:
|
||||
name: collection
|
||||
url: "https://pub.dartlang.org"
|
||||
source: hosted
|
||||
version: "1.15.0-nullsafety.5"
|
||||
version: "1.15.0"
|
||||
flutter:
|
||||
dependency: "direct main"
|
||||
description: flutter
|
||||
source: sdk
|
||||
version: "0.0.0"
|
||||
flutter_lints:
|
||||
dependency: "direct dev"
|
||||
description:
|
||||
name: flutter_lints
|
||||
url: "https://pub.dartlang.org"
|
||||
source: hosted
|
||||
version: "1.0.3"
|
||||
flutter_page_indicator:
|
||||
dependency: transitive
|
||||
description:
|
||||
@@ -55,13 +62,20 @@ packages:
|
||||
url: "https://pub.dartlang.org"
|
||||
source: hosted
|
||||
version: "3.1.4"
|
||||
lints:
|
||||
dependency: transitive
|
||||
description:
|
||||
name: lints
|
||||
url: "https://pub.dartlang.org"
|
||||
source: hosted
|
||||
version: "1.0.1"
|
||||
meta:
|
||||
dependency: transitive
|
||||
description:
|
||||
name: meta
|
||||
url: "https://pub.dartlang.org"
|
||||
source: hosted
|
||||
version: "1.3.0-nullsafety.6"
|
||||
version: "1.3.0"
|
||||
path:
|
||||
dependency: transitive
|
||||
description:
|
||||
@@ -70,7 +84,7 @@ packages:
|
||||
source: hosted
|
||||
version: "1.7.0"
|
||||
pedantic:
|
||||
dependency: "direct dev"
|
||||
dependency: transitive
|
||||
description:
|
||||
name: pedantic
|
||||
url: "https://pub.dartlang.org"
|
||||
@@ -115,14 +129,14 @@ packages:
|
||||
name: typed_data
|
||||
url: "https://pub.dartlang.org"
|
||||
source: hosted
|
||||
version: "1.3.0-nullsafety.5"
|
||||
version: "1.3.0"
|
||||
vector_math:
|
||||
dependency: transitive
|
||||
description:
|
||||
name: vector_math
|
||||
url: "https://pub.dartlang.org"
|
||||
source: hosted
|
||||
version: "2.1.0-nullsafety.5"
|
||||
version: "2.1.0"
|
||||
sdks:
|
||||
dart: ">=2.12.0-0 <3.0.0"
|
||||
dart: ">=2.12.0 <3.0.0"
|
||||
flutter: ">=0.1.4"
|
||||
|
||||
@@ -10,8 +10,7 @@ dependencies:
|
||||
http: ^0.12.0
|
||||
|
||||
dev_dependencies:
|
||||
pedantic: ^1.9.0
|
||||
|
||||
flutter_lints: ^1.0.0
|
||||
|
||||
flutter_icons:
|
||||
android: "launcher_icon"
|
||||
@@ -64,4 +63,4 @@ flutter:
|
||||
- asset: fonts/OpenSans-Bold.ttf
|
||||
- family: ark
|
||||
fonts:
|
||||
- asset: fonts/Arkipelago.otf
|
||||
- asset: fonts/Arkipelago.otf
|
||||
|
||||
@@ -1,14 +1,22 @@
|
||||
# Defines a default set of lint rules enforced for
|
||||
# projects at Google. For details and rationale,
|
||||
# see https://github.com/dart-lang/pedantic#enabled-lints.
|
||||
include: package:pedantic/analysis_options.yaml
|
||||
|
||||
# For lint rules and documentation, see http://dart-lang.github.io/linter/lints.
|
||||
# Uncomment to specify additional rules.
|
||||
# linter:
|
||||
# rules:
|
||||
# - camel_case_types
|
||||
include: package:flutter_lints/flutter.yaml
|
||||
|
||||
analyzer:
|
||||
# exclude:
|
||||
# - path/to/excluded/files/**
|
||||
exclude:
|
||||
- lib/src/data.g.dart
|
||||
strong-mode:
|
||||
implicit-casts: false
|
||||
implicit-dynamic: false
|
||||
|
||||
linter:
|
||||
rules:
|
||||
avoid_types_on_closure_parameters: true
|
||||
avoid_void_async: true
|
||||
cancel_subscriptions: true
|
||||
close_sinks: true
|
||||
directives_ordering: true
|
||||
package_api_docs: true
|
||||
package_prefixed_library_names: true
|
||||
test_types_in_equals: true
|
||||
throw_in_finally: true
|
||||
unnecessary_statements: true
|
||||
use_key_in_widget_constructors: false
|
||||
|
||||
@@ -15,7 +15,7 @@ class CookbookScraper {
|
||||
WebDriver _driver;
|
||||
|
||||
Future init() async {
|
||||
_driver = await createDriver(desired: {});
|
||||
_driver = await createDriver(desired: <String, dynamic>{});
|
||||
}
|
||||
|
||||
Future dispose() async {
|
||||
|
||||
@@ -4,9 +4,9 @@
|
||||
|
||||
import 'dart:convert';
|
||||
import 'dart:io';
|
||||
import 'package:checked_yaml/checked_yaml.dart';
|
||||
|
||||
import 'src/data.dart';
|
||||
import 'package:checked_yaml/checked_yaml.dart';
|
||||
|
||||
export 'src/data.dart';
|
||||
|
||||
@@ -17,6 +17,7 @@ Future<List<Sample>> getSamples() async {
|
||||
var cookbookContents = await cookbookFile.readAsString();
|
||||
var index = checkedYamlDecode(contents, (m) => Index.fromJson(m),
|
||||
sourceUrl: yamlFile.uri);
|
||||
var cookbookIndex = Index.fromJson(json.decode(cookbookContents));
|
||||
var cookbookIndex =
|
||||
Index.fromJson(json.decode(cookbookContents) as Map<dynamic, dynamic>);
|
||||
return index.samples..addAll(cookbookIndex.samples);
|
||||
}
|
||||
|
||||
@@ -45,13 +45,14 @@ class Carousel {
|
||||
|
||||
// Move to the first slide after init
|
||||
// This is responsible for creating a smooth animation
|
||||
Future.delayed(Duration(milliseconds: 500)).then((value) => _slideRight());
|
||||
Future<void>.delayed(const Duration(milliseconds: 500))
|
||||
.then((value) => _slideRight());
|
||||
}
|
||||
|
||||
void _hideSlides() {
|
||||
slides.forEach((s) {
|
||||
for (final s in slides) {
|
||||
s.classes.add('next-hidden');
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
void _initBullets() {
|
||||
@@ -95,7 +96,7 @@ class Carousel {
|
||||
|
||||
void _touchEndListener(TouchEvent e) {
|
||||
if (touched) {
|
||||
int dx = e.changedTouches.first.client.x - x0;
|
||||
int dx = (e.changedTouches.first.client.x - x0) as int;
|
||||
|
||||
// dx==0 case is ignored
|
||||
if (dx > 0 && currentSlideIndex > 0) {
|
||||
@@ -167,11 +168,11 @@ class Carousel {
|
||||
nextSlide = slides[0];
|
||||
}
|
||||
|
||||
slides.forEach((e) {
|
||||
for (final e in slides) {
|
||||
_removeSlideClasses([e]);
|
||||
if (e.classes.contains('prev-hidden')) e.classes.add('next-hidden');
|
||||
if (e.classes.contains('prev')) e.classes.add('prev-hidden');
|
||||
});
|
||||
}
|
||||
|
||||
_removeSlideClasses([prevSlide, currentSlide, nextSlide]);
|
||||
|
||||
@@ -203,11 +204,11 @@ class Carousel {
|
||||
prevSlide = slides[lastSlideIndex];
|
||||
}
|
||||
|
||||
slides.forEach((e) {
|
||||
for (final e in slides) {
|
||||
_removeSlideClasses([e]);
|
||||
if (e.classes.contains('next')) e.classes.add('next-hidden');
|
||||
if (e.classes.contains('next-hidden')) e.classes.add('prev-hidden');
|
||||
});
|
||||
}
|
||||
|
||||
_removeSlideClasses([prevSlide, currentSlide, nextSlide]);
|
||||
|
||||
@@ -218,7 +219,7 @@ class Carousel {
|
||||
_updateBullets();
|
||||
}
|
||||
|
||||
void _goToIndexSlide(index) {
|
||||
void _goToIndexSlide(int index) {
|
||||
final sliding =
|
||||
(currentSlideIndex < index) ? () => _slideRight() : () => _slideLeft();
|
||||
while (currentSlideIndex != index) {
|
||||
@@ -227,10 +228,10 @@ class Carousel {
|
||||
}
|
||||
|
||||
void _removeSlideClasses(List<Element> slides) {
|
||||
slides.forEach((s) {
|
||||
for (final s in slides) {
|
||||
s.classes
|
||||
.removeAll(['prev-hidden', 'prev', 'active', 'next', 'next-hidden']);
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
void _initArrowKeyControl() {
|
||||
|
||||
@@ -7,9 +7,9 @@ import 'data.dart';
|
||||
import 'util.dart' as util;
|
||||
|
||||
String _escapeAttribute(String s) =>
|
||||
HtmlEscape(HtmlEscapeMode.attribute).convert(s);
|
||||
const HtmlEscape(HtmlEscapeMode.attribute).convert(s);
|
||||
String _escapeElement(String s) =>
|
||||
HtmlEscape(HtmlEscapeMode.element).convert(s);
|
||||
const HtmlEscape(HtmlEscapeMode.element).convert(s);
|
||||
|
||||
String description(Sample sample) => '''
|
||||
<!DOCTYPE html>
|
||||
|
||||
@@ -4,7 +4,7 @@ homepage: https://github.com/flutter/samples_index
|
||||
author: Flutter Team <flutter-dev@googlegroups.com>
|
||||
version: 0.0.1
|
||||
environment:
|
||||
sdk: '>=2.5.0 <3.0.0'
|
||||
sdk: ">=2.5.0 <3.0.0"
|
||||
dependencies:
|
||||
json_annotation: ^3.0.0
|
||||
path: ^1.6.0
|
||||
@@ -16,7 +16,7 @@ dependencies:
|
||||
html: ^0.14.0
|
||||
dev_dependencies:
|
||||
grinder: ^0.8.3
|
||||
pedantic: ^1.9.0
|
||||
flutter_lints: ^1.0.0
|
||||
test: ^1.6.0
|
||||
json_serializable: ^3.2.0
|
||||
build: ^1.2.0
|
||||
|
||||
@@ -54,7 +54,7 @@ void main() {
|
||||
var sample = index.samples.first;
|
||||
expect(
|
||||
sample.searchAttributes.split(' '),
|
||||
containsAll([
|
||||
containsAll(const <String>[
|
||||
'kittens',
|
||||
'tag:beginner',
|
||||
'tag:kittens',
|
||||
|
||||
@@ -2,8 +2,8 @@
|
||||
// Use of this source code is governed by a BSD-style license that can be
|
||||
// found in the LICENSE file
|
||||
|
||||
import 'dart:io';
|
||||
import 'dart:convert';
|
||||
import 'dart:io';
|
||||
|
||||
import 'package:grinder/grinder.dart';
|
||||
import 'package:path/path.dart' as path;
|
||||
@@ -12,10 +12,11 @@ import 'package:samples_index/src/templates.dart' as templates;
|
||||
import 'package:samples_index/cookbook.dart';
|
||||
import 'package:image/image.dart' as image;
|
||||
|
||||
void main(args) => grind(args);
|
||||
Future<void> main(List<String> args) => grind(args);
|
||||
|
||||
@Task('Run tests in the VM')
|
||||
void testCli() async => await TestRunner().testAsync(platformSelector: 'vm');
|
||||
Future<void> testCli() async =>
|
||||
await TestRunner().testAsync(platformSelector: 'vm');
|
||||
|
||||
@Task()
|
||||
void analyze() {
|
||||
@@ -25,13 +26,13 @@ void analyze() {
|
||||
@Task('deploy')
|
||||
@Depends(analyze, testCli, generate, buildRelease)
|
||||
void deploy() {
|
||||
print('All tasks completed. ');
|
||||
print('');
|
||||
log('All tasks completed. ');
|
||||
log('');
|
||||
}
|
||||
|
||||
@Task('Run build_runner to public/ directory')
|
||||
@Depends(createThumbnails)
|
||||
Future buildRelease() async {
|
||||
Future<void> buildRelease() async {
|
||||
var app = PubApp.local('build_runner');
|
||||
await app.runAsync(
|
||||
'build --release --output web:public --delete-conflicting-outputs'
|
||||
@@ -41,9 +42,9 @@ Future buildRelease() async {
|
||||
|
||||
@DefaultTask('Build the project.')
|
||||
@Depends(clean)
|
||||
Future generate() async {
|
||||
Future<void> generate() async {
|
||||
var samples = await getSamples();
|
||||
print('Generating index for ${samples.length} samples...');
|
||||
log('Generating index for ${samples.length} samples...');
|
||||
var outputFile = File('web/index.html');
|
||||
await outputFile.create(recursive: true);
|
||||
await outputFile.writeAsString(templates.index(samples));
|
||||
@@ -55,12 +56,12 @@ Future generate() async {
|
||||
});
|
||||
futures.add(future);
|
||||
}
|
||||
await Future.wait(futures);
|
||||
print('Generated index for ${samples.length} samples.');
|
||||
await Future.wait<void>(futures);
|
||||
log('Generated index for ${samples.length} samples.');
|
||||
}
|
||||
|
||||
@Task('Scrape the cookbook for images and descriptions')
|
||||
Future scrapeCookbook() async {
|
||||
Future<void> scrapeCookbook() async {
|
||||
var driver = await Process.start(
|
||||
'chromedriver', ['--port=4444', '--url-base=wd/hub', '--verbose']);
|
||||
await driver.stdout.pipe(stdout);
|
||||
@@ -68,7 +69,7 @@ Future scrapeCookbook() async {
|
||||
var scraper = CookbookScraper();
|
||||
await scraper.init();
|
||||
var links = await scraper.fetchCookbookLinks();
|
||||
print('Scraping ${links.length} cookbook articles');
|
||||
log('Scraping ${links.length} cookbook articles');
|
||||
var allSamples = <Sample>[];
|
||||
for (var link in links) {
|
||||
allSamples.add(await scraper.getMetadata(link));
|
||||
@@ -76,23 +77,23 @@ Future scrapeCookbook() async {
|
||||
}
|
||||
var file = File('lib/src/cookbook.json');
|
||||
await file.create();
|
||||
var encoder = JsonEncoder.withIndent('\t');
|
||||
var encoder = const JsonEncoder.withIndent('\t');
|
||||
await file.writeAsString(encoder.convert(Index(allSamples)));
|
||||
await scraper.dispose();
|
||||
var killed = driver.kill();
|
||||
if (!killed) {
|
||||
print('failed to kill chromedriver process');
|
||||
log('failed to kill chromedriver process');
|
||||
}
|
||||
}
|
||||
|
||||
@Task('creates thumbnail images in web/images')
|
||||
Future createThumbnails() async {
|
||||
Future<void> createThumbnails() async {
|
||||
await _createThumbnails(Directory('web/images'));
|
||||
await _createThumbnails(Directory('web/images/cookbook'));
|
||||
}
|
||||
|
||||
// Creates a thumbnail image for each png file
|
||||
Future _createThumbnails(Directory directory) async {
|
||||
Future<void> _createThumbnails(Directory directory) async {
|
||||
var files = await directory.list().toList();
|
||||
var filesToWrite = <Future>{};
|
||||
|
||||
@@ -112,16 +113,16 @@ Future _createThumbnails(Directory directory) async {
|
||||
filesToWrite.add(thumbnailFile.writeAsBytes(image.encodePng(resized)));
|
||||
}
|
||||
|
||||
await Future.wait(filesToWrite);
|
||||
await Future.wait<void>(filesToWrite);
|
||||
}
|
||||
|
||||
@Task('remove generated HTML files')
|
||||
Future clean() async {
|
||||
Future<void> clean() async {
|
||||
var tasks = <Future>[];
|
||||
await for (var file in Directory('web').list(recursive: true)) {
|
||||
if (path.extension(file.path) == '.html') {
|
||||
tasks.add(file.delete());
|
||||
}
|
||||
}
|
||||
await Future.wait(tasks);
|
||||
await Future.wait<void>(tasks);
|
||||
}
|
||||
|
||||
@@ -37,13 +37,13 @@ void main() {
|
||||
}));
|
||||
|
||||
// Filter cards on each keypress
|
||||
searchBar.listen('keydown', (Event e) async {
|
||||
searchBar.listen('keydown', (e) async {
|
||||
await Future(() {});
|
||||
handleSearch();
|
||||
});
|
||||
|
||||
// Update the URL only when the user is done typing in the search bar
|
||||
searchBar.listen('change', (Event e) {
|
||||
searchBar.listen('change', (e) {
|
||||
queryParams[searchKey] = searchBar.value;
|
||||
updateHash();
|
||||
});
|
||||
@@ -58,7 +58,7 @@ void main() {
|
||||
|
||||
// Initialize chips
|
||||
chipSet = MDCChipSet(querySelector('.mdc-chip-set'));
|
||||
chipSet.listen('MDCChip:selection', (Event e) {
|
||||
chipSet.listen('MDCChip:selection', (e) {
|
||||
// Get the query parameters for this chip
|
||||
var selectedChipIndex = chipSet.chips.indexWhere((chip) => chip.selected);
|
||||
var chipParams = paramsForChip(selectedChipIndex);
|
||||
|
||||
Reference in New Issue
Block a user