mirror of
https://github.com/flutter/samples.git
synced 2025-11-10 14:58:34 +00:00
Upgrading samples to flutter_lints, part 1 of n (#804)
This commit is contained in:
@@ -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();
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user