Skip to content

Commit

Permalink
Manually update to null safe - step2
Browse files Browse the repository at this point in the history
apply some simple fixes like:
1. adding "late"
2. adding "?"/"!"
  • Loading branch information
X-Wei committed Jul 25, 2021
1 parent d055f46 commit e1679aa
Show file tree
Hide file tree
Showing 64 changed files with 275 additions and 226 deletions.
1 change: 1 addition & 0 deletions lib/generated_plugin_registrant.dart
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
// Generated file. Do not edit.
//

// ignore_for_file: directives_ordering
// ignore_for_file: lines_longer_than_80_chars

import 'package:cloud_firestore_web/cloud_firestore_web.dart';
Expand Down
2 changes: 1 addition & 1 deletion lib/my_route_search_delegate.dart
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ class MyRouteSearchDelegate extends SearchDelegate<String> {
return IconButton(
tooltip: 'Back',
icon: const Icon(Icons.arrow_back),
onPressed: () => this.close(context, null),
onPressed: () => this.close(context, ''),
);
}

Expand Down
2 changes: 1 addition & 1 deletion lib/routes/animation_animated_builder_ex.dart
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ class AnimatedBuilderExample extends StatefulWidget {

class _AnimatedBuilderExampleState extends State<AnimatedBuilderExample>
with SingleTickerProviderStateMixin {
AnimationController _controller;
late AnimationController _controller;

@override
void initState() {
Expand Down
2 changes: 1 addition & 1 deletion lib/routes/animation_animated_icons_ex.dart
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,7 @@ class _AnimIconDemoBox extends StatefulWidget {
// ! Add SingleTickerProviderStateMixin to use animation controllers.
class _AnimIconDemoBoxState extends State<_AnimIconDemoBox>
with SingleTickerProviderStateMixin {
AnimationController _animationController;
late AnimationController _animationController;

@override
void initState() {
Expand Down
2 changes: 1 addition & 1 deletion lib/routes/animation_animated_text_kit_ex.dart
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ class AnimatedTextKitExample extends StatelessWidget {
TextLiquidFill(
text: 'LIQUIDY',
waveColor: Colors.blueAccent,
boxBackgroundColor: Colors.red[100],
boxBackgroundColor: Colors.red[100]!,
textStyle:
const TextStyle(fontSize: 80.0, fontWeight: FontWeight.bold),
boxHeight: 300.0,
Expand Down
6 changes: 3 additions & 3 deletions lib/routes/animation_animated_widget_ex.dart
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ import 'package:flutter/material.dart';
// The AnimatedWidget base class allows you to separate out the core widget code
// from the animation code.
class _AnimatedLogo extends AnimatedWidget {
const _AnimatedLogo({Key? key, Animation<double> animation})
const _AnimatedLogo({Key? key, required Animation<double> animation})
: super(key: key, listenable: animation);

@override
Expand All @@ -28,8 +28,8 @@ class AnimatedWidgetExample extends StatefulWidget {

class _AnimatedWidgetExampleState extends State<AnimatedWidgetExample>
with SingleTickerProviderStateMixin {
Animation<double> _sizeAnimation;
AnimationController _controller;
late Animation<double> _sizeAnimation;
late AnimationController _controller;

@override
void initState() {
Expand Down
5 changes: 3 additions & 2 deletions lib/routes/animation_animations_pkg_ex.dart
Original file line number Diff line number Diff line change
Expand Up @@ -232,8 +232,9 @@ class __SharedAxisExState extends State<_SharedAxisEx> {
.substring('SharedAxisTransitionType.'.length)),
)
],
onChanged: (SharedAxisTransitionType val) =>
setState(() => this._transitionType = val),
onChanged: (SharedAxisTransitionType? val) {
if (val != null) setState(() => this._transitionType = val);
},
),
),
],
Expand Down
2 changes: 1 addition & 1 deletion lib/routes/animation_lottie_ex.dart
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ class _LottieCustom extends StatefulWidget {

class __LottieCustomState extends State<_LottieCustom>
with TickerProviderStateMixin {
AnimationController _controller;
late AnimationController _controller;

@override
void initState() {
Expand Down
8 changes: 4 additions & 4 deletions lib/routes/animation_low_level_ex.dart
Original file line number Diff line number Diff line change
Expand Up @@ -15,14 +15,14 @@ class _LowLevelAnimationExampleState extends State<LowLevelAnimationExample>
// An Animation object knows the current state of an animation (for example,
// whether it’s started, stopped, or moving forward or in reverse), but
// doesn’t know anything about what appears onscreen.
Animation<double> _sizeAnimation;
Animation<Color> _colorAnimation;
late Animation<double> _sizeAnimation;
late Animation<Color?> _colorAnimation;
// Both AnimationController and CurvedAnimation extends Animation<double>,
// but add additional methods
// An AnimationController manages the Animation.
AnimationController _controller;
late AnimationController _controller;
// A CurvedAnimation defines progression as a non-linear curve.
CurvedAnimation _curve;
late CurvedAnimation _curve;

@override
void initState() {
Expand Down
2 changes: 1 addition & 1 deletion lib/routes/appbar_bottom_appbar_ex.dart
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ class _BottomAppbarExampleState extends State<BottomAppbarExample> {
title: const Text('FloatingActionButton position:'),
trailing: DropdownButton<FloatingActionButtonLocation>(
value: this._fabLocation,
onChanged: (FloatingActionButtonLocation newVal) {
onChanged: (FloatingActionButtonLocation? newVal) {
if (newVal != null) {
setState(() => this._fabLocation = newVal);
}
Expand Down
2 changes: 1 addition & 1 deletion lib/routes/appbar_convex_appbar_ex.dart
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,7 @@ class _ConvexAppExampleState extends State<ConvexAppExample> {
final dropdown = DropdownButton<TabStyle>(
value: _tabStyle,
onChanged: (newStyle) {
setState(() => _tabStyle = newStyle);
if (newStyle != null) setState(() => _tabStyle = newStyle);
},
items: [
for (final style in TabStyle.values)
Expand Down
15 changes: 9 additions & 6 deletions lib/routes/appbar_search_ex.dart
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ class AppBarSearchExample extends StatefulWidget {

class _AppBarSearchExampleState extends State<AppBarSearchExample> {
final List<String> kEnglishWords;
_MySearchDelegate _delegate;
late _MySearchDelegate _delegate;

_AppBarSearchExampleState()
: kEnglishWords = List.from(Set.from(english_words.all))
Expand All @@ -38,7 +38,7 @@ class _AppBarSearchExampleState extends State<AppBarSearchExample> {
tooltip: 'Search',
icon: const Icon(Icons.search),
onPressed: () async {
final String selected = await showSearch<String>(
final String? selected = await showSearch<String>(
context: context,
delegate: _delegate,
);
Expand Down Expand Up @@ -87,7 +87,7 @@ class _MySearchDelegate extends SearchDelegate<String> {
),
onPressed: () {
// SearchDelegate.close() can return vlaues, similar to Navigator.pop().
this.close(context, null);
this.close(context, '');
},
);
}
Expand All @@ -112,7 +112,7 @@ class _MySearchDelegate extends SearchDelegate<String> {
this.query,
style: Theme.of(context)
.textTheme
.headline4
.headline4!
.copyWith(fontWeight: FontWeight.bold),
),
),
Expand Down Expand Up @@ -167,15 +167,18 @@ class _MySearchDelegate extends SearchDelegate<String> {

// Suggestions list widget displayed in the search page.
class _SuggestionList extends StatelessWidget {
const _SuggestionList({this.suggestions, this.query, this.onSelected});
const _SuggestionList(
{required this.suggestions,
required this.query,
required this.onSelected});

final List<String> suggestions;
final String query;
final ValueChanged<String> onSelected;

@override
Widget build(BuildContext context) {
final textTheme = Theme.of(context).textTheme.subtitle1;
final textTheme = Theme.of(context).textTheme.subtitle1!;
return ListView.builder(
itemCount: suggestions.length,
itemBuilder: (BuildContext context, int i) {
Expand Down
2 changes: 1 addition & 1 deletion lib/routes/async_futurebuilder_ex.dart
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ class FutureBuilderExampleState extends State<FutureBuilderExample> {
// This shouldn't happen in our case, but good to handle errors.
return const Text('Error has happened in the future!');
} else {
return Image.memory(snapshot.data.buffer.asUint8List());
return Image.memory(snapshot.data!.buffer.asUint8List());
}
},
),
Expand Down
2 changes: 1 addition & 1 deletion lib/routes/async_streambuilder_ex.dart
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ class StreamBuilderExampleState extends State<StreamBuilderExample> {
if (snapshot.hasData) {
if (snapshot.data != this._previousStreamValue) {
print('Latest snapshot from stream: ${snapshot.data}');
this._previousStreamValue = snapshot.data;
this._previousStreamValue = snapshot.data!;
if (!_paused) {
this._timerValue++;
}
Expand Down
2 changes: 1 addition & 1 deletion lib/routes/async_streamcontroller_ex.dart
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,7 @@ class _StreamControllerExampleState extends State<StreamControllerExample> {
title: Text('no data'),
);
}
final Widget widgetToRender = snapshot.data;
final Widget widgetToRender = snapshot.data!;
return widgetToRender;
},
),
Expand Down
2 changes: 1 addition & 1 deletion lib/routes/charts_fl_bar_chart_ex.dart
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ class _FlBarChartExampleState extends State<FlBarChartExample> {
x: entry.key.toInt(),
barRods: [
BarChartRodData(y: entry.value, colors: [Colors.blue]),
BarChartRodData(y: _data2[entry.key], colors: [Colors.red]),
BarChartRodData(y: _data2[entry.key]!, colors: [Colors.red]),
],
),
];
Expand Down
4 changes: 2 additions & 2 deletions lib/routes/charts_fl_line_chart_ex.dart
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ class _FlLineChartExampleState extends State<FlLineChartExample> {
isCurved: _isCurved,
dotData: FlDotData(show: _showDot),
belowBarData:
BarAreaData(show: _showBelowArea, colors: [Colors.blue[200]]),
BarAreaData(show: _showBelowArea, colors: [Colors.blue[200]!]),
),
LineChartBarData(
spots: spots2,
Expand All @@ -52,7 +52,7 @@ class _FlLineChartExampleState extends State<FlLineChartExample> {
isCurved: _isCurved,
dotData: FlDotData(show: _showDot),
belowBarData:
BarAreaData(show: _showBelowArea, colors: [Colors.red[200]]),
BarAreaData(show: _showBelowArea, colors: [Colors.red[200]!]),
),
],
// ! Behavior when touching the chart:
Expand Down
4 changes: 3 additions & 1 deletion lib/routes/charts_fl_pie_chart_ex.dart
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,9 @@ class _FlPieChartExampleState extends State<FlPieChartExample> {
pieTouchData: PieTouchData(
enabled: true,
touchCallback: (pieTouchResponse) => setState(() {
_touchedIdx = pieTouchResponse.touchedSection.touchedSectionIndex;
if (pieTouchResponse.touchedSection != null) {
_touchedIdx = pieTouchResponse.touchedSection!.touchedSectionIndex;
}
}),
),
centerSpaceRadius: _innerRadius,
Expand Down
2 changes: 1 addition & 1 deletion lib/routes/charts_heatmap_calendar_ex.dart
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ class HeatmapCalendarExample extends StatelessWidget {
squareSize: 18,
textOpacity: 0.3,
labelTextColor: Colors.blueGrey,
dayTextColor: Colors.blue[500],
dayTextColor: Colors.blue[500]!,
// Week day and month labels can be overriden:
// weekDaysLabels: const ['S', 'M', 'T', 'W', 'T', 'F', 'S'],
// monthsLabels: const ['', 'Jan', 'Feb', 'Mar', 'Apr', 'May', 'Jun',
Expand Down
8 changes: 4 additions & 4 deletions lib/routes/charts_pie_chart_ex.dart
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ class _PieChartExampleState extends State<PieChartExample> {
/*seriesList=*/ [
charts.Series<_CostsData, String>(
id: 'Sales-1',
colorFn: (_, idx) => _colorPalettes[idx].shadeDefault,
colorFn: (_, idx) => _colorPalettes[idx!].shadeDefault,
domainFn: (_CostsData sales, _) => sales.category,
measureFn: (_CostsData sales, _) => sales.cost,
data: this._data,
Expand Down Expand Up @@ -107,7 +107,7 @@ class _PieChartExampleState extends State<PieChartExample> {
title: const Text('arcLabelPosition:'),
trailing: DropdownButton<charts.ArcLabelPosition>(
value: this._arcLabelPosition,
onChanged: (charts.ArcLabelPosition newVal) {
onChanged: (charts.ArcLabelPosition? newVal) {
if (newVal != null) {
setState(() => this._arcLabelPosition = newVal);
}
Expand All @@ -122,7 +122,7 @@ class _PieChartExampleState extends State<PieChartExample> {
title: const Text('titlePosition:'),
trailing: DropdownButton<charts.BehaviorPosition>(
value: this._titlePosition,
onChanged: (charts.BehaviorPosition newVal) {
onChanged: (charts.BehaviorPosition? newVal) {
if (newVal != null) {
setState(() => this._titlePosition = newVal);
}
Expand All @@ -137,7 +137,7 @@ class _PieChartExampleState extends State<PieChartExample> {
title: const Text('legendPosition:'),
trailing: DropdownButton<charts.BehaviorPosition>(
value: this._legendPosition,
onChanged: (charts.BehaviorPosition newVal) {
onChanged: (charts.BehaviorPosition? newVal) {
if (newVal != null) {
setState(() => this._legendPosition = newVal);
}
Expand Down
6 changes: 3 additions & 3 deletions lib/routes/charts_time_series_ex.dart
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ class _TimeseriesChartExampleState extends State<TimeseriesChartExample> {
charts.BehaviorPosition _legendPosition = charts.BehaviorPosition.bottom;

// Data to render.
List<_SalesData> _series1, _series2;
late List<_SalesData> _series1, _series2;

@override
void initState() {
Expand Down Expand Up @@ -135,7 +135,7 @@ class _TimeseriesChartExampleState extends State<TimeseriesChartExample> {
title: const Text('titlePosition:'),
trailing: DropdownButton<charts.BehaviorPosition>(
value: this._titlePosition,
onChanged: (charts.BehaviorPosition newVal) {
onChanged: (charts.BehaviorPosition? newVal) {
if (newVal != null) {
setState(() => this._titlePosition = newVal);
}
Expand All @@ -150,7 +150,7 @@ class _TimeseriesChartExampleState extends State<TimeseriesChartExample> {
title: const Text('legendPosition:'),
trailing: DropdownButton<charts.BehaviorPosition>(
value: this._legendPosition,
onChanged: (charts.BehaviorPosition newVal) {
onChanged: (charts.BehaviorPosition? newVal) {
if (newVal != null) {
setState(() => this._legendPosition = newVal);
}
Expand Down
10 changes: 7 additions & 3 deletions lib/routes/data/todo_item.dart
Original file line number Diff line number Diff line change
Expand Up @@ -6,16 +6,20 @@ part 'todo_item.g.dart';
@HiveType(typeId: 0)
class TodoItem extends HiveObject {
@HiveField(0)
int id;
int? id;
@HiveField(1)
String content;
@HiveField(2)
bool isDone;
@HiveField(3)
final DateTime createdAt;

TodoItem({this.id, this.content, this.isDone = false, DateTime createdAt})
: this.createdAt = createdAt ?? DateTime.now();
TodoItem({
this.id,
required this.content,
this.isDone = false,
DateTime? createdAt,
}) : this.createdAt = createdAt ?? DateTime.now();

@override
String toString() {
Expand Down
14 changes: 7 additions & 7 deletions lib/routes/firebase_chatroom_ex.dart
Original file line number Diff line number Diff line change
Expand Up @@ -19,8 +19,8 @@ class FirebaseChatroomExample extends StatefulWidget {
}

class _FirebaseChatroomExampleState extends State<FirebaseChatroomExample> {
firebase_auth.User _user;
DatabaseReference _firebaseMsgDbRef;
firebase_auth.User? _user;
late DatabaseReference _firebaseMsgDbRef;

final TextEditingController _textController = TextEditingController();
bool _isComposing = false;
Expand Down Expand Up @@ -49,7 +49,7 @@ class _FirebaseChatroomExampleState extends State<FirebaseChatroomExample> {
scrollDirection: Axis.horizontal,
child: Text(_user == null
? 'Chatting'
: 'Chatting as "${_user.displayName}"'),
: 'Chatting as "${_user!.displayName}"'),
),
),
body: Center(
Expand Down Expand Up @@ -91,7 +91,7 @@ class _FirebaseChatroomExampleState extends State<FirebaseChatroomExample> {
child: FirebaseAnimatedList(
defaultChild: const Center(child: CircularProgressIndicator()),
query: _firebaseMsgDbRef,
sort: (a, b) => b.key.compareTo(a.key),
sort: (a, b) => b.key!.compareTo(a.key!),
padding: const EdgeInsets.all(8.0),
reverse: true,
itemBuilder: (BuildContext ctx, DataSnapshot snapshot,
Expand Down Expand Up @@ -214,9 +214,9 @@ class _FirebaseChatroomExampleState extends State<FirebaseChatroomExample> {
});
// Send message to firebase realtime database.
_firebaseMsgDbRef.push().set({
'senderId': this._user.uid,
'senderName': this._user.displayName,
'senderPhotoUrl': this._user.photoURL,
'senderId': this._user!.uid,
'senderName': this._user!.displayName,
'senderPhotoUrl': this._user!.photoURL,
'text': text,
'timestamp': DateTime.now().millisecondsSinceEpoch,
});
Expand Down
Loading

0 comments on commit e1679aa

Please sign in to comment.