Skip to content

Commit 91e5f4d

Browse files
author
Kamil Klyta
committed
Add presentation screen
1 parent ff2ef72 commit 91e5f4d

File tree

3 files changed

+245
-58
lines changed

3 files changed

+245
-58
lines changed

example/lib/indicators/ice_cream_indicator.dart

Lines changed: 26 additions & 40 deletions
Original file line numberDiff line numberDiff line change
@@ -58,18 +58,37 @@ class _IceCreamIndicatorState extends State<IceCreamIndicator>
5858
];
5959

6060
static const _indicatorSize = 150.0;
61+
static const _imageSize = 140.0;
6162

6263
IndicatorState _prevState;
6364
AnimationController _spoonController;
65+
static final _spoonTween = CurveTween(curve: Curves.easeInOut);
66+
6467
@override
6568
void initState() {
6669
_spoonController =
6770
AnimationController(vsync: this, duration: const Duration(seconds: 1));
6871
super.initState();
6972
}
7073

71-
static final _spoonTween = CurveTween(curve: Curves.easeInOut);
72-
static const double _imageSize = 150.0;
74+
Widget _buildImage(IndicatorController controller, ParalaxConfig asset) {
75+
return Transform.translate(
76+
offset: Offset(
77+
0,
78+
-(asset.level * (controller.value.clamp(1.0, 1.5) - 1.0) * 20) + 10,
79+
),
80+
child: OverflowBox(
81+
maxHeight: _imageSize,
82+
minHeight: _imageSize,
83+
child: Image(
84+
image: asset.image,
85+
fit: BoxFit.contain,
86+
height: _imageSize,
87+
),
88+
),
89+
);
90+
}
91+
7392
@override
7493
Widget build(BuildContext context) {
7594
return CustomRefreshIndicator(
@@ -97,34 +116,19 @@ class _IceCreamIndicatorState extends State<IceCreamIndicator>
97116
_prevState != currentState) {
98117
_spoonController..value = 0.0;
99118
}
119+
100120
_prevState = currentState;
101121
return SizedBox(
102122
height: controller.value * _indicatorSize,
103123
child: Stack(
104124
children: <Widget>[
105125
for (int i = 0; i < _assets.length; i++)
126+
127+
/// check if it is a spoon build animated builed and attach spoon controller
106128
if (i == 1)
107129
AnimatedBuilder(
108130
animation: _spoonController,
109-
child: Transform.translate(
110-
offset: Offset(
111-
0,
112-
(-_assets[i].level) *
113-
(20.0 *
114-
(controller.value.clamp(1.0, 1.5) -
115-
1.0)) +
116-
10,
117-
),
118-
child: OverflowBox(
119-
maxHeight: _imageSize,
120-
minHeight: _imageSize,
121-
child: Image(
122-
image: _assets[i].image,
123-
fit: BoxFit.contain,
124-
height: _imageSize,
125-
),
126-
),
127-
),
131+
child: _buildImage(controller, _assets[i]),
128132
builder: (context, child) {
129133
return Transform.rotate(
130134
angle: (-_spoonTween
@@ -135,25 +139,7 @@ class _IceCreamIndicatorState extends State<IceCreamIndicator>
135139
},
136140
)
137141
else
138-
Transform.translate(
139-
offset: Offset(
140-
0,
141-
(-_assets[i].level) *
142-
(20.0 *
143-
(controller.value.clamp(1.0, 1.5) -
144-
1.0)) +
145-
10,
146-
),
147-
child: OverflowBox(
148-
maxHeight: _imageSize,
149-
minHeight: _imageSize,
150-
child: Image(
151-
image: _assets[i].image,
152-
fit: BoxFit.contain,
153-
height: _imageSize,
154-
),
155-
),
156-
)
142+
_buildImage(controller, _assets[i])
157143
],
158144
),
159145
);

example/lib/main.dart

Lines changed: 18 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,11 @@
1-
import 'package:example/indicators/simple_indicator.dart';
2-
import 'package:example/screens/example_indicator_screen.dart';
3-
import 'package:example/screens/ice_cream_indicator_screen.dart';
4-
import 'package:example/screens/plane_indicator_screen.dart';
1+
import 'package:example/screens/presentation_screen.dart';
52
import 'package:flutter/material.dart';
63

74
import 'indicators/emoji_indicator.dart';
8-
import 'indicators/test_indicator.dart';
5+
import 'indicators/simple_indicator.dart';
6+
import 'screens/example_indicator_screen.dart';
7+
import 'screens/ice_cream_indicator_screen.dart';
8+
import 'screens/plane_indicator_screen.dart';
99

1010
void main() => runApp(MyApp());
1111

@@ -22,6 +22,7 @@ class MyApp extends StatelessWidget {
2222
'/example': (context) => ExampleIndicatorScreen(),
2323
'/plane': (context) => PlaneIndicatorScreen(),
2424
'/ice_cream': (context) => IceCreamIndicatorScreen(),
25+
'/presentation': (context) => PresentationScreen(),
2526
},
2627
);
2728
}
@@ -38,6 +39,18 @@ class MainScreen extends StatelessWidget {
3839
child: ListView(
3940
padding: const EdgeInsets.all(15),
4041
children: <Widget>[
42+
RaisedButton(
43+
child: Container(
44+
height: 50,
45+
alignment: Alignment.center,
46+
child: Text("Presentation"),
47+
),
48+
onPressed: () => Navigator.pushNamed(
49+
context,
50+
'/presentation',
51+
),
52+
),
53+
const SizedBox(height: 15),
4154
RaisedButton(
4255
child: Container(
4356
height: 50,
@@ -100,19 +113,6 @@ class MainScreen extends StatelessWidget {
100113
arguments: emojiIndicator,
101114
),
102115
),
103-
const SizedBox(height: 15),
104-
RaisedButton(
105-
child: Container(
106-
height: 50,
107-
alignment: Alignment.center,
108-
child: Text("Test indicator"),
109-
),
110-
onPressed: () => Navigator.pushNamed(
111-
context,
112-
'/example',
113-
arguments: testIndicator,
114-
),
115-
),
116116
],
117117
),
118118
),
Lines changed: 201 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,201 @@
1+
import 'package:custom_refresh_indicator/custom_refresh_indicator.dart';
2+
import 'package:example/indicators/custom_indicator.dart';
3+
import 'package:example/widgets/example_app_bar.dart';
4+
import 'package:flutter/material.dart';
5+
6+
class PresentationScreen extends StatefulWidget {
7+
@override
8+
_PresentationScreenState createState() => _PresentationScreenState();
9+
}
10+
11+
class _PresentationScreenState extends State<PresentationScreen> {
12+
IndicatorController _controller;
13+
@override
14+
void initState() {
15+
_controller = IndicatorController(refreshEnabled: true);
16+
super.initState();
17+
}
18+
19+
@override
20+
Widget build(BuildContext context) {
21+
return Scaffold(
22+
backgroundColor: appBackgroundColor,
23+
appBar: const ExampleAppBar(),
24+
body: SafeArea(
25+
child: CustomRefreshIndicator(
26+
loadingToIdleDuration: const Duration(seconds: 1),
27+
armedToLoadingDuration: const Duration(seconds: 1),
28+
dragingToIdleDuration: const Duration(seconds: 1),
29+
leadingGlowVisible: false,
30+
trailingGlowVisible: false,
31+
offsetToArmed: 100.0,
32+
controller: _controller,
33+
onRefresh: () => Future.delayed(const Duration(seconds: 2)),
34+
child: DecoratedBox(
35+
decoration: BoxDecoration(color: appBackgroundColor),
36+
child: ListView(
37+
children: [
38+
AnimatedBuilder(
39+
animation: _controller,
40+
builder: (BuildContext context, Widget child) {
41+
return Column(
42+
mainAxisSize: MainAxisSize.max,
43+
children: <Widget>[
44+
Container(
45+
margin: const EdgeInsets.all(15),
46+
padding: const EdgeInsets.all(15),
47+
width: double.infinity,
48+
decoration: const BoxDecoration(
49+
color: Colors.white,
50+
borderRadius: BorderRadius.all(Radius.circular(20)),
51+
boxShadow: [
52+
BoxShadow(
53+
color: Colors.black12,
54+
blurRadius: 4,
55+
spreadRadius: 1,
56+
),
57+
],
58+
),
59+
child: Column(
60+
crossAxisAlignment: CrossAxisAlignment.start,
61+
children: <Widget>[
62+
Center(
63+
child: Text(
64+
"IndicatorController",
65+
style: const TextStyle(
66+
fontSize: 20,
67+
fontWeight: FontWeight.bold,
68+
),
69+
),
70+
),
71+
const Divider(
72+
indent: 5,
73+
thickness: 2,
74+
color: appBackgroundColor,
75+
),
76+
Text(
77+
"value: ${_controller.value.toStringAsFixed(2)}",
78+
style: const TextStyle(fontSize: 18),
79+
),
80+
const Divider(
81+
indent: 2.5,
82+
thickness: 1,
83+
color: appBackgroundColor,
84+
),
85+
Text(
86+
"state: ${_controller.state.toString().split('.').last}",
87+
style: const TextStyle(fontSize: 18),
88+
),
89+
const Divider(
90+
indent: 2.5,
91+
thickness: 1,
92+
color: appBackgroundColor,
93+
),
94+
Text(
95+
"scrollingDirection: ${_controller.scrollingDirection.toString().split('.').last}",
96+
style: const TextStyle(fontSize: 18),
97+
),
98+
const Divider(
99+
indent: 2.5,
100+
thickness: 1,
101+
color: appBackgroundColor,
102+
),
103+
Text(
104+
"direction: ${_controller.direction.toString().split('.').last}",
105+
style: const TextStyle(fontSize: 18),
106+
),
107+
const Divider(
108+
indent: 2.5,
109+
thickness: 1,
110+
color: appBackgroundColor,
111+
),
112+
Row(
113+
children: [
114+
Text(
115+
"isRefreshEnabled: ${_controller.isRefreshEnabled}",
116+
style: const TextStyle(fontSize: 18),
117+
),
118+
const Spacer(),
119+
RaisedButton(
120+
color: _controller.isRefreshEnabled
121+
? Colors.red
122+
: Colors.lightGreen,
123+
child: Text(
124+
_controller.isRefreshEnabled
125+
? "DISABLE"
126+
: "ENABLE",
127+
style: TextStyle(
128+
color: Colors.white,
129+
),
130+
),
131+
onPressed: () =>
132+
_controller.isRefreshEnabled
133+
? _controller.disableRefresh()
134+
: _controller.enableRefresh(),
135+
),
136+
],
137+
),
138+
],
139+
),
140+
),
141+
],
142+
);
143+
},
144+
),
145+
],
146+
),
147+
),
148+
builder: (
149+
BuildContext context,
150+
Widget child,
151+
IndicatorController controller,
152+
) {
153+
return Stack(
154+
children: <Widget>[
155+
Container(
156+
height: 100,
157+
color: Colors.amber,
158+
child: Center(
159+
child: Text(
160+
"NOT ARMED",
161+
style: TextStyle(
162+
color: Colors.white,
163+
fontWeight: FontWeight.bold,
164+
fontSize: 20,
165+
),
166+
),
167+
),
168+
),
169+
Container(
170+
margin: const EdgeInsets.only(top: 100),
171+
width: double.infinity,
172+
height: 50,
173+
color: Colors.greenAccent,
174+
child: Center(
175+
child: Text(
176+
"ARMED",
177+
style: TextStyle(
178+
color: Colors.white,
179+
fontWeight: FontWeight.bold,
180+
fontSize: 20,
181+
),
182+
),
183+
),
184+
),
185+
AnimatedBuilder(
186+
animation: _controller,
187+
builder: (context, snapshot) {
188+
return Transform.translate(
189+
offset: Offset(0.0, 100 * _controller.value),
190+
child: child,
191+
);
192+
},
193+
),
194+
],
195+
);
196+
},
197+
),
198+
),
199+
);
200+
}
201+
}

0 commit comments

Comments
 (0)