Skip to content

Commit 7956b94

Browse files
author
Gordon Hayes
committed
feat: null safety
1 parent 91b7f04 commit 7956b94

13 files changed

+53
-56
lines changed

section_4/login_example_sequence_animation/lib/main.dart

+1-1
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ import 'pages/auth_page.dart';
55
void main() => runApp(const MyApp());
66

77
class MyApp extends StatelessWidget {
8-
const MyApp({Key key}) : super(key: key);
8+
const MyApp({Key? key}) : super(key: key);
99

1010
@override
1111
Widget build(BuildContext context) {

section_4/login_example_sequence_animation/lib/pages/auth_page.dart

+6-6
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ enum AuthState {
1818
}
1919

2020
class AuthPage extends StatefulWidget {
21-
const AuthPage({Key key}) : super(key: key);
21+
const AuthPage({Key? key}) : super(key: key);
2222

2323
@override
2424
_AuthPageState createState() => _AuthPageState();
@@ -27,8 +27,8 @@ class AuthPage extends StatefulWidget {
2727
class _AuthPageState extends State<AuthPage>
2828
with SingleTickerProviderStateMixin {
2929
// animation variables
30-
AnimationController _controller;
31-
SequenceAnimation _sequenceAnimation;
30+
late AnimationController _controller;
31+
late SequenceAnimation _sequenceAnimation;
3232

3333
// variables to control the transition effect to the home page
3434
double _expandingWidth = 0;
@@ -47,15 +47,15 @@ class _AuthPageState extends State<AuthPage>
4747

4848
@override
4949
void initState() {
50+
super.initState();
51+
5052
_controller = AnimationController(
5153
vsync: this,
5254
duration: const Duration(milliseconds: 1200),
5355
)..addStatusListener(_animationStatusListener);
5456

5557
_initSequenceAnimation();
5658
_controller.forward(from: 0);
57-
58-
super.initState();
5959
}
6060

6161
@override
@@ -211,7 +211,7 @@ class _AuthPageState extends State<AuthPage>
211211
decoration: BoxDecoration(
212212
color: Colors.grey.shade300.withOpacity(0.1),
213213
borderRadius: _sequenceAnimation['borderRadius'].value
214-
as BorderRadiusGeometry,
214+
as BorderRadiusGeometry?,
215215
),
216216
child: Stack(
217217
children: <Widget>[

section_4/login_example_sequence_animation/lib/pages/home_page.dart

+3-3
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ import 'package:flutter/material.dart';
33
import '../styles/backgrounds.dart';
44

55
class HomePage extends StatefulWidget {
6-
const HomePage({Key key}) : super(key: key);
6+
const HomePage({Key? key}) : super(key: key);
77

88
@override
99
_HomePageState createState() => _HomePageState();
@@ -22,13 +22,13 @@ class _HomePageState extends State<HomePage> {
2222
children: <Widget>[
2323
Text(
2424
'Success!',
25-
style: Theme.of(context).textTheme.headline4.copyWith(
25+
style: Theme.of(context).textTheme.headline4!.copyWith(
2626
color: Colors.white,
2727
),
2828
),
2929
Text(
3030
'This is the home page',
31-
style: Theme.of(context).textTheme.headline6.copyWith(
31+
style: Theme.of(context).textTheme.headline6!.copyWith(
3232
color: Colors.white,
3333
),
3434
),

section_4/login_example_sequence_animation/lib/styles/backgrounds.dart

+7-7
Original file line numberDiff line numberDiff line change
@@ -9,9 +9,9 @@ BoxDecoration backgroundAuthDecoration() {
99
end: Alignment.topRight,
1010
stops: const [0.1, 0.5, 0.9],
1111
colors: [
12-
authPageBackgroundColor[700],
13-
authPageBackgroundColor[600],
14-
authPageBackgroundColor[400],
12+
authPageBackgroundColor[700]!,
13+
authPageBackgroundColor[600]!,
14+
authPageBackgroundColor[400]!,
1515
],
1616
),
1717
);
@@ -27,10 +27,10 @@ LinearGradient linearGradientHomeDecoration() {
2727
end: Alignment.topRight,
2828
stops: const [0.1, 0.5, 0.7, 0.9],
2929
colors: [
30-
homePageBackgroundColor[800],
31-
homePageBackgroundColor[700],
32-
homePageBackgroundColor[600],
33-
homePageBackgroundColor[400],
30+
homePageBackgroundColor[800]!,
31+
homePageBackgroundColor[700]!,
32+
homePageBackgroundColor[600]!,
33+
homePageBackgroundColor[400]!,
3434
],
3535
);
3636
}

section_4/login_example_sequence_animation/lib/utils/fade_route.dart

+2-2
Original file line numberDiff line numberDiff line change
@@ -6,10 +6,10 @@ class FadeRoute extends PageRoute<dynamic> {
66
final Widget child;
77

88
@override
9-
Color get barrierColor => null;
9+
Color? get barrierColor => null;
1010

1111
@override
12-
String get barrierLabel => null;
12+
String? get barrierLabel => null;
1313

1414
@override
1515
Widget buildPage(BuildContext context, Animation<double> animation,

section_4/login_example_sequence_animation/lib/widgets/expanding_page_animation.dart

+4-4
Original file line numberDiff line numberDiff line change
@@ -4,10 +4,10 @@ import '../styles/backgrounds.dart';
44

55
class ExpandingPageAnimation extends StatelessWidget {
66
const ExpandingPageAnimation({
7-
Key key,
8-
@required double width,
9-
@required double height,
10-
@required double borderRadius,
7+
Key? key,
8+
required double width,
9+
required double height,
10+
required double borderRadius,
1111
}) : _width = width,
1212
_height = height,
1313
_borderRadius = borderRadius,

section_4/login_example_sequence_animation/lib/widgets/forms/call_to_action_button.dart

+6-11
Original file line numberDiff line numberDiff line change
@@ -2,12 +2,11 @@ import 'package:flutter/material.dart';
22

33
class CallToActionButton extends StatelessWidget {
44
const CallToActionButton({
5-
Key key,
6-
@required this.onPressed,
7-
@required this.text,
8-
@required this.color,
9-
}) : assert(onPressed != null),
10-
super(key: key);
5+
Key? key,
6+
required this.onPressed,
7+
required this.text,
8+
required this.color,
9+
}) : super(key: key);
1110

1211
final VoidCallback onPressed;
1312
final String text;
@@ -16,11 +15,7 @@ class CallToActionButton extends StatelessWidget {
1615
@override
1716
Widget build(BuildContext context) {
1817
return TextButton(
19-
onPressed: () {
20-
if (onPressed != null) {
21-
onPressed();
22-
}
23-
},
18+
onPressed: onPressed,
2419
child: Text(text, style: TextStyle(color: color, fontSize: 16)),
2520
);
2621
}
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,17 @@
11
import 'package:flutter/material.dart';
22

33
class CallToActionText extends StatelessWidget {
4-
const CallToActionText(this.text, {Key key}) : super(key: key);
4+
const CallToActionText(this.text, {Key? key}) : super(key: key);
55

66
final String text;
77
@override
88
Widget build(BuildContext context) {
99
return Text(
1010
text,
11-
style:
12-
Theme.of(context).textTheme.subtitle1.copyWith(color: Colors.white70),
11+
style: Theme.of(context)
12+
.textTheme
13+
.subtitle1!
14+
.copyWith(color: Colors.white70),
1315
);
1416
}
1517
}

section_4/login_example_sequence_animation/lib/widgets/forms/login_form.dart

+4-4
Original file line numberDiff line numberDiff line change
@@ -7,10 +7,10 @@ import 'text_input_box.dart';
77

88
class LoginForm extends StatelessWidget {
99
const LoginForm({
10-
Key key,
11-
@required this.onLoginPressed,
12-
@required this.onSignUpPressed,
13-
@required this.safeArea,
10+
Key? key,
11+
required this.onLoginPressed,
12+
required this.onSignUpPressed,
13+
required this.safeArea,
1414
}) : super(key: key);
1515

1616
final VoidCallback onSignUpPressed;

section_4/login_example_sequence_animation/lib/widgets/forms/signup_form.dart

+6-6
Original file line numberDiff line numberDiff line change
@@ -6,12 +6,12 @@ import 'call_to_action_text.dart';
66
import 'text_input_box.dart';
77

88
class SignUpForm extends StatelessWidget {
9-
const SignUpForm(
10-
{Key key,
11-
@required this.onLoginPressed,
12-
@required this.onSignUpPressed,
13-
@required this.safeArea})
14-
: super(key: key);
9+
const SignUpForm({
10+
Key? key,
11+
required this.onLoginPressed,
12+
required this.onSignUpPressed,
13+
required this.safeArea,
14+
}) : super(key: key);
1515

1616
final VoidCallback onLoginPressed;
1717
final VoidCallback onSignUpPressed;

section_4/login_example_sequence_animation/lib/widgets/forms/text_input_box.dart

+3-3
Original file line numberDiff line numberDiff line change
@@ -2,9 +2,9 @@ import 'package:flutter/material.dart';
22

33
class TextInputBox extends StatelessWidget {
44
const TextInputBox({
5-
Key key,
6-
@required this.icon,
7-
@required this.hintText,
5+
Key? key,
6+
required this.icon,
7+
required this.hintText,
88
this.obscureText = false,
99
}) : super(key: key);
1010

section_4/login_example_sequence_animation/lib/widgets/header.dart

+5-5
Original file line numberDiff line numberDiff line change
@@ -4,10 +4,10 @@ import '../styles/colors.dart';
44

55
class Header extends StatelessWidget {
66
const Header({
7-
Key key,
8-
@required double scale,
9-
@required double height,
10-
@required bool isLogin,
7+
Key? key,
8+
required double scale,
9+
required double height,
10+
required bool isLogin,
1111
}) : _scale = scale,
1212
_height = height,
1313
_isLogin = isLogin,
@@ -36,7 +36,7 @@ class Header extends StatelessWidget {
3636
headerText,
3737
overflow: TextOverflow.fade,
3838
maxLines: 1,
39-
style: Theme.of(context).textTheme.headline5.copyWith(
39+
style: Theme.of(context).textTheme.headline5!.copyWith(
4040
color: Colors.white,
4141
),
4242
),

section_4/login_example_sequence_animation/pubspec.yaml

+1-1
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ description: A new Flutter project.
1414
version: 1.0.0+1
1515

1616
environment:
17-
sdk: ">=2.1.0 <3.0.0"
17+
sdk: '>=2.12.0 <3.0.0'
1818

1919
dependencies:
2020
flutter:

0 commit comments

Comments
 (0)