Skip to content

Commit

Permalink
fix: 格式化代码
Browse files Browse the repository at this point in the history
  • Loading branch information
xuelongqy committed Dec 8, 2019
1 parent 9986a39 commit f000760
Show file tree
Hide file tree
Showing 35 changed files with 805 additions and 607 deletions.
11 changes: 5 additions & 6 deletions example/lib/example.dart
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,6 @@ class _Example extends StatefulWidget {
}

class _ExampleState extends State<_Example> {

EasyRefreshController _controller;

// 条目总数
Expand Down Expand Up @@ -74,14 +73,15 @@ class _ExampleState extends State<_Example> {
slivers: <Widget>[
SliverList(
delegate: SliverChildBuilderDelegate(
(context, index) {
(context, index) {
return Container(
width: 60.0,
height: 60.0,
child: Center(
child: Text('$index'),
),
color: index%2==0 ? Colors.grey[300] : Colors.transparent,
color:
index % 2 == 0 ? Colors.grey[300] : Colors.transparent,
);
},
childCount: _count,
Expand All @@ -100,7 +100,6 @@ class _ExampleState extends State<_Example> {
_controller.callLoad();
},
child: Text("Load more", style: TextStyle(color: Colors.black))),
]
);
]);
}
}
}
74 changes: 47 additions & 27 deletions example/lib/header/bob_minion_header.dart
Original file line number Diff line number Diff line change
Expand Up @@ -8,16 +8,16 @@ import 'package:flutter/material.dart';
import 'package:flutter_easyrefresh/easy_refresh.dart';

/// 小黄人动画类型
enum BobMinionAnimation {
Stand, Dance, Jump, Wave
}
enum BobMinionAnimation { Stand, Dance, Jump, Wave }

/// 小黄人(Bob)样式
class BobMinionHeader extends Header {
/// Key
final Key key;

/// 动画类型
final BobMinionAnimation animation;

/// 背景颜色
final Color backgroundColor;

Expand All @@ -28,28 +28,43 @@ class BobMinionHeader extends Header {
bool enableHapticFeedback = false,
this.animation = BobMinionAnimation.Stand,
this.backgroundColor = Colors.transparent,
}): super(
extent: 80.0,
triggerDistance: 100.0,
float: false,
enableHapticFeedback: enableHapticFeedback,
enableInfiniteRefresh: false,
completeDuration: const Duration(seconds: 1),
);
}) : super(
extent: 80.0,
triggerDistance: 100.0,
float: false,
enableHapticFeedback: enableHapticFeedback,
enableInfiniteRefresh: false,
completeDuration: const Duration(seconds: 1),
);

@override
Widget contentBuilder(BuildContext context, RefreshMode refreshState,
double pulledExtent, double refreshTriggerPullDistance,
double refreshIndicatorExtent, AxisDirection axisDirection,
bool float, Duration completeDuration, bool enableInfiniteRefresh,
bool success, bool noMore) {
Widget contentBuilder(
BuildContext context,
RefreshMode refreshState,
double pulledExtent,
double refreshTriggerPullDistance,
double refreshIndicatorExtent,
AxisDirection axisDirection,
bool float,
Duration completeDuration,
bool enableInfiniteRefresh,
bool success,
bool noMore) {
// 不能为水平方向以及反向
assert(axisDirection == AxisDirection.down,
'Widget can only be vertical and cannot be reversed'
);
linkNotifier.contentBuilder(context, refreshState, pulledExtent,
refreshTriggerPullDistance, refreshIndicatorExtent, axisDirection,
float, completeDuration, enableInfiniteRefresh, success, noMore);
'Widget can only be vertical and cannot be reversed');
linkNotifier.contentBuilder(
context,
refreshState,
pulledExtent,
refreshTriggerPullDistance,
refreshIndicatorExtent,
axisDirection,
float,
completeDuration,
enableInfiniteRefresh,
success,
noMore);
String animationName;
switch (animation) {
case BobMinionAnimation.Stand:
Expand All @@ -76,11 +91,14 @@ class BobMinionHeader extends Header {
);
}
}

/// 小黄人组件
class BobMinionHeaderWidget extends StatefulWidget {
final LinkHeaderNotifier linkNotifier;

/// 动画类型
final String animation;

/// 背景颜色
final Color backgroundColor;

Expand All @@ -96,6 +114,7 @@ class BobMinionHeaderWidget extends StatefulWidget {
return BobMinionHeaderWidgetState();
}
}

