Skip to content

Commit

Permalink
update to null safety
Browse files Browse the repository at this point in the history
  • Loading branch information
GIfatahTH committed Mar 12, 2021
1 parent 8533164 commit 72f9a11
Show file tree
Hide file tree
Showing 40 changed files with 1,072 additions and 401 deletions.
12 changes: 0 additions & 12 deletions .circleci/config.yml

This file was deleted.

27 changes: 27 additions & 0 deletions .github/workflows/config.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@

name: test
on:
pull_request:
branches:
- master
- null_safety

jobs:
flutter_test:
name: Run flutter test and analyze
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v2
- uses: actions/setup-java@v1
with:
java-version: "12.x"
- uses: subosito/flutter-action@v1
with:
channel: "dev"
- run: |
flutter doctor
flutter pub get
flutter test --coverage
bash <(curl -s https://codecov.io/bash)
3 changes: 3 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,6 @@
## [3.0.0]
* update to null safety

## [2.0.2]
* update dependencies

Expand Down
70 changes: 70 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -244,3 +244,73 @@ AnimatorRebuilder(
```

The order of Animator and AnimatorRebuilder in the widget tree is irrelevant, except in the case, AnimatorRebuilder is first inserted in the widget tree, you have to provide initial values in AnimatorKey to avoid null exceptions.


## Example of Flutter log random walk

```dart
import 'dart:math';
import 'package:flutter/material.dart';
import 'package:animator/animator.dart';
class RandomFlutterWalk extends StatefulWidget {
@override
_RandomFlutterWalkState createState() => _RandomFlutterWalkState();
}
class _RandomFlutterWalkState extends State<RandomFlutterWalk> {
double beginX = 0.0;
double beginY = 0.0;
double endX = Random().nextDouble() * 50;
double endY = Random().nextDouble() * 50;
int seconds = Random().nextInt(1000);
@override
Widget build(BuildContext context) {
final screenSize = MediaQuery.of(context).size;
return Scaffold(
body: Animator<Offset>(
tween: Tween<Offset>(
begin: Offset(beginX, beginY), end: Offset(endX, endY)),
duration: Duration(milliseconds: 500 + seconds),
curve: seconds % 2 == 0 ? Curves.linear : Curves.easeInOut,
resetAnimationOnRebuild: true,
triggerOnInit: true,
cycles: 1,
builder: (_, animatorState, __) => Transform.translate(
offset: animatorState.value,
child: FlutterLogo(
size: 50,
),
),
statusListener: (status, setup) {
if (status == AnimationStatus.completed) {
setState(() {
final sign = Random().nextBool() ? 1 : -1;
beginX = endX;
beginY = endY;
double nextEndX = endX + sign * Random().nextDouble() * 50;
double nextEndY = endY + sign * Random().nextDouble() * 50;
nextEndX = nextEndX > screenSize.width - 50
? screenSize.width - 50
: nextEndX;
nextEndX = nextEndX < 0 ? 0 : nextEndX;
nextEndY = nextEndY > screenSize.height - 50
? screenSize.width - 50
: nextEndY;
nextEndY = nextEndY < 0 ? 0 : nextEndY;
endX = nextEndX;
endY = nextEndY;
seconds = Random().nextInt(8);
});
}
},
),
);
}
}
```
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
<?xml version="1.0" encoding="utf-8"?>
<!-- Modify this file to customize your launch splash screen -->
<layer-list xmlns:android="http://schemas.android.com/apk/res/android">
<item android:drawable="?android:colorBackground" />

<!-- You can insert your own image assets here -->
<!-- <item>
<bitmap
android:gravity="center"
android:src="@mipmap/launch_image" />
</item> -->
</layer-list>
18 changes: 18 additions & 0 deletions example/android/app/src/main/res/values-night/styles.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
<?xml version="1.0" encoding="utf-8"?>
<resources>
<!-- Theme applied to the Android Window while the process is starting when the OS's Dark Mode setting is on -->
<style name="LaunchTheme" parent="@android:style/Theme.Black.NoTitleBar">
<!-- Show a splash screen on the activity. Automatically removed when
Flutter draws its first frame -->
<item name="android:windowBackground">@drawable/launch_background</item>
</style>
<!-- Theme applied to the Android Window as soon as the process has started.
This theme determines the color of the Android Window while your
Flutter UI initializes, as well as behind your Flutter UI while its
running.
This Theme is only used starting with V2 of Flutter's Android embedding. -->
<style name="NormalTheme" parent="@android:style/Theme.Black.NoTitleBar">
<item name="android:windowBackground">?android:colorBackground</item>
</style>
</resources>
6 changes: 2 additions & 4 deletions example/ios/Flutter/flutter_export_environment.sh
Original file line number Diff line number Diff line change
@@ -1,12 +1,10 @@
#!/bin/sh
# This is a generated file; do not edit or check into version control.
export "FLUTTER_ROOT=/mnt/A270A07970A055B7/flutter"
export "FLUTTER_APPLICATION_PATH=/mnt/A270A07970A055B7/Repositories/animator/example"
export "FLUTTER_ROOT=/home/mafatahnj/flutter"
export "FLUTTER_APPLICATION_PATH=/run/media/mafatahnj/data/Repository/animator/example"
export "FLUTTER_TARGET=lib/main.dart"
export "FLUTTER_BUILD_DIR=build"
export "SYMROOT=${SOURCE_ROOT}/../build/ios"
export "OTHER_LDFLAGS=$(inherited) -framework Flutter"
export "FLUTTER_FRAMEWORK_DIR=/mnt/A270A07970A055B7/flutter/bin/cache/artifacts/engine/ios"
export "FLUTTER_BUILD_NAME=1.0.0"
export "FLUTTER_BUILD_NUMBER=1"
export "DART_OBFUSCATION=false"
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
<plist version="1.0">
<dict>
<key>IDEDidComputeMac32BitWarning</key>
<true/>
</dict>
</plist>
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
<plist version="1.0">
<dict>
<key>PreviewsEnabled</key>
<false/>
</dict>
</plist>
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
<plist version="1.0">
<dict>
<key>IDEDidComputeMac32BitWarning</key>
<true/>
</dict>
</plist>
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
<plist version="1.0">
<dict>
<key>PreviewsEnabled</key>
<false/>
</dict>
</plist>
15 changes: 7 additions & 8 deletions example/lib/basic_animation_0/main.dart
Original file line number Diff line number Diff line change
@@ -1,15 +1,15 @@
import 'dart:math';

import 'package:flutter/material.dart';
import 'package:animator/animator.dart';

class BasicAnimation0 extends StatelessWidget {
Widget build(BuildContext context) {
return MaterialApp(
home: Scaffold(
appBar: AppBar(
title: Text('Basic Animation 0'),
),
body: Body(),
return Scaffold(
appBar: AppBar(
title: Text('Basic Animation 0'),
),
body: Body(),
);
}
}
Expand Down Expand Up @@ -58,7 +58,6 @@ class _BodyState extends State<Body> {
Divider(),
Text('Animation is reset on rebuild. Curve changes on rebuild'),
Animator<double>(
// tickerMixin: TickerMixin.tickerProviderStateMixin,
duration: Duration(seconds: 2),
repeats: 1,
resetAnimationOnRebuild: true,
Expand All @@ -70,7 +69,7 @@ class _BodyState extends State<Body> {
),
),
),
RaisedButton(
ElevatedButton(
child: Text('Rebuild '),
onPressed: () {
setState(() {
Expand Down
34 changes: 19 additions & 15 deletions example/lib/basic_animation_1/main.dart
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import 'package:flutter/material.dart';
import 'pages/opacity.dart';
import 'pages/random_flutter_walk.dart';
import 'pages/rotation.dart';
import 'pages/scale.dart';
import 'pages/translation.dart';
Expand All @@ -10,14 +11,12 @@ import 'pages/animator_key.dart';
class BasicAnimation1 extends StatelessWidget {
@override
Widget build(BuildContext context) {
return MaterialApp(
title: 'Animator Demo',
home: Scaffold(
appBar: AppBar(
title: Text("Animator demo"),
),
body: MyHomePage(),
));
return Scaffold(
appBar: AppBar(
title: Text("Animator demo"),
),
body: MyHomePage(),
);
}
}

Expand All @@ -36,34 +35,39 @@ class MyHomePage extends StatelessWidget {
return Center(
child: Column(
crossAxisAlignment: CrossAxisAlignment.center,
mainAxisAlignment: MainAxisAlignment.spaceEvenly,
children: <Widget>[
RaisedButton(
ElevatedButton(
child: Text("Opacity Animation"),
onPressed: () => goto(OpacityAnimation(), context),
),
RaisedButton(
ElevatedButton(
child: Text("Rotation Animation"),
onPressed: () => goto(RotationAnimation(), context),
),
RaisedButton(
ElevatedButton(
child: Text("Scale Animation"),
onPressed: () => goto(ScaleAnimation(), context),
),
RaisedButton(
ElevatedButton(
child: Text("Translation Animation"),
onPressed: () => goto(TranslateAnimation(), context),
),
RaisedButton(
ElevatedButton(
child: Text("Multi Tween Animation"),
onPressed: () => goto(MultiTweenAnimation(), context),
),
RaisedButton(
ElevatedButton(
child: Text("Flutter Animation"),
onPressed: () => goto(FlutterAnimation(), context),
),
RaisedButton(
ElevatedButton(
child: Text("Animation with AnimatorKey"),
onPressed: () => goto(AnimationWithAnimatorKey(), context),
),
ElevatedButton(
child: Text("Random Flutter walk"),
onPressed: () => goto(RandomFlutterWalk(), context),
)
],
),
Expand Down
7 changes: 4 additions & 3 deletions example/lib/basic_animation_1/pages/animator_key.dart
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ class MyAnimation extends StatelessWidget {
FlutterLogo(size: 150, style: FlutterLogoStyle.horizontal);

final AnimatorKey animatorKey = AnimatorKey<double>();

@override
Widget build(BuildContext context) {
return Center(
Expand All @@ -31,20 +32,20 @@ class MyAnimation extends StatelessWidget {
crossAxisAlignment: CrossAxisAlignment.center,
children: [
Text('Start Animation and you can not restart it until it ends'),
RaisedButton(
ElevatedButton(
child: Text("Animate"),
onPressed: () => animatorKey.triggerAnimation(),
),
SizedBox(height: 5),
Text('Start Animation and restart it if it is running'),
RaisedButton(
ElevatedButton(
child: Text("restart animation"),
onPressed: () => animatorKey.triggerAnimation(restart: true),
),
SizedBox(height: 5),
Text('Change animation setting and restart it'),
Text('Curve is changed from linear to bounceIn'),
RaisedButton(
ElevatedButton(
child: Text("reset and restart animation using AnimatorKey"),
onPressed: () => animatorKey
..refreshAnimation(
Expand Down
Loading

0 comments on commit 72f9a11

Please sign in to comment.