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 theme.dart to be null safe. #3633

Merged
merged 43 commits into from
Feb 8, 2022
Merged
Show file tree
Hide file tree
Changes from 32 commits
Commits
Show all changes
43 commits
Select commit Hold shift + click to select a range
814d53b
Update globals.dart
polina-c Feb 4, 2022
8d5c3d8
ns
polina-c Feb 4, 2022
5044a39
ns
polina-c Feb 4, 2022
455f6c8
comments
polina-c Feb 4, 2022
9e71acb
ns
polina-c Feb 5, 2022
0bd4728
ns
polina-c Feb 5, 2022
59abcf8
Update theme.dart
polina-c Feb 5, 2022
f66fdf7
ignore
polina-c Feb 5, 2022
119d3f9
ideTheme
polina-c Feb 7, 2022
e810175
Update version.dart
polina-c Feb 7, 2022
1e5c40c
ns
polina-c Feb 4, 2022
6815f67
ns
polina-c Feb 5, 2022
a85d131
ns
polina-c Feb 5, 2022
81bc861
Update theme.dart
polina-c Feb 5, 2022
4cc8869
ignore
polina-c Feb 5, 2022
0bc089e
ideTheme
polina-c Feb 7, 2022
bffd848
Update utils.dart
polina-c Feb 7, 2022
b512d5e
Merge branch 'ns2' of github.com:polina-c/devtools into ns2
polina-c Feb 7, 2022
05b719f
Merge branch 'master' of github.com:flutter/devtools into ns2
polina-c Feb 7, 2022
d8a1b1f
Update about_dialog_test.dart
polina-c Feb 7, 2022
45b6625
Update theme.dart
polina-c Feb 7, 2022
5acf384
Update theme.dart
polina-c Feb 7, 2022
0c35da1
Update analytics_prompt_test.dart
polina-c Feb 7, 2022
23cf846
theme
polina-c Feb 7, 2022
c0eee12
Update banner_messages_test.dart
polina-c Feb 7, 2022
6bbd99f
Update code_size_attribution_test.dart
polina-c Feb 7, 2022
8469d8d
Update common_widgets_test.dart
polina-c Feb 7, 2022
0ecae82
Update cpu_profiler_test.dart
polina-c Feb 7, 2022
4f8a488
Update debugger_screen_test.dart
polina-c Feb 7, 2022
9811261
revert utils
polina-c Feb 7, 2022
033cfa0
Update debugger_screen_test.dart
polina-c Feb 7, 2022
f668f94
address comments
polina-c Feb 7, 2022
1f8ab25
Update chart_test.dart
polina-c Feb 7, 2022
03e432e
Update rebuild_counts.dart
polina-c Feb 7, 2022
784fde9
Update ide_theme_stub.dart
polina-c Feb 8, 2022
f8978fb
Update theme.dart
polina-c Feb 8, 2022
54d9999
Update theme.dart
polina-c Feb 8, 2022
ca2dcde
Merge branch 'master' of github.com:flutter/devtools into ns2
polina-c Feb 8, 2022
81a3dbc
Update theme.dart
polina-c Feb 8, 2022
d55c101
fix wrap
polina-c Feb 8, 2022
93a673b
Update theme_test.dart
polina-c Feb 8, 2022
d10eec2
Update vm_flag_widgets_test.dart
polina-c Feb 8, 2022
c280712
Update theme_test.dart
polina-c Feb 8, 2022
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
2 changes: 2 additions & 0 deletions packages/devtools_app/lib/src/performance/rebuild_counts.dart
Original file line number Diff line number Diff line change
Expand Up @@ -100,6 +100,7 @@ class RebuildCountModel {
}

// We've updated the build counts and possibly the locations.
// ignore: invalid_use_of_visible_for_testing_member, invalid_use_of_protected_member
_locations.notifyListeners();
}

Expand All @@ -116,6 +117,7 @@ class RebuildCountModel {
}