class BobMinionHeaderWidgetState extends State<BobMinionHeaderWidget> {
RefreshMode get _refreshState => widget.linkNotifier.refreshState;
double get _pulledExtent => widget.linkNotifier.pulledExtent;
Expand Down Expand Up @@ -130,11 +149,13 @@ class BobMinionHeaderWidgetState extends State<BobMinionHeaderWidget> {
alignment: Alignment.center,
width: double.infinity,
height: _pulledExtent > _indicatorExtent
? _pulledExtent : _indicatorExtent,
? _pulledExtent
: _indicatorExtent,
color: widget.backgroundColor,
child: Container(
height: 80.0,
child: FlareActor("assets/flare/Bob (Minion).flr",
child: FlareActor(
"assets/flare/Bob (Minion).flr",
alignment: Alignment.center,
animation: 'idle',
fit: BoxFit.fitHeight,
Expand All @@ -154,9 +175,7 @@ class BobMinionController extends FlareController {
FlutterActorArtboard _artboard;

/// 动画列表
List<String> _animationList = [
"Stand", "Dance", "Jump", "Wave"
];
List<String> _animationList = ["Stand", "Dance", "Jump", "Wave"];

/// The current [ActorAnimation].
String _animationName;
Expand Down Expand Up @@ -214,6 +233,7 @@ class BobMinionController extends FlareController {
/// the two instead of immediately switching to the new one.
for (int i = 0; i < _animationLayers.length; i++) {
FlareAnimationLayer layer = _animationLayers[i];

/// Apply the animation with the current mix.
if (layer.name == _animationName) {
layer.mix += elapsed;
Expand All @@ -232,4 +252,4 @@ class BobMinionController extends FlareController {
}
return _animationLayers.isNotEmpty;
}
}
}
64 changes: 40 additions & 24 deletions example/lib/header/space_header.dart
Original file line number Diff line number Diff line change
Expand Up @@ -35,34 +35,50 @@ class SpaceHeader extends Header {
SpaceHeader({
this.key,
bool enableHapticFeedback = false,
}): super(
extent: 140.0,
triggerDistance: 160.0,
float: false,
enableHapticFeedback: enableHapticFeedback,
enableInfiniteRefresh: false,
completeDuration: const Duration(seconds: 1),
);
}) : super(
extent: 140.0,
triggerDistance: 160.0,
float: false,
enableHapticFeedback: enableHapticFeedback,
enableInfiniteRefresh: false,
completeDuration: const Duration(seconds: 1),
);

@override
Widget contentBuilder(BuildContext context, RefreshMode refreshState,
double pulledExtent, double refreshTriggerPullDistance,
double refreshIndicatorExtent, AxisDirection axisDirection,
bool float, Duration completeDuration, bool enableInfiniteRefresh,
bool success, bool noMore) {
Widget contentBuilder(
BuildContext context,
RefreshMode refreshState,
double pulledExtent,
double refreshTriggerPullDistance,
double refreshIndicatorExtent,
AxisDirection axisDirection,
bool float,
Duration completeDuration,
bool enableInfiniteRefresh,
bool success,
bool noMore) {
// 不能为水平方向以及反向
assert(axisDirection == AxisDirection.down,
'Widget can only be vertical and cannot be reversed'
);
linkNotifier.contentBuilder(context, refreshState, pulledExtent,
refreshTriggerPullDistance, refreshIndicatorExtent, axisDirection,
float, completeDuration, enableInfiniteRefresh, success, noMore);
'Widget can only be vertical and cannot be reversed');
linkNotifier.contentBuilder(
context,
refreshState,
pulledExtent,
refreshTriggerPullDistance,
refreshIndicatorExtent,
axisDirection,
float,
completeDuration,
enableInfiniteRefresh,
success,
noMore);
return SpaceHeaderWidget(
key: key,
linkNotifier: linkNotifier,
);
}
}

/// 星空组件
class SpaceHeaderWidget extends StatefulWidget {
final LinkHeaderNotifier linkNotifier;
Expand All @@ -77,8 +93,9 @@ class SpaceHeaderWidget extends StatefulWidget {
return SpaceHeaderWidgetState();
}
}

class SpaceHeaderWidgetState extends State<SpaceHeaderWidget>
with FlareController{
with FlareController {
RefreshMode get _refreshState => widget.linkNotifier.refreshState;
double get _pulledExtent => widget.linkNotifier.pulledExtent;
double get _indicatorExtent => widget.linkNotifier.refreshIndicatorExtent;
Expand All @@ -98,7 +115,6 @@ class SpaceHeaderWidgetState extends State<SpaceHeaderWidget>
super.initState();
}


@override
bool advance(FlutterActorArtboard artboard, double elapsed) {
double animationPosition = _pulledExtent / _indicatorExtent;
Expand Down Expand Up @@ -128,16 +144,16 @@ class SpaceHeaderWidgetState extends State<SpaceHeaderWidget>
}
return true;
}

void initialize(FlutterActorArtboard actor) {
_pullAnimation = actor.getAnimation("pull");
_successAnimation = actor.getAnimation("success");
_loadingAnimation = actor.getAnimation("loading");
_cometAnimation = actor.getAnimation("idle comet");
}

@override
void setViewTransform(Mat2D viewTransform) { }
void setViewTransform(Mat2D viewTransform) {}

@override
Widget build(BuildContext context) {
Expand All @@ -151,4 +167,4 @@ class SpaceHeaderWidgetState extends State<SpaceHeaderWidget>
controller: this),
);
}
}
}
7 changes: 2 additions & 5 deletions example/lib/main.dart
Original file line number Diff line number Diff line change
Expand Up @@ -29,10 +29,7 @@ class _MyAppState extends State<MyApp> {
home: HomePage(),
localizationsDelegates: [
FlutterI18nDelegate(
useCountryCode: true,
fallbackFile: 'en',
path: 'assets/locale'
),
useCountryCode: true, fallbackFile: 'en', path: 'assets/locale'),
GlobalMaterialLocalizations.delegate,
GlobalWidgetsLocalizations.delegate
],
Expand All @@ -41,4 +38,4 @@ class _MyAppState extends State<MyApp> {
},
);
}
}
}
3 changes: 2 additions & 1 deletion example/lib/page/home.dart
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ class HomePage extends StatefulWidget {
@override
_HomePageState createState() => _HomePageState();
}

