Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Migrate survey.dart to null safety. #3684

Merged
merged 4 commits into from
Feb 15, 2022
Merged
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
50 changes: 25 additions & 25 deletions packages/devtools_app/lib/src/shared/survey.dart
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.

// @dart=2.9
// ignore_for_file: import_of_legacy_library_into_null_safe

import 'dart:convert';

Expand Down Expand Up @@ -33,15 +33,15 @@ class SurveyService {
/// it.
static const _notificationDuration = Duration(days: 1);

DevToolsSurvey _cachedSurvey;
DevToolsSurvey? _cachedSurvey;

Future<DevToolsSurvey> get activeSurvey async {
Future<DevToolsSurvey?> get activeSurvey async {
// If the server is unavailable we don't need to do anything survey related.
if (!server.isDevToolsServerAvailable) return null;

_cachedSurvey ??= await _fetchSurveyContent();
if (_cachedSurvey != null) {
await server.setActiveSurvey(_cachedSurvey.id);
await server.setActiveSurvey(_cachedSurvey!.id);
}

if (await _shouldShowSurvey()) {
Expand All @@ -58,23 +58,23 @@ class SurveyService {
NotificationAction(
_noThanksLabel,
() => _noThanksPressed(
message: message,
message: message!,
context: context,
),
),
NotificationAction(
_takeSurveyLabel,
() => _takeSurveyPressed(
surveyUrl: _generateSurveyUrl(survey.url),
message: message,
surveyUrl: _generateSurveyUrl(survey.url!),
message: message!,
context: context,
),
isPrimary: true,
),
];
WidgetsBinding.instance.addPostFrameCallback((_) {
final didPush = Notifications.of(context).push(
message,
WidgetsBinding.instance!.addPostFrameCallback((_) {
final didPush = Notifications.of(context)!.push(
message!,
actions: actions,
duration: _notificationDuration,
allowDuplicates: false,
Expand Down Expand Up @@ -108,13 +108,13 @@ class SurveyService {

final currentTimeMs = DateTime.now().millisecondsSinceEpoch;
final activeSurveyRange = Range(
_cachedSurvey.startDate.millisecondsSinceEpoch,
_cachedSurvey.endDate.millisecondsSinceEpoch,
_cachedSurvey!.startDate!.millisecondsSinceEpoch,
_cachedSurvey!.endDate!.millisecondsSinceEpoch,
);
return activeSurveyRange.contains(currentTimeMs);
}

Future<DevToolsSurvey> _fetchSurveyContent() async {
Future<DevToolsSurvey?> _fetchSurveyContent() async {
try {
final response = await get(_metadataUrl);
if (response.statusCode == 200) {
Expand All @@ -128,21 +128,21 @@ class SurveyService {
}

void _noThanksPressed({
@required String message,
@required BuildContext context,
required String message,
required BuildContext context,
}) async {
await server.setSurveyActionTaken();
Notifications.of(context).dismiss(message);
Notifications.of(context)!.dismiss(message);
}

void _takeSurveyPressed({
@required String surveyUrl,
@required String message,
@required BuildContext context,
required String surveyUrl,
required String message,
required BuildContext context,
}) async {
await launchUrl(surveyUrl, context);
await server.setSurveyActionTaken();
Notifications.of(context).dismiss(message);
Notifications.of(context)!.dismiss(message);
}
}

Expand All @@ -166,13 +166,13 @@ class DevToolsSurvey {
return DevToolsSurvey._(id, startDate, endDate, title, surveyUrl);
}

final String id;
final String? id;

final DateTime startDate;
final DateTime? startDate;

final DateTime endDate;
final DateTime? endDate;

final String title;
final String? title;

final String url;
final String? url;
}