Skip to content

Commit e244ad0

Browse files
author
Kamil Klyta
committed
Improve examples
1 parent 096ce7f commit e244ad0

File tree

4 files changed

+24
-38
lines changed

4 files changed

+24
-38
lines changed

example/lib/indicators/plane_indicator.dart

Lines changed: 14 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,4 @@
11
import 'package:custom_refresh_indicator/custom_refresh_indicator.dart';
2-
import 'package:example/indicators/custom_indicator.dart';
32
import 'package:flutter/material.dart';
43

54
class _Cloud {
@@ -33,11 +32,9 @@ class _Cloud {
3332

3433
/// Desgin by Katarzyna Klyta kasia@klyta.it
3534
class PlaneIndicator extends StatefulWidget {
36-
final IndicatorController controller;
3735
final Widget child;
3836
const PlaneIndicator({
3937
@required this.child,
40-
@required this.controller,
4138
});
4239

4340
@override
@@ -52,7 +49,6 @@ class _PlaneIndicatorState extends State<PlaneIndicator>
5249

5350
@override
5451
void initState() {
55-
_prevState = widget.controller.state;
5652
_planeController = AnimationController(
5753
vsync: this,
5854
duration: const Duration(milliseconds: 500),
@@ -66,39 +62,39 @@ class _PlaneIndicatorState extends State<PlaneIndicator>
6662
_Cloud(
6763
color: _Cloud._dark,
6864
initialValue: 0.6,
69-
dy: 17.5,
65+
dy: 10.0,
7066
image: AssetImage(_Cloud._assets[1]),
7167
width: 100,
7268
duration: Duration(milliseconds: 1600),
7369
),
7470
_Cloud(
7571
color: _Cloud._light,
7672
initialValue: 0.15,
77-
dy: 35,
73+
dy: 25.0,
7874
image: AssetImage(_Cloud._assets[3]),
7975
width: 40,
8076
duration: Duration(milliseconds: 1600),
8177
),
8278
_Cloud(
8379
color: _Cloud._light,
8480
initialValue: 0.3,
85-
dy: 75,
81+
dy: 65.0,
8682
image: AssetImage(_Cloud._assets[2]),
8783
width: 60,
8884
duration: Duration(milliseconds: 1600),
8985
),
9086
_Cloud(
9187
color: _Cloud._dark,
9288
initialValue: 0.8,
93-
dy: 80,
89+
dy: 70.0,
9490
image: AssetImage(_Cloud._assets[3]),
9591
width: 100,
9692
duration: Duration(milliseconds: 1600),
9793
),
9894
_Cloud(
9995
color: _Cloud._normal,
10096
initialValue: 0.0,
101-
dy: 110,
97+
dy: 10,
10298
image: AssetImage(_Cloud._assets[0]),
10399
width: 80,
104100
duration: Duration(milliseconds: 1600),
@@ -143,6 +139,8 @@ class _PlaneIndicatorState extends State<PlaneIndicator>
143139
super.dispose();
144140
}
145141

142+
static const _offsetToArmed = 150.0;
143+
146144
@override
147145
Widget build(BuildContext context) {
148146
final screenWidth = MediaQuery.of(context).size.width;
@@ -163,15 +161,16 @@ class _PlaneIndicatorState extends State<PlaneIndicator>
163161
},
164162
);
165163
return CustomRefreshIndicator(
164+
offsetToArmed: _offsetToArmed,
166165
child: widget.child,
167166
onRefresh: () => Future.delayed(const Duration(seconds: 3)),
168167
builder:
169168
(BuildContext context, Widget child, IndicatorController controller) {
170169
return AnimatedBuilder(
171-
animation: widget.controller,
172-
child: widget.child,
170+
animation: controller,
171+
child: child,
173172
builder: (context, child) {
174-
final currentState = widget.controller.state;
173+
final currentState = controller.state;
175174
if (_prevState == IndicatorState.armed &&
176175
currentState == IndicatorState.loading) {
177176
_startCloudAnimation();
@@ -191,7 +190,7 @@ class _PlaneIndicatorState extends State<PlaneIndicator>
191190
children: <Widget>[
192191
if (_prevState != IndicatorState.idle)
193192
Container(
194-
height: 150 * widget.controller.value,
193+
height: _offsetToArmed * controller.value,
195194
color: Color(0xFFFDFEFF),
196195
width: double.infinity,
197196
child: AnimatedBuilder(
@@ -206,7 +205,7 @@ class _PlaneIndicatorState extends State<PlaneIndicator>
206205
((screenWidth + cloud.width) *
207206
cloud.controller.value) -
208207
cloud.width,
209-
cloud.dy * widget.controller.value,
208+
cloud.dy * controller.value,
210209
),
211210
child: OverflowBox(
212211
minWidth: cloud.width,
@@ -241,7 +240,7 @@ class _PlaneIndicatorState extends State<PlaneIndicator>
241240
),
242241
),
243242
Transform.translate(
244-
offset: Offset(0.0, 150 * widget.controller.value),
243+
offset: Offset(0.0, _offsetToArmed * controller.value),
245244
child: child,
246245
),
247246
],
@@ -252,10 +251,3 @@ class _PlaneIndicatorState extends State<PlaneIndicator>
252251
);
253252
}
254253
}
255-
256-
CustomIndicatorConfig planeIndicator = CustomIndicatorConfig(
257-
builder: (context, child, data) => PlaneIndicator(
258-
child: child,
259-
controller: data,
260-
),
261-
);

example/lib/main.dart

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,6 @@ import 'package:example/screens/plane_indicator_screen.dart';
44
import 'package:flutter/material.dart';
55

66
import 'indicators/emoji_indicator.dart';
7-
import 'indicators/plane_indicator.dart';
87
import 'indicators/test_indicator.dart';
98

109
void main() => runApp(MyApp());
@@ -17,6 +16,7 @@ class MyApp extends StatelessWidget {
1716
theme: ThemeData(
1817
primarySwatch: Colors.blue,
1918
),
19+
2020
home: MainScreen(),
2121
routes: {
2222
'/example': (context) => ExampleIndicatorScreen(),
@@ -72,7 +72,6 @@ class MainScreen extends StatelessWidget {
7272
onPressed: () => Navigator.pushNamed(
7373
context,
7474
'/plane',
75-
arguments: planeIndicator,
7675
),
7776
),
7877
const SizedBox(height: 15),

example/lib/screens/plane_indicator_screen.dart

Lines changed: 1 addition & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,3 @@
1-
import 'package:custom_refresh_indicator/custom_refresh_indicator.dart';
21
import 'package:example/indicators/plane_indicator.dart';
32
import 'package:example/widgets/example_app_bar.dart';
43
import 'package:example/widgets/example_list.dart';
@@ -17,19 +16,8 @@ class _PlaneIndicatorScreenState extends State<PlaneIndicatorScreen> {
1716
backgroundColor: appBackgroundColor,
1817
appBar: const ExampleAppBar(),
1918
body: SafeArea(
20-
child: CustomRefreshIndicator(
21-
leadingGlowVisible: false,
22-
offsetToArmed: 200.0,
23-
trailingGlowVisible: false,
24-
onRefresh: () => Future.delayed(const Duration(seconds: 3)),
19+
child: PlaneIndicator(
2520
child: const ExampleList(),
26-
builder: (BuildContext context, Widget child,
27-
IndicatorController controller) {
28-
return PlaneIndicator(
29-
child: child,
30-
controller: controller,
31-
);
32-
},
3321
),
3422
),
3523
);

example/lib/widgets/example_list.dart

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,14 @@ class ExampleList extends StatelessWidget {
88
@override
99
Widget build(BuildContext context) {
1010
return DecoratedBox(
11-
decoration: BoxDecoration(color: backgroundColor),
11+
decoration: BoxDecoration(color: backgroundColor, boxShadow: [
12+
BoxShadow(
13+
blurRadius: 2,
14+
color: Colors.black12,
15+
spreadRadius: 0.5,
16+
offset: Offset(0.0, .0),
17+
)
18+
]),
1219
child: ListView.separated(
1320
itemBuilder: (BuildContext context, int index) => const Element(),
1421
itemCount: 4,

0 commit comments

Comments
 (0)