// We've updated the build counts.
// ignore: invalid_use_of_visible_for_testing_member, invalid_use_of_protected_member
_locations.notifyListeners();
}
}
Expand Down
75 changes: 39 additions & 36 deletions packages/devtools_app/lib/src/shared/theme.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 'package:flutter/material.dart';

Expand All @@ -18,9 +18,9 @@ const contrastForegroundWhite = _contrastForegroundWhite;
/// Constructs the light or dark theme for the app taking into account
/// IDE-supplied theming.
ThemeData themeFor({
@required bool isDarkTheme,
@required IdeTheme ideTheme,
ThemeData theme,
required bool isDarkTheme,
required IdeTheme? ideTheme,
ThemeData? theme,
}) {
ThemeData colorTheme;
// If the theme specifies a background color, use it to infer a theme.
Expand All @@ -44,43 +44,43 @@ ThemeData themeFor({
);
}

ThemeData _darkTheme(IdeTheme ideTheme) {
ThemeData _darkTheme(IdeTheme? ideTheme) {
final theme = ThemeData.dark();
final background = isValidDarkColor(ideTheme?.backgroundColor)
? ideTheme?.backgroundColor
? ideTheme!.backgroundColor!
: theme.canvasColor;
return _baseTheme(
theme: theme,
ideTheme: ideTheme,
primaryColor: devtoolsGrey[900],
primaryColor: devtoolsGrey[900]!,
backgroundColor: background,
indicatorColor: devtoolsBlue[400],
selectedRowColor: devtoolsGrey[600],
indicatorColor: devtoolsBlue[400]!,
selectedRowColor: devtoolsGrey[600]!,
);
}

ThemeData _lightTheme(IdeTheme ideTheme) {
ThemeData _lightTheme(IdeTheme? ideTheme) {
final theme = ThemeData.light();
final background = isValidLightColor(ideTheme?.backgroundColor)
? ideTheme?.backgroundColor
? ideTheme!.backgroundColor!
: theme.canvasColor;
return _baseTheme(
theme: theme,
ideTheme: ideTheme,
primaryColor: devtoolsBlue[600],
primaryColor: devtoolsBlue[600]!,
backgroundColor: background,
indicatorColor: Colors.yellowAccent[400],
selectedRowColor: devtoolsBlue[600],
indicatorColor: Colors.yellowAccent[400]!,
selectedRowColor: devtoolsBlue[600]!,
);
}

ThemeData _baseTheme({
@required ThemeData theme,
@required IdeTheme ideTheme,
@required Color primaryColor,
@required Color backgroundColor,
@required Color indicatorColor,
@required Color selectedRowColor,
required ThemeData theme,
required IdeTheme? ideTheme,
required Color primaryColor,
required Color backgroundColor,
required Color indicatorColor,
required Color selectedRowColor,
}) {
return theme.copyWith(
primaryColor: primaryColor,
Expand Down Expand Up @@ -127,14 +127,14 @@ ThemeData _baseTheme({
/// Flutter's luminance calculation.
const _lightDarkLuminanceThreshold = 0.1;

bool isValidDarkColor(Color color) {
bool isValidDarkColor(Color? color) {
if (color == null) {
return false;
}
return color.computeLuminance() <= _lightDarkLuminanceThreshold;
}

bool isValidLightColor(Color color) {
bool isValidLightColor(Color? color) {
if (color == null) {
return false;
}
Expand Down Expand Up @@ -256,7 +256,7 @@ extension DevToolsColorScheme on ColorScheme {
Color get toggleButtonsTitleSelected =>
isLight ? Colors.white : const Color(0xFF464646);

Color get toggleButtonsFillSelected => devtoolsBlue[400];
Color get toggleButtonsFillSelected => devtoolsBlue[400]!;

Color get grey => isLight
? const Color.fromARGB(255, 128, 128, 128)
Expand All @@ -276,7 +276,7 @@ extension DevToolsColorScheme on ColorScheme {
// TODO(jacobr): replace this with Theme.of(context).scaffoldBackgroundColor, but we use
// this in places where we do not have access to the context.
Color get defaultBackgroundColor =>
isLight ? Colors.grey[50] : Colors.grey[850];
isLight ? Colors.grey[50]! : Colors.grey[850]!;

Color get alternatingBackgroundColor => isLight
? defaultBackgroundColor.darken()
Expand Down Expand Up @@ -324,11 +324,11 @@ extension DevToolsColorScheme on ColorScheme {

// Bar color for current selection (hover).
Color get hoverSelectionBarColor =>
isLight ? Colors.lime[600] : Colors.yellowAccent;
isLight ? Colors.lime[600]! : Colors.yellowAccent;

// Highlight color for an selected item in the autocomplete dropdown list.
Color get autoCompleteHighlightColor =>
isLight ? Colors.grey[300] : Colors.grey[700];
isLight ? Colors.grey[300]! : Colors.grey[700]!;

Color get autoCompleteTextColor => isLight ? Colors.black : Colors.white;

Expand Down Expand Up @@ -381,13 +381,13 @@ extension DevToolsColorScheme on ColorScheme {
decoration: TextDecoration.none,
);

Color get expandedColor => isLight ? Colors.grey[200] : Colors.grey[800];
Color get expandedColor => isLight ? Colors.grey[200]! : Colors.grey[800]!;

Color get expandedTopContentColor =>
isLight ? Colors.grey[50] : Colors.grey[850];
isLight ? Colors.grey[50]! : Colors.grey[850]!;

Color get expandedBottomContentColor =>
isLight ? Colors.grey[200] : Colors.grey[800];
isLight ? Colors.grey[200]! : Colors.grey[800]!;

Gradient get verticalGradient => LinearGradient(
begin: Alignment.topCenter,
Expand Down Expand Up @@ -417,7 +417,7 @@ extension ThemeDataExtension on ThemeData {
bool get isDarkTheme => brightness == Brightness.dark;

TextStyle get regularTextStyle => TextStyle(
color: textTheme.bodyText2.color,
color: textTheme.bodyText2!.color,
fontSize: defaultFontSize,
);

Expand All @@ -432,7 +432,7 @@ extension ThemeDataExtension on ThemeData {
);

TextStyle get fixedFontStyle =>
textTheme.bodyText2.copyWith(fontFamily: 'RobotoMono');
textTheme.bodyText2!.copyWith(fontFamily: 'RobotoMono');

TextStyle get subtleFixedFontStyle =>
fixedFontStyle.copyWith(color: unselectedWidgetColor);
Expand All @@ -442,7 +442,7 @@ extension ThemeDataExtension on ThemeData {
);

TextStyle get devToolsTitleStyle =>
textTheme.headline6.copyWith(color: Colors.white);
textTheme.headline6!.copyWith(color: Colors.white);

Color get titleSolidBackgroundColor => colorScheme.isLight
? colorScheme.alternatingBackgroundColor
Expand Down Expand Up @@ -514,7 +514,7 @@ const longDuration = Duration(milliseconds: 400);
/// This is the standard duration to use for animations.
AnimationController defaultAnimationController(
TickerProvider vsync, {
double value,
double? value,
}) {
return AnimationController(
duration: defaultDuration,
Expand All @@ -528,7 +528,7 @@ AnimationController defaultAnimationController(
/// This is the standard duration to use for slow animations.
AnimationController longAnimationController(
TickerProvider vsync, {
double value,
double? value,
}) {
return AnimationController(
duration: longDuration,
Expand All @@ -554,7 +554,9 @@ double get chartFontSizeSmall => scaleByFontFactor(12.0);
const lightSelection = Color(0xFFD4D7DA);

bool includeText(
BuildContext context, double minScreenWidthForTextBeforeScaling) {
BuildContext context,
double? minScreenWidthForTextBeforeScaling,
) {
return minScreenWidthForTextBeforeScaling == null ||
MediaQuery.of(context).size.width >
scaleByFontFactor(minScreenWidthForTextBeforeScaling);
Expand All @@ -564,7 +566,8 @@ ButtonStyle denseAwareOutlinedButtonStyle(
BuildContext context,
double minScreenWidthForTextBeforeScaling,
) {
var buttonStyle = Theme.of(context).outlinedButtonTheme.style;
ButtonStyle buttonStyle =
Theme.of(context).outlinedButtonTheme.style ?? const ButtonStyle();
if (!includeText(context, minScreenWidthForTextBeforeScaling)) {
buttonStyle = buttonStyle.copyWith(
padding: MaterialStateProperty.resolveWith<EdgeInsets>((_) {
Expand Down
2 changes: 2 additions & 0 deletions packages/devtools_app/test/about_dialog_test.dart
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@

import 'package:devtools_app/devtools.dart' as devtools;
import 'package:devtools_app/src/app.dart';
import 'package:devtools_app/src/config_specific/ide_theme/ide_theme.dart';
import 'package:devtools_app/src/extension_points/extensions_base.dart';
import 'package:devtools_app/src/extension_points/extensions_external.dart';
import 'package:devtools_app/src/shared/globals.dart';
Expand All @@ -21,6 +22,7 @@ void main() {
aboutDialog = DevToolsAboutDialog();
setGlobal(DevToolsExtensionPoints, ExternalDevToolsExtensionPoints());
setGlobal(ServiceConnectionManager, FakeServiceManager());
setGlobal(IdeTheme, IdeTheme());
});

testWidgets('builds dialog', (WidgetTester tester) async {
Expand Down
2 changes: 2 additions & 0 deletions packages/devtools_app/test/analytics_prompt_test.dart
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@

import 'package:devtools_app/src/analytics/analytics_controller.dart';
import 'package:devtools_app/src/analytics/prompt.dart';
import 'package:devtools_app/src/config_specific/ide_theme/ide_theme.dart';
import 'package:devtools_app/src/shared/common_widgets.dart';
import 'package:devtools_app/src/shared/globals.dart';
import 'package:devtools_app/src/shared/service_manager.dart';
Expand All @@ -32,6 +33,7 @@ void main() {
setUp(() {
didCallEnableAnalytics = false;
setGlobal(ServiceConnectionManager, FakeServiceManager());
setGlobal(IdeTheme, IdeTheme());
});
group('with analytics enabled', () {
group('on first run', () {
Expand Down
2 changes: 2 additions & 0 deletions packages/devtools_app/test/app_size_screen_test.dart
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ import 'dart:convert';
import 'package:devtools_app/src/app_size/app_size_controller.dart';
import 'package:devtools_app/src/app_size/app_size_screen.dart';
import 'package:devtools_app/src/app_size/app_size_table.dart';
import 'package:devtools_app/src/config_specific/ide_theme/ide_theme.dart';
import 'package:devtools_app/src/shared/common_widgets.dart';
import 'package:devtools_app/src/shared/file_import.dart';
import 'package:devtools_app/src/shared/globals.dart';
Expand All @@ -29,6 +30,7 @@ import 'test_data/app_size_test_data/unsupported_file.dart';
void main() {
setUp(() {
setGlobal(ServiceConnectionManager, FakeServiceManager());
setGlobal(IdeTheme, IdeTheme());
});

final lastModifiedTime = DateTime.parse('2020-07-28 13:29:00');
Expand Down
2 changes: 2 additions & 0 deletions packages/devtools_app/test/banner_messages_test.dart
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@

// @dart=2.9

import 'package:devtools_app/src/config_specific/ide_theme/ide_theme.dart';
import 'package:devtools_app/src/profiler/profiler_screen.dart';
import 'package:devtools_app/src/shared/banner_messages.dart';
import 'package:devtools_app/src/shared/common_widgets.dart';
Expand All @@ -23,6 +24,7 @@ void main() {
controller = BannerMessagesController();
fakeServiceManager = FakeServiceManager();
setGlobal(ServiceConnectionManager, fakeServiceManager);
setGlobal(IdeTheme, IdeTheme());
});

group('BannerMessages', () {
Expand Down
2 changes: 2 additions & 0 deletions packages/devtools_app/test/code_size_attribution_test.dart
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
// @dart=2.9

import 'package:devtools_app/src/app_size/code_size_attribution.dart';
import 'package:devtools_app/src/config_specific/ide_theme/ide_theme.dart';
import 'package:devtools_app/src/shared/globals.dart';
import 'package:devtools_app/src/shared/service_manager.dart';
import 'package:devtools_app/src/shared/table.dart';
Expand All @@ -21,6 +22,7 @@ void main() {

setUp(() {
setGlobal(ServiceConnectionManager, FakeServiceManager());
setGlobal(IdeTheme, IdeTheme());
callGraph = generateCallGraphWithDominators(
precompilerTrace,
NodeType.packageNode,
Expand Down
2 changes: 2 additions & 0 deletions packages/devtools_app/test/common_widgets_test.dart
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@

// @dart=2.9

import 'package:devtools_app/src/config_specific/ide_theme/ide_theme.dart';
import 'package:devtools_app/src/shared/common_widgets.dart';
import 'package:devtools_app/src/shared/globals.dart';
import 'package:devtools_app/src/shared/service_manager.dart';
Expand All @@ -22,6 +23,7 @@ void main() {
group('Common widgets', () {
setUp(() {
setGlobal(ServiceConnectionManager, FakeServiceManager());
setGlobal(IdeTheme, IdeTheme());
});

testWidgetsWithWindowSize('recordingInfo builds info for pause', windowSize,
Expand Down
2 changes: 2 additions & 0 deletions packages/devtools_app/test/cpu_profiler_test.dart
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
// @dart=2.9

import 'package:devtools_app/src/charts/flame_chart.dart';
import 'package:devtools_app/src/config_specific/ide_theme/ide_theme.dart';
import 'package:devtools_app/src/config_specific/import_export/import_export.dart';
import 'package:devtools_app/src/profiler/cpu_profile_bottom_up.dart';
import 'package:devtools_app/src/profiler/cpu_profile_call_tree.dart';
Expand Down Expand Up @@ -42,6 +43,7 @@ void main() {
.thenReturn(false);
setGlobal(ServiceConnectionManager, fakeServiceManager);
setGlobal(OfflineModeController, OfflineModeController());
setGlobal(IdeTheme, IdeTheme());
});

group('CpuProfiler', () {
Expand Down
6 changes: 3 additions & 3 deletions packages/devtools_app/test/debugger_screen_test.dart
Original file line number Diff line number Diff line change
Expand Up @@ -7,14 +7,13 @@
import 'dart:io';

import 'package:ansicolor/ansicolor.dart';
import 'package:devtools_app/devtools_app.dart';
import 'package:devtools_app/src/config_specific/ide_theme/ide_theme.dart';
import 'package:devtools_app/src/debugger/console.dart';
import 'package:devtools_app/src/debugger/controls.dart';
import 'package:devtools_app/src/debugger/debugger_controller.dart';
import 'package:devtools_app/src/debugger/debugger_model.dart';
import 'package:devtools_app/src/debugger/debugger_screen.dart';
import 'package:devtools_app/src/debugger/program_explorer_model.dart';
import 'package:devtools_app/src/shared/globals.dart';
import 'package:devtools_app/src/shared/service_manager.dart';
import 'package:devtools_test/devtools_test.dart';
import 'package:flutter/material.dart';
import 'package:flutter/services.dart';
Expand All @@ -35,6 +34,7 @@ void main() {
when(fakeServiceManager.connectedApp.isProfileBuildNow).thenReturn(false);
when(fakeServiceManager.connectedApp.isDartWebAppNow).thenReturn(false);
setGlobal(ServiceConnectionManager, fakeServiceManager);
setGlobal(IdeTheme, IdeTheme());
fakeServiceManager.consoleService.ensureServiceInitialized();
});

Expand Down