Skip to content

Commit

Permalink
Introduce null safety (fluttercommunity#155)
Browse files Browse the repository at this point in the history
Adds null safety via version 3.0.0-beta.1
  • Loading branch information
Sebastian Roth authored Mar 31, 2021
1 parent 5eb31d2 commit 210cc7b
Show file tree
Hide file tree
Showing 23 changed files with 529 additions and 951 deletions.
3 changes: 2 additions & 1 deletion .ci/Dockerfile
Original file line number Diff line number Diff line change
@@ -1,8 +1,9 @@
# https://github.com/cirruslabs/docker-images-flutter/blob/master/.cirrus.yml
FROM cirrusci/flutter:1.22.5
FROM cirrusci/flutter:2.1.0-12.2.pre

RUN yes | sdkmanager \
"platforms;android-29" \
"build-tools;28.0.3" \
"build-tools;29.0.3" \
"extras;google;m2repository" \
"extras;android;m2repository" \
Expand Down
1 change: 1 addition & 0 deletions .cirrus.yml
Original file line number Diff line number Diff line change
Expand Up @@ -83,6 +83,7 @@ ios_task:
install_swiftlint_script:
- brew install swiftlint
test_script:
- flutter channel beta
- flutter upgrade
- flutter test
build_script:
Expand Down
3 changes: 3 additions & 0 deletions .fvm/fvm_config.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
{
"flutterSdkVersion": "beta"
}
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -46,3 +46,4 @@ build/
.classpath
.settings
.last_build_id
.fvm/flutter_sdk
4 changes: 4 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,7 @@
## 3.0.0-beta.1

- Migrate to nullsafety

## 2.0.0-beta.6

- Android: Ensure to properly unregister upload observers
Expand Down
1,032 changes: 241 additions & 791 deletions example/backend/functions/package-lock.json

Large diffs are not rendered by default.

6 changes: 3 additions & 3 deletions example/backend/functions/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,8 @@
},
"dependencies": {
"busboy": "^0.3.0",
"firebase-admin": "^8.6.1",
"firebase-functions": "^3.3.0",
"firebase-admin": "^9.6.0",
"firebase-functions": "^3.13.2",
"md5-file": "^4.0.0"
},
"devDependencies": {
Expand All @@ -23,4 +23,4 @@
"engines": {
"node": "10"
}
}
}
26 changes: 13 additions & 13 deletions example/integration_test/flutter_uploader_test.dart
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ final baseUrl = Uri.parse(
void main() {
IntegrationTestWidgetsFlutterBinding.ensureInitialized();

FlutterUploader uploader;
late FlutterUploader uploader;
var tempFilePaths = <String>[];

setUp(() {
Expand All @@ -33,13 +33,14 @@ void main() {
tempFilePaths.clear();
});

Function(UploadTaskResponse) isCompleted(String taskId) {
return (response) =>
response.taskId == taskId &&
response.status == UploadTaskStatus.complete;
bool Function(UploadTaskResponse) isCompleted(String taskId) {
return (response) {
return response.taskId == taskId &&
response.status == UploadTaskStatus.complete;
};
}

Function(UploadTaskResponse) isFailed(String taskId) {
bool Function(UploadTaskResponse) isFailed(String taskId) {
return (response) =>
response.taskId == taskId && response.status == UploadTaskStatus.failed;
}
Expand All @@ -57,7 +58,7 @@ void main() {
expect(taskId, isNotNull);

final res = await uploader.result.firstWhere(isCompleted(taskId));
final json = jsonDecode(res.response);
final json = jsonDecode(res.response!);

expect(json['message'], 'Successfully uploaded');
expect(res.statusCode, 200);
Expand Down Expand Up @@ -105,7 +106,7 @@ void main() {
expect(taskId, isNotNull);

final res = await uploader.result.firstWhere(isCompleted(taskId));
final json = jsonDecode(res.response);
final json = jsonDecode(res.response!);

expect(json['request']['fields']['simpleKey'], 'simpleValue');
expect(jsonDecode(json['request']['fields']['listOf']),
Expand All @@ -125,7 +126,7 @@ void main() {
headers: {'Accept': 'application/json, charset=utf-8'},
));
final res = await uploader.result.firstWhere(isCompleted(taskId));
final json = jsonDecode(res.response);
final json = jsonDecode(res.response!);

expect(json['request']['headers']['accept'],
'application/json, charset=utf-8');
Expand All @@ -142,7 +143,7 @@ void main() {
expect(taskId, isNotNull);

final res = await uploader.result.firstWhere(isCompleted(taskId));
final json = jsonDecode(res.response);
final json = jsonDecode(res.response!);

expect(json['message'], 'Successfully uploaded');
expect(res.statusCode, 200);
Expand Down Expand Up @@ -203,8 +204,7 @@ void main() {
expect(taskId, isNotNull);

final res = await uploader.result.firstWhere(isCompleted(taskId));

final json = jsonDecode(res.response);
final json = jsonDecode(res.response!);

expect(json['message'], 'Successfully uploaded');
expect(res.statusCode, 200);
Expand Down Expand Up @@ -238,7 +238,7 @@ void main() {
headers: {'Accept': 'application/json, charset=utf-8'},
));
final res = await uploader.result.firstWhere(isCompleted(taskId));
final json = jsonDecode(res.response);
final json = jsonDecode(res.response!);

expect(json['headers']['accept'], 'application/json, charset=utf-8');
});
Expand Down
8 changes: 3 additions & 5 deletions example/lib/main.dart
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ void backgroundHandler() {
'FlutterUploader.Example',
'FlutterUploader',
'Installed when you activate the Flutter Uploader Example',
progress: progress.progress,
progress: progress.progress ?? 0,
icon: 'ic_upload',
enableVibration: false,
importance: Importance.low,
Expand Down Expand Up @@ -108,9 +108,7 @@ void backgroundHandler() {
void main() => runApp(App());

class App extends StatefulWidget {
final Widget child;

App({Key key, this.child}) : super(key: key);
App({Key? key}) : super(key: key);

@override
_AppState createState() => _AppState();
Expand All @@ -133,7 +131,7 @@ class _AppState extends State<App> {
requestBadgePermission: false,
requestAlertPermission: true,
onDidReceiveLocalNotification:
(int id, String title, String body, String payload) async {},
(int id, String? title, String? body, String? payload) async {},
);
var initializationSettings = InitializationSettings(
android: initializationSettingsAndroid, iOS: initializationSettingsIOS);
Expand Down
14 changes: 7 additions & 7 deletions example/lib/responses_screen.dart
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,8 @@ import 'package:flutter_uploader_example/upload_item_view.dart';
/// Shows the statusresponses for previous uploads.
class ResponsesScreen extends StatefulWidget {
ResponsesScreen({
Key key,
@required this.uploader,
Key? key,
required this.uploader,
}) : super(key: key);

final FlutterUploader uploader;
Expand All @@ -21,8 +21,8 @@ class ResponsesScreen extends StatefulWidget {
}

class _ResponsesScreenState extends State<ResponsesScreen> {
StreamSubscription<UploadTaskProgress> _progressSubscription;
StreamSubscription<UploadTaskResponse> _resultSubscription;
StreamSubscription<UploadTaskProgress>? _progressSubscription;
StreamSubscription<UploadTaskResponse>? _resultSubscription;

Map<String, UploadItem> _tasks = {};

Expand All @@ -44,7 +44,7 @@ class _ResponsesScreenState extends State<ResponsesScreen> {
setState(() => _tasks = tmp);
}, onError: (ex, stacktrace) {
print('exception: $ex');
print('stacktrace: $stacktrace' ?? 'no stacktrace');
print('stacktrace: $stacktrace');
});

_resultSubscription = widget.uploader.result.listen((result) {
Expand All @@ -54,12 +54,12 @@ class _ResponsesScreenState extends State<ResponsesScreen> {
var tmp = <String, UploadItem>{}..addAll(_tasks);
tmp.putIfAbsent(result.taskId, () => UploadItem(result.taskId));
tmp[result.taskId] =
tmp[result.taskId].copyWith(status: result.status, response: result);
tmp[result.taskId]!.copyWith(status: result.status, response: result);

setState(() => _tasks = tmp);
}, onError: (ex, stacktrace) {
print('exception: $ex');
print('stacktrace: $stacktrace' ?? 'no stacktrace');
print('stacktrace: $stacktrace');
});
}

Expand Down
16 changes: 8 additions & 8 deletions example/lib/upload_item.dart
Original file line number Diff line number Diff line change
Expand Up @@ -6,11 +6,11 @@ import 'package:flutter_uploader/flutter_uploader.dart';

class UploadItem extends Equatable {
final String id;
final int progress;
final UploadTaskStatus status;
final int? progress;
final UploadTaskStatus? status;

/// Store the entire response object.
final UploadTaskResponse response;
final UploadTaskResponse? response;

const UploadItem(
this.id, {
Expand All @@ -20,10 +20,10 @@ class UploadItem extends Equatable {
});

UploadItem copyWith({
String id,
int progress,
UploadTaskStatus status,
UploadTaskResponse response,
String? id,
int? progress,
UploadTaskStatus? status,
UploadTaskResponse? response,
}) {
return UploadItem(
id ?? this.id,
Expand All @@ -39,7 +39,7 @@ class UploadItem extends Equatable {
status == UploadTaskStatus.failed;

@override
List<Object> get props {
List<Object?> get props {
return [
id,
progress,
Expand Down
20 changes: 10 additions & 10 deletions example/lib/upload_item_view.dart
Original file line number Diff line number Diff line change
Expand Up @@ -12,9 +12,9 @@ class UploadItemView extends StatelessWidget {
final CancelUploadCallback onCancel;

UploadItemView({
Key key,
this.item,
this.onCancel,
Key? key,
required this.item,
required this.onCancel,
}) : super(key: key);

@override
Expand All @@ -29,13 +29,13 @@ class UploadItemView extends StatelessWidget {
item.id,
style: Theme.of(context)
.textTheme
.caption
.caption!
.copyWith(fontFamily: 'monospace'),
),
Container(
height: 5.0,
),
Text(item.status.description),
Text(item.status!.description),
// if (item.status == UploadTaskStatus.complete &&
// item.remoteHash != null)
// Builder(builder: (context) {
Expand All @@ -50,16 +50,16 @@ class UploadItemView extends StatelessWidget {
// }),
Container(height: 5.0),
if (item.status == UploadTaskStatus.running)
LinearProgressIndicator(value: item.progress.toDouble() / 100),
LinearProgressIndicator(value: item.progress!.toDouble() / 100),
if (item.status == UploadTaskStatus.complete ||
item.status == UploadTaskStatus.failed) ...[
Text('HTTP status code: ${item.response.statusCode}'),
if (item.response.response != null)
Text('HTTP status code: ${item.response!.statusCode}'),
if (item.response!.response != null)
Text(
item.response.response,
item.response!.response!,
style: Theme.of(context)
.textTheme
.caption
.caption!
.copyWith(fontFamily: 'monospace'),
),
]
Expand Down
Loading

0 comments on commit 210cc7b

Please sign in to comment.