Skip to content

Commit fd15f59

Browse files
add wheel_switch and loading
1 parent 16320c4 commit fd15f59

File tree

13 files changed

+785
-1
lines changed

13 files changed

+785
-1
lines changed
Lines changed: 67 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,67 @@
1+
import 'package:flutter/material.dart';
2+
3+
///
4+
/// desc:球
5+
///
6+
7+
class Ball extends StatelessWidget {
8+
///
9+
/// 半径
10+
///
11+
final double radius;
12+
13+
///
14+
/// 实心球颜色
15+
///
16+
final Color color;
17+
18+
///
19+
/// 球的类型 [ BallType ]
20+
///
21+
final BallType ballType;
22+
23+
///
24+
/// 边框宽
25+
///
26+
final double borderWidth;
27+
28+
///
29+
/// 边框颜色
30+
///
31+
final Color borderColor;
32+
33+
const Ball({
34+
Key key,
35+
this.radius = 16,
36+
this.color = Colors.white,
37+
this.ballType = BallType.solid,
38+
this.borderWidth = 0.0,
39+
this.borderColor = Colors.white,
40+
}) : super(key: key);
41+
42+
@override
43+
Widget build(BuildContext context) {
44+
return SizedBox(
45+
width: radius,
46+
height: radius,
47+
child: DecoratedBox(
48+
decoration: BoxDecoration(
49+
shape: BoxShape.circle,
50+
color: ballType == BallType.solid ? color : Colors.transparent,
51+
border: Border.all(color: borderColor, width: borderWidth)),
52+
),
53+
);
54+
}
55+
}
56+
57+
enum BallType {
58+
///
59+
/// 空心
60+
///
61+
hollow,
62+
63+
///
64+
/// 实心
65+
///
66+
solid
67+
}
Lines changed: 61 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,61 @@
1+
import 'package:flutter/cupertino.dart';
2+
import 'package:flutter/material.dart';
3+
import '../common/delay_tween.dart';
4+
import 'ball.dart';
5+
6+
///
7+
/// desc:小球脉冲效果
8+
///
9+
10+
class BallGridPulseLoading extends StatefulWidget {
11+
final double minRadius;
12+
final double maxRadius;
13+
final int count;
14+
final Duration duration;
15+
16+
const BallGridPulseLoading(
17+
{Key key,
18+
this.minRadius = 0.0,
19+
this.maxRadius = 50.0,
20+
this.count = 3,
21+
this.duration = const Duration(milliseconds: 800)})
22+
: super(key: key);
23+
24+
@override
25+
_BallGridPulseLoadingState createState() => _BallGridPulseLoadingState();
26+
}
27+
28+
class _BallGridPulseLoadingState extends State<BallGridPulseLoading>
29+
with SingleTickerProviderStateMixin {
30+
AnimationController _controller;
31+
32+
@override
33+
void initState() {
34+
_controller = AnimationController(vsync: this, duration: widget.duration)
35+
..repeat();
36+
super.initState();
37+
}
38+
39+
@override
40+
void dispose() {
41+
_controller.dispose();
42+
super.dispose();
43+
}
44+
45+
@override
46+
Widget build(BuildContext context) {
47+
return GridView.builder(
48+
gridDelegate: SliverGridDelegateWithFixedCrossAxisCount(
49+
crossAxisCount: 3,
50+
),
51+
itemBuilder: (context, index) {
52+
return ScaleTransition(
53+
scale: DelayTween(begin: 0.0, end: 1.0, delay: index * .2)
54+
.animate(_controller),
55+
child: Ball(),
56+
);
57+
},
58+
itemCount: 9,
59+
);
60+
}
61+
}
Lines changed: 56 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,56 @@
1+
import 'package:flutter/material.dart';
2+
import '../common/delay_tween.dart';
3+
import 'ball.dart';
4+
5+
///
6+
/// desc:小球脉冲效果
7+
///
8+
9+
class BallPulseLoading extends StatefulWidget {
10+
final double minRadius;
11+
final double maxRadius;
12+
final int count;
13+
final Duration duration;
14+
15+
const BallPulseLoading(
16+
{Key key,
17+
this.minRadius = 0.0,
18+
this.maxRadius = 50.0,
19+
this.count = 3,
20+
this.duration = const Duration(milliseconds: 800)})
21+
: super(key: key);
22+
23+
@override
24+
_BallPulseLoadingState createState() => _BallPulseLoadingState();
25+
}
26+
27+
class _BallPulseLoadingState extends State<BallPulseLoading>
28+
with SingleTickerProviderStateMixin {
29+
AnimationController _controller;
30+
31+
@override
32+
void initState() {
33+
_controller = AnimationController(vsync: this, duration: widget.duration)
34+
..repeat();
35+
super.initState();
36+
}
37+
38+
@override
39+
void dispose() {
40+
_controller.dispose();
41+
super.dispose();
42+
}
43+
44+
@override
45+
Widget build(BuildContext context) {
46+
return Row(
47+
children: List.generate(widget.count, (index) {
48+
return ScaleTransition(
49+
scale: DelayTween(begin: 0.0, end: 1.0, delay: index * .2)
50+
.animate(_controller),
51+
child: Ball(),
52+
);
53+
}),
54+
);
55+
}
56+
}
Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
import 'dart:math' as math;
2+
3+
import 'package:flutter/animation.dart';
4+
5+
///
6+
/// desc:
7+
///
8+
class DelayTween extends Tween<double> {
9+
final double delay;
10+
11+
DelayTween({double begin, double end, this.delay})
12+
:super(begin: begin, end: end);
13+
14+
@override
15+
double lerp(double t) {
16+
return super.lerp((math.sin((t - delay) * 2 * math.pi) + 1) / 2);
17+
}
18+
19+
@override
20+
double evaluate(Animation<double> animation) => lerp(animation.value);
21+
}