class _HomePageState extends State<HomePage>
with SingleTickerProviderStateMixin {
// 页面控制
Expand Down Expand Up @@ -82,4 +83,4 @@ class _HomePageState extends State<HomePage>
),
);
}
}
}
15 changes: 9 additions & 6 deletions example/lib/page/more/more.dart
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,9 @@ class MorePage extends StatefulWidget {
@override
_MorePageState createState() => _MorePageState();
}

class _MorePageState extends State<MorePage>
with AutomaticKeepAliveClientMixin{
with AutomaticKeepAliveClientMixin {
@override
Widget build(BuildContext context) {
super.build(context);
Expand All @@ -32,7 +33,8 @@ class _MorePageState extends State<MorePage>
delegate: SliverChildListDelegate([
ListItem(
title: FlutterI18n.translate(context, 'joinDiscussion'),
describe: FlutterI18n.translate(context, 'joinDiscussionDescribe'),
describe:
FlutterI18n.translate(context, 'joinDiscussionDescribe'),
icon: CircularIcon(
bgColor: Colors.blue,
icon: Icons.supervised_user_circle,
Expand All @@ -55,16 +57,17 @@ class _MorePageState extends State<MorePage>
),
ListItem(
title: FlutterI18n.translate(context, 'supportAuthor'),
describe: FlutterI18n.translate(context, 'supportAuthorDescribe'),
describe:
FlutterI18n.translate(context, 'supportAuthorDescribe'),
icon: CircularIcon(
bgColor: Colors.red,
icon: Icons.star,
),
onPressed: () {
Navigator.push(context,
MaterialPageRoute(builder: (BuildContext context) {
return SupportPage();
}));
return SupportPage();
}));
},
),
ListItem(
Expand All @@ -87,4 +90,4 @@ class _MorePageState extends State<MorePage>
@override
// TODO: implement wantKeepAlive
bool get wantKeepAlive => true;
}
}
6 changes: 4 additions & 2 deletions example/lib/page/more/support.dart
Original file line number Diff line number Diff line change
Expand Up @@ -86,7 +86,9 @@ class _SupportPageState extends State<SupportPage> {
ListItem(
title: FlutterI18n.translate(context, 'payPal'),
icon: Container(
padding: EdgeInsets.all(5.0,),
padding: EdgeInsets.all(
5.0,
),
decoration: BoxDecoration(
color: Colors.teal,
borderRadius: BorderRadius.all(Radius.circular(20.0)),
Expand All @@ -109,4 +111,4 @@ class _SupportPageState extends State<SupportPage> {
),
);
}
}
}
Loading

0 comments on commit f000760

Please sign in to comment.