Skip to content

Commit 7438e87

Browse files
authored
[beta branch] Migrate animation sample (#701)
1 parent 8155ce3 commit 7438e87

21 files changed

+143
-145
lines changed

animations/ios/Runner.xcodeproj/project.pbxproj

Lines changed: 1 addition & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -9,11 +9,7 @@
99
/* Begin PBXBuildFile section */
1010
1498D2341E8E89220040F4C2 /* GeneratedPluginRegistrant.m in Sources */ = {isa = PBXBuildFile; fileRef = 1498D2331E8E89220040F4C2 /* GeneratedPluginRegistrant.m */; };
1111
3B3967161E833CAA004F5970 /* AppFrameworkInfo.plist in Resources */ = {isa = PBXBuildFile; fileRef = 3B3967151E833CAA004F5970 /* AppFrameworkInfo.plist */; };
12-
3B80C3941E831B6300D905FE /* App.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = 3B80C3931E831B6300D905FE /* App.framework */; };
13-
3B80C3951E831B6300D905FE /* App.framework in Embed Frameworks */ = {isa = PBXBuildFile; fileRef = 3B80C3931E831B6300D905FE /* App.framework */; settings = {ATTRIBUTES = (CodeSignOnCopy, RemoveHeadersOnCopy, ); }; };
1412
74858FAF1ED2DC5600515810 /* AppDelegate.swift in Sources */ = {isa = PBXBuildFile; fileRef = 74858FAE1ED2DC5600515810 /* AppDelegate.swift */; };
15-
9705A1C61CF904A100538489 /* Flutter.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = 9740EEBA1CF902C7004384FC /* Flutter.framework */; };
16-
9705A1C71CF904A300538489 /* Flutter.framework in Embed Frameworks */ = {isa = PBXBuildFile; fileRef = 9740EEBA1CF902C7004384FC /* Flutter.framework */; settings = {ATTRIBUTES = (CodeSignOnCopy, RemoveHeadersOnCopy, ); }; };
1713
97C146FC1CF9000F007C117D /* Main.storyboard in Resources */ = {isa = PBXBuildFile; fileRef = 97C146FA1CF9000F007C117D /* Main.storyboard */; };
1814
97C146FE1CF9000F007C117D /* Assets.xcassets in Resources */ = {isa = PBXBuildFile; fileRef = 97C146FD1CF9000F007C117D /* Assets.xcassets */; };
1915
97C147011CF9000F007C117D /* LaunchScreen.storyboard in Resources */ = {isa = PBXBuildFile; fileRef = 97C146FF1CF9000F007C117D /* LaunchScreen.storyboard */; };
@@ -26,8 +22,6 @@
2622
dstPath = "";
2723
dstSubfolderSpec = 10;
2824
files = (
29-
3B80C3951E831B6300D905FE /* App.framework in Embed Frameworks */,
30-
9705A1C71CF904A300538489 /* Flutter.framework in Embed Frameworks */,
3125
);
3226
name = "Embed Frameworks";
3327
runOnlyForDeploymentPostprocessing = 0;
@@ -38,13 +32,11 @@
3832
1498D2321E8E86230040F4C2 /* GeneratedPluginRegistrant.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = GeneratedPluginRegistrant.h; sourceTree = "<group>"; };
3933
1498D2331E8E89220040F4C2 /* GeneratedPluginRegistrant.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = GeneratedPluginRegistrant.m; sourceTree = "<group>"; };
4034
3B3967151E833CAA004F5970 /* AppFrameworkInfo.plist */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = text.plist.xml; name = AppFrameworkInfo.plist; path = Flutter/AppFrameworkInfo.plist; sourceTree = "<group>"; };
41-
3B80C3931E831B6300D905FE /* App.framework */ = {isa = PBXFileReference; lastKnownFileType = wrapper.framework; name = App.framework; path = Flutter/App.framework; sourceTree = "<group>"; };
4235
74858FAD1ED2DC5600515810 /* Runner-Bridging-Header.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = "Runner-Bridging-Header.h"; sourceTree = "<group>"; };
4336
74858FAE1ED2DC5600515810 /* AppDelegate.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = AppDelegate.swift; sourceTree = "<group>"; };
4437
7AFA3C8E1D35360C0083082E /* Release.xcconfig */ = {isa = PBXFileReference; lastKnownFileType = text.xcconfig; name = Release.xcconfig; path = Flutter/Release.xcconfig; sourceTree = "<group>"; };
4538
9740EEB21CF90195004384FC /* Debug.xcconfig */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = text.xcconfig; name = Debug.xcconfig; path = Flutter/Debug.xcconfig; sourceTree = "<group>"; };
4639
9740EEB31CF90195004384FC /* Generated.xcconfig */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = text.xcconfig; name = Generated.xcconfig; path = Flutter/Generated.xcconfig; sourceTree = "<group>"; };
47-
9740EEBA1CF902C7004384FC /* Flutter.framework */ = {isa = PBXFileReference; lastKnownFileType = wrapper.framework; name = Flutter.framework; path = Flutter/Flutter.framework; sourceTree = "<group>"; };
4840
97C146EE1CF9000F007C117D /* Runner.app */ = {isa = PBXFileReference; explicitFileType = wrapper.application; includeInIndex = 0; path = Runner.app; sourceTree = BUILT_PRODUCTS_DIR; };
4941
97C146FB1CF9000F007C117D /* Base */ = {isa = PBXFileReference; lastKnownFileType = file.storyboard; name = Base; path = Base.lproj/Main.storyboard; sourceTree = "<group>"; };
5042
97C146FD1CF9000F007C117D /* Assets.xcassets */ = {isa = PBXFileReference; lastKnownFileType = folder.assetcatalog; path = Assets.xcassets; sourceTree = "<group>"; };
@@ -57,8 +49,6 @@
5749
isa = PBXFrameworksBuildPhase;
5850
buildActionMask = 2147483647;
5951
files = (
60-
9705A1C61CF904A100538489 /* Flutter.framework in Frameworks */,
61-
3B80C3941E831B6300D905FE /* App.framework in Frameworks */,
6252
);
6353
runOnlyForDeploymentPostprocessing = 0;
6454
};
@@ -68,9 +58,7 @@
6858
9740EEB11CF90186004384FC /* Flutter */ = {
6959
isa = PBXGroup;
7060
children = (
71-
3B80C3931E831B6300D905FE /* App.framework */,
7261
3B3967151E833CAA004F5970 /* AppFrameworkInfo.plist */,
73-
9740EEBA1CF902C7004384FC /* Flutter.framework */,
7462
9740EEB21CF90195004384FC /* Debug.xcconfig */,
7563
7AFA3C8E1D35360C0083082E /* Release.xcconfig */,
7664
9740EEB31CF90195004384FC /* Generated.xcconfig */,
@@ -201,7 +189,7 @@
201189
);
202190
runOnlyForDeploymentPostprocessing = 0;
203191
shellPath = /bin/sh;
204-
shellScript = "/bin/sh \"$FLUTTER_ROOT/packages/flutter_tools/bin/xcode_backend.sh\" thin";
192+
shellScript = "/bin/sh \"$FLUTTER_ROOT/packages/flutter_tools/bin/xcode_backend.sh\" embed_and_thin";
205193
};
206194
9740EEB61CF901F6004384FC /* Run Script */ = {
207195
isa = PBXShellScriptBuildPhase;
@@ -253,7 +241,6 @@
253241
/* Begin XCBuildConfiguration section */
254242
249021D3217E4FDB00AE95B9 /* Profile */ = {
255243
isa = XCBuildConfiguration;
256-
baseConfigurationReference = 7AFA3C8E1D35360C0083082E /* Release.xcconfig */;
257244
buildSettings = {
258245
ALWAYS_SEARCH_USER_PATHS = NO;
259246
CLANG_ANALYZER_NONNULL = YES;
@@ -330,7 +317,6 @@
330317
};
331318
97C147031CF9000F007C117D /* Debug */ = {
332319
isa = XCBuildConfiguration;
333-
baseConfigurationReference = 9740EEB21CF90195004384FC /* Debug.xcconfig */;
334320
buildSettings = {
335321
ALWAYS_SEARCH_USER_PATHS = NO;
336322
CLANG_ANALYZER_NONNULL = YES;
@@ -386,7 +372,6 @@
386372
};
387373
97C147041CF9000F007C117D /* Release */ = {
388374
isa = XCBuildConfiguration;
389-
baseConfigurationReference = 7AFA3C8E1D35360C0083082E /* Release.xcconfig */;
390375
buildSettings = {
391376
ALWAYS_SEARCH_USER_PATHS = NO;
392377
CLANG_ANALYZER_NONNULL = YES;

animations/ios/Runner.xcodeproj/project.xcworkspace/contents.xcworkspacedata

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

animations/lib/main.dart

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,11 @@ class Demo {
3131
final String route;
3232
final WidgetBuilder builder;
3333

34-
const Demo({this.name, this.route, this.builder});
34+
const Demo({
35+
required this.name,
36+
required this.route,
37+
required this.builder,
38+
});
3539
}
3640

3741
final basicDemos = [

animations/lib/src/basics/01_animated_container.dart

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -18,9 +18,9 @@ class AnimatedContainerDemo extends StatefulWidget {
1818
}
1919

2020
class _AnimatedContainerDemoState extends State<AnimatedContainerDemo> {
21-
Color color;
22-
double borderRadius;
23-
double margin;
21+
late Color color;
22+
late double borderRadius;
23+
late double margin;
2424

2525
@override
2626
void initState() {

animations/lib/src/basics/03_animation_controller.dart

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ class _AnimationControllerDemoState extends State<AnimationControllerDemo>
2020
// Widget is not visible.
2121

2222
static const Duration _duration = Duration(seconds: 1);
23-
AnimationController controller;
23+
late final AnimationController controller;
2424

2525
@override
2626
void initState() {

animations/lib/src/basics/04_tweens.dart

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -15,8 +15,8 @@ class _TweenDemoState extends State<TweenDemo>
1515
with SingleTickerProviderStateMixin {
1616
static const Duration _duration = Duration(seconds: 1);
1717
static const double accountBalance = 1000000;
18-
AnimationController controller;
19-
Animation<double> animation;
18+
late final AnimationController controller;
19+
late final Animation<double> animation;
2020

2121
@override
2222
void initState() {

animations/lib/src/basics/05_animated_builder.dart

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -16,8 +16,8 @@ class _AnimatedBuilderDemoState extends State<AnimatedBuilderDemo>
1616
static const Color beginColor = Colors.deepPurple;
1717
static const Color endColor = Colors.deepOrange;
1818
Duration duration = Duration(milliseconds: 800);
19-
AnimationController controller;
20-
Animation<Color> animation;
19+
late AnimationController controller;
20+
late Animation<Color?> animation;
2121

2222
@override
2323
void initState() {

animations/lib/src/basics/06_custom_tween.dart

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -5,13 +5,13 @@
55
import 'package:flutter/material.dart';
66

77
class TypewriterTween extends Tween<String> {
8-
TypewriterTween({String begin = '', String end})
8+
TypewriterTween({String begin = '', String end = ''})
99
: super(begin: begin, end: end);
1010

1111
@override
1212
String lerp(double t) {
13-
var cutoff = (end.length * t).round();
14-
return end.substring(0, cutoff);
13+
var cutoff = (end!.length * t).round();
14+
return end!.substring(0, cutoff);
1515
}
1616
}
1717

@@ -26,8 +26,8 @@ class _CustomTweenDemoState extends State<CustomTweenDemo>
2626
with SingleTickerProviderStateMixin {
2727
static const Duration _duration = Duration(seconds: 3);
2828
static const String message = loremIpsum;
29-
AnimationController controller;
30-
Animation<String> animation;
29+
late final AnimationController controller;
30+
late final Animation<String> animation;
3131

3232
@override
3333
void initState() {

animations/lib/src/basics/07_tween_sequence.dart

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -14,8 +14,8 @@ class TweenSequenceDemo extends StatefulWidget {
1414
class _TweenSequenceDemoState extends State<TweenSequenceDemo>
1515
with SingleTickerProviderStateMixin {
1616
static const Duration duration = Duration(seconds: 3);
17-
AnimationController controller;
18-
Animation<Color> animation;
17+
late final AnimationController controller;
18+
late final Animation<Color?> animation;
1919

2020
static final colors = [
2121
Colors.red,
@@ -31,23 +31,23 @@ class _TweenSequenceDemoState extends State<TweenSequenceDemo>
3131
void initState() {
3232
super.initState();
3333

34-
final sequenceItems = <TweenSequenceItem<Color>>[];
34+
final sequenceItems = <TweenSequenceItem<Color?>>[];
3535

3636
for (var i = 0; i < colors.length; i++) {
3737
final beginColor = colors[i];
3838
final endColor = colors[(i + 1) % colors.length];
3939
final weight = 1 / colors.length;
4040

4141
sequenceItems.add(
42-
TweenSequenceItem<Color>(
42+
TweenSequenceItem<Color?>(
4343
tween: ColorTween(begin: beginColor, end: endColor),
4444
weight: weight,
4545
),
4646
);
4747
}
4848

4949
controller = AnimationController(duration: duration, vsync: this);
50-
animation = TweenSequence<Color>(sequenceItems).animate(controller);
50+
animation = TweenSequence<Color?>(sequenceItems).animate(controller);
5151
}
5252

5353
@override

animations/lib/src/basics/08_fade_transition.dart

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -15,9 +15,9 @@ class FadeTransitionDemo extends StatefulWidget {
1515

1616
class _FadeTransitionDemoState extends State<FadeTransitionDemo>
1717
with SingleTickerProviderStateMixin {
18-
AnimationController _controller;
19-
Animation<double> _animation;
20-
CurvedAnimation _curve;
18+
late final AnimationController _controller;
19+
late final Animation<double> _animation;
20+
late final CurvedAnimation _curve;
2121

2222
@override
2323
void initState() {

animations/lib/src/misc/animated_list.dart

Lines changed: 24 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -14,23 +14,31 @@ class AnimatedListDemo extends StatefulWidget {
1414

1515
class _AnimatedListDemoState extends State<AnimatedListDemo> {
1616
final GlobalKey<AnimatedListState> _listKey = GlobalKey();
17-
final listData = initialListData;
17+
final listData = [
18+
UserModel(0, 'Govind', 'Dixit'),
19+
UserModel(1, 'Greta', 'Stoll'),
20+
UserModel(2, 'Monty', 'Carlo'),
21+
UserModel(3, 'Petey', 'Cruiser'),
22+
UserModel(4, 'Barry', 'Cade'),
23+
];
24+
final initialListSize = 5;
1825

1926
void addUser() {
2027
setState(() {
2128
var index = listData.length;
2229
listData.add(
23-
UserModel(firstName: 'New', lastName: 'Person'),
30+
UserModel(++_maxIdValue, 'New', 'Person'),
2431
);
25-
_listKey.currentState
32+
_listKey.currentState!
2633
.insertItem(index, duration: Duration(milliseconds: 300));
2734
});
2835
}
2936

30-
void deleteUser(int index) {
37+
void deleteUser(int id) {
3138
setState(() {
39+
final index = listData.indexWhere((u) => u.id == id);
3240
var user = listData.removeAt(index);
33-
_listKey.currentState.removeItem(
41+
_listKey.currentState!.removeItem(
3442
index,
3543
(context, animation) {
3644
return FadeTransition(
@@ -49,7 +57,7 @@ class _AnimatedListDemoState extends State<AnimatedListDemo> {
4957
});
5058
}
5159

52-
Widget _buildItem(UserModel user, [int index]) {
60+
Widget _buildItem(UserModel user) {
5361
return ListTile(
5462
key: ValueKey<UserModel>(user),
5563
title: Text(user.firstName),
@@ -59,7 +67,7 @@ class _AnimatedListDemoState extends State<AnimatedListDemo> {
5967
),
6068
trailing: IconButton(
6169
icon: Icon(Icons.delete),
62-
onPressed: () => deleteUser(index),
70+
onPressed: () => deleteUser(user.id),
6371
),
6472
);
6573
}
@@ -79,11 +87,11 @@ class _AnimatedListDemoState extends State<AnimatedListDemo> {
7987
body: SafeArea(
8088
child: AnimatedList(
8189
key: _listKey,
82-
initialItemCount: initialListData.length,
90+
initialItemCount: 5,
8391
itemBuilder: (context, index, animation) {
8492
return FadeTransition(
8593
opacity: animation,
86-
child: _buildItem(listData[index], index),
94+
child: _buildItem(listData[index]),
8795
);
8896
},
8997
),
@@ -93,31 +101,15 @@ class _AnimatedListDemoState extends State<AnimatedListDemo> {
93101
}
94102

95103
class UserModel {
96-
const UserModel({this.firstName, this.lastName});
104+
UserModel(
105+
this.id,
106+
this.firstName,
107+
this.lastName,
108+
);
97109

110+
final int id;
98111
final String firstName;
99112
final String lastName;
100113
}
101114

102-
List<UserModel> initialListData = [
103-
UserModel(
104-
firstName: 'Govind',
105-
lastName: 'Dixit',
106-
),
107-
UserModel(
108-
firstName: 'Greta',
109-
lastName: 'Stoll',
110-
),
111-
UserModel(
112-
firstName: 'Monty',
113-
lastName: 'Carlo',
114-
),
115-
UserModel(
116-
firstName: 'Petey',
117-
lastName: 'Cruiser',
118-
),
119-
UserModel(
120-
firstName: 'Barry',
121-
lastName: 'Cade',
122-
),
123-
];
115+
int _maxIdValue = 4;

0 commit comments

Comments
 (0)