wheel_switch/.gitignore

Lines changed: 74 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,74 @@
1+
# Miscellaneous
2+
*.class
3+
*.log
4+
*.pyc
5+
*.swp
6+
.DS_Store
7+
.atom/
8+
.buildlog/
9+
.history
10+
.svn/
11+
12+
# IntelliJ related
13+
*.iml
14+
*.ipr
15+
*.iws
16+
.idea/
17+
18+
# The .vscode folder contains launch configuration and tasks you configure in
19+
# VS Code which you may wish to be included in version control, so this line
20+
# is commented out by default.
21+
#.vscode/
22+
23+
# Flutter/Dart/Pub related
24+
**/doc/api/
25+
.dart_tool/
26+
.flutter-plugins
27+
.flutter-plugins-dependencies
28+
.packages
29+
.pub-cache/
30+
.pub/
31+
build/
32+
33+
# Android related
34+
**/android/**/gradle-wrapper.jar
35+
**/android/.gradle
36+
**/android/captures/
37+
**/android/gradlew
38+
**/android/gradlew.bat
39+
**/android/local.properties
40+
**/android/**/GeneratedPluginRegistrant.java
41+
42+
# iOS/XCode related
43+
**/ios/**/*.mode1v3
44+
**/ios/**/*.mode2v3
45+
**/ios/**/*.moved-aside
46+
**/ios/**/*.pbxuser
47+
**/ios/**/*.perspectivev3
48+
**/ios/**/*sync/
49+
**/ios/**/.sconsign.dblite
50+
**/ios/**/.tags*
51+
**/ios/**/.vagrant/
52+
**/ios/**/DerivedData/
53+
**/ios/**/Icon?
54+
**/ios/**/Pods/
55+
**/ios/**/.symlinks/
56+
**/ios/**/profile
57+
**/ios/**/xcuserdata
58+
**/ios/.generated/
59+
**/ios/Flutter/App.framework
60+
**/ios/Flutter/Flutter.framework
61+
**/ios/Flutter/Flutter.podspec
62+
**/ios/Flutter/Generated.xcconfig
63+
**/ios/Flutter/app.flx
64+
**/ios/Flutter/app.zip
65+
**/ios/Flutter/flutter_assets/
66+
**/ios/Flutter/flutter_export_environment.sh
67+
**/ios/ServiceDefinitions.json
68+
**/ios/Runner/GeneratedPluginRegistrant.*
69+
70+
# Exceptions to above rules.
71+
!**/ios/**/default.mode1v3
72+
!**/ios/**/default.mode2v3
73+
!**/ios/**/default.pbxuser
74+
!**/ios/**/default.perspectivev3

wheel_switch/.metadata

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
# This file tracks properties of this Flutter project.
2+
# Used by Flutter tool to assess capabilities and perform upgrades etc.
3+
#
4+
# This file should be version controlled and should not be manually edited.
5+
6+
version:
7+
revision: f30b7f4db93ee747cd727df747941a28ead25ff5
8+
channel: stable
9+
10+
project_type: package

wheel_switch/CHANGELOG.md

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
## [0.0.1] - TODO: Add release date.
2+
3+
* TODO: Describe initial release.

0 commit comments

Comments
 (0)