From 61c036b623a65b8368cf2046ad99ff7de6977ace Mon Sep 17 00:00:00 2001 From: Parker Lougheed Date: Tue, 24 Sep 2024 16:41:04 -0400 Subject: [PATCH] Minor clean up and simplifications (#3059) --- pkgs/dart_services/lib/src/compiling.dart | 4 +- pkgs/dartpad_shared/analysis_options.yaml | 1 + pkgs/dartpad_shared/lib/model.dart | 88 +++++++++++------------ pkgs/dartpad_shared/lib/services.dart | 10 +-- pkgs/dartpad_shared/pubspec.yaml | 2 +- pkgs/dartpad_ui/analysis_options.yaml | 1 + pkgs/dartpad_ui/lib/editor/editor.dart | 2 +- pkgs/dartpad_ui/lib/embed.dart | 2 +- pkgs/dartpad_ui/lib/execution/frame.dart | 43 +++++------ pkgs/dartpad_ui/lib/extensions.dart | 7 +- pkgs/dartpad_ui/lib/flutter_samples.dart | 5 +- pkgs/dartpad_ui/lib/gists.dart | 12 ++-- pkgs/dartpad_ui/lib/main.dart | 20 +++--- pkgs/dartpad_ui/lib/model.dart | 5 +- pkgs/dartpad_ui/lib/problems.dart | 10 +-- pkgs/dartpad_ui/lib/theme.dart | 44 ++++++------ pkgs/dartpad_ui/lib/utils.dart | 2 +- pkgs/dartpad_ui/lib/widgets.dart | 25 ++++--- pkgs/dartpad_ui/test/gists_test.dart | 10 +-- 19 files changed, 144 insertions(+), 149 deletions(-) diff --git a/pkgs/dart_services/lib/src/compiling.dart b/pkgs/dart_services/lib/src/compiling.dart index 5cc49858f..8f3f689e7 100644 --- a/pkgs/dart_services/lib/src/compiling.dart +++ b/pkgs/dart_services/lib/src/compiling.dart @@ -302,13 +302,13 @@ String _rewritePaths(String output) { final lines = output.split('\n'); return lines.map((line) { - final token1 = 'lib/bootstrap.dart:'; + const token1 = 'lib/bootstrap.dart:'; var index = line.indexOf(token1); if (index != -1) { return 'main.dart:${line.substring(index + token1.length)}'; } - final token2 = 'lib/main.dart:'; + const token2 = 'lib/main.dart:'; index = line.indexOf(token2); if (index != -1) { return 'main.dart:${line.substring(index + token2.length)}'; diff --git a/pkgs/dartpad_shared/analysis_options.yaml b/pkgs/dartpad_shared/analysis_options.yaml index c5bc1a8fc..6ebfb591c 100644 --- a/pkgs/dartpad_shared/analysis_options.yaml +++ b/pkgs/dartpad_shared/analysis_options.yaml @@ -8,5 +8,6 @@ analyzer: linter: rules: + - avoid_dynamic_calls - prefer_final_in_for_each - prefer_final_locals diff --git a/pkgs/dartpad_shared/lib/model.dart b/pkgs/dartpad_shared/lib/model.dart index 43787e5a2..252cd6b77 100644 --- a/pkgs/dartpad_shared/lib/model.dart +++ b/pkgs/dartpad_shared/lib/model.dart @@ -13,10 +13,10 @@ class SourceRequest { SourceRequest({required this.source, this.offset}); - factory SourceRequest.fromJson(Map json) => + factory SourceRequest.fromJson(Map json) => _$SourceRequestFromJson(json); - Map toJson() => _$SourceRequestToJson(this); + Map toJson() => _$SourceRequestToJson(this); @override String toString() => 'SourceRequest[source=$source,offset=$offset]'; @@ -30,10 +30,10 @@ class AnalysisResponse { required this.issues, }); - factory AnalysisResponse.fromJson(Map json) => + factory AnalysisResponse.fromJson(Map json) => _$AnalysisResponseFromJson(json); - Map toJson() => _$AnalysisResponseToJson(this); + Map toJson() => _$AnalysisResponseToJson(this); } @JsonSerializable() @@ -56,10 +56,10 @@ class AnalysisIssue { this.contextMessages, }); - factory AnalysisIssue.fromJson(Map json) => + factory AnalysisIssue.fromJson(Map json) => _$AnalysisIssueFromJson(json); - Map toJson() => _$AnalysisIssueToJson(this); + Map toJson() => _$AnalysisIssueToJson(this); int get severity { return switch (kind) { @@ -88,10 +88,10 @@ class Location { this.column = -1, }); - factory Location.fromJson(Map json) => + factory Location.fromJson(Map json) => _$LocationFromJson(json); - Map toJson() => _$LocationToJson(this); + Map toJson() => _$LocationToJson(this); } @JsonSerializable() @@ -104,10 +104,10 @@ class DiagnosticMessage { required this.location, }); - factory DiagnosticMessage.fromJson(Map json) => + factory DiagnosticMessage.fromJson(Map json) => _$DiagnosticMessageFromJson(json); - Map toJson() => _$DiagnosticMessageToJson(this); + Map toJson() => _$DiagnosticMessageToJson(this); } @JsonSerializable() @@ -116,10 +116,10 @@ class CompileRequest { CompileRequest({required this.source}); - factory CompileRequest.fromJson(Map json) => + factory CompileRequest.fromJson(Map json) => _$CompileRequestFromJson(json); - Map toJson() => _$CompileRequestToJson(this); + Map toJson() => _$CompileRequestToJson(this); } @JsonSerializable() @@ -128,10 +128,10 @@ class CompileResponse { CompileResponse({required this.result}); - factory CompileResponse.fromJson(Map json) => + factory CompileResponse.fromJson(Map json) => _$CompileResponseFromJson(json); - Map toJson() => _$CompileResponseToJson(this); + Map toJson() => _$CompileResponseToJson(this); } @JsonSerializable() @@ -144,10 +144,10 @@ class CompileDDCResponse { required this.modulesBaseUrl, }); - factory CompileDDCResponse.fromJson(Map json) => + factory CompileDDCResponse.fromJson(Map json) => _$CompileDDCResponseFromJson(json); - Map toJson() => _$CompileDDCResponseToJson(this); + Map toJson() => _$CompileDDCResponseToJson(this); } @JsonSerializable() @@ -160,10 +160,10 @@ class FormatResponse { required this.offset, }); - factory FormatResponse.fromJson(Map json) => + factory FormatResponse.fromJson(Map json) => _$FormatResponseFromJson(json); - Map toJson() => _$FormatResponseToJson(this); + Map toJson() => _$FormatResponseToJson(this); @override String toString() => 'FormatResponse[source=$source,offset=$offset]'; @@ -184,10 +184,10 @@ class FixesResponse { required this.assists, }); - factory FixesResponse.fromJson(Map json) => + factory FixesResponse.fromJson(Map json) => _$FixesResponseFromJson(json); - Map toJson() => _$FixesResponseToJson(this); + Map toJson() => _$FixesResponseToJson(this); } @JsonSerializable() @@ -204,10 +204,10 @@ class SourceChange { this.selectionOffset, }); - factory SourceChange.fromJson(Map json) => + factory SourceChange.fromJson(Map json) => _$SourceChangeFromJson(json); - Map toJson() => _$SourceChangeToJson(this); + Map toJson() => _$SourceChangeToJson(this); @override String toString() => 'SourceChange [$message]'; @@ -225,10 +225,10 @@ class SourceEdit { required this.replacement, }); - factory SourceEdit.fromJson(Map json) => + factory SourceEdit.fromJson(Map json) => _$SourceEditFromJson(json); - Map toJson() => _$SourceEditToJson(this); + Map toJson() => _$SourceEditToJson(this); @override String toString() => 'SourceEdit [$offset,$length,$replacement]'; @@ -246,10 +246,10 @@ class LinkedEditGroup { required this.suggestions, }); - factory LinkedEditGroup.fromJson(Map json) => + factory LinkedEditGroup.fromJson(Map json) => _$LinkedEditGroupFromJson(json); - Map toJson() => _$LinkedEditGroupToJson(this); + Map toJson() => _$LinkedEditGroupToJson(this); } @JsonSerializable() @@ -262,10 +262,10 @@ class LinkedEditSuggestion { required this.kind, }); - factory LinkedEditSuggestion.fromJson(Map json) => + factory LinkedEditSuggestion.fromJson(Map json) => _$LinkedEditSuggestionFromJson(json); - Map toJson() => _$LinkedEditSuggestionToJson(this); + Map toJson() => _$LinkedEditSuggestionToJson(this); } @JsonSerializable() @@ -286,10 +286,10 @@ class DocumentResponse { this.propagatedType, }); - factory DocumentResponse.fromJson(Map json) => + factory DocumentResponse.fromJson(Map json) => _$DocumentResponseFromJson(json); - Map toJson() => _$DocumentResponseToJson(this); + Map toJson() => _$DocumentResponseToJson(this); } @JsonSerializable() @@ -310,10 +310,10 @@ class CompleteResponse { required this.suggestions, }); - factory CompleteResponse.fromJson(Map json) => + factory CompleteResponse.fromJson(Map json) => _$CompleteResponseFromJson(json); - Map toJson() => _$CompleteResponseToJson(this); + Map toJson() => _$CompleteResponseToJson(this); } @JsonSerializable() @@ -342,10 +342,10 @@ class CompletionSuggestion { required this.elementParameters, }); - factory CompletionSuggestion.fromJson(Map json) => + factory CompletionSuggestion.fromJson(Map json) => _$CompletionSuggestionFromJson(json); - Map toJson() => _$CompletionSuggestionToJson(this); + Map toJson() => _$CompletionSuggestionToJson(this); @override String toString() => '[$relevance] [$kind] $completion'; @@ -369,10 +369,10 @@ class VersionResponse { required this.packages, }); - factory VersionResponse.fromJson(Map json) => + factory VersionResponse.fromJson(Map json) => _$VersionResponseFromJson(json); - Map toJson() => _$VersionResponseToJson(this); + Map toJson() => _$VersionResponseToJson(this); } @JsonSerializable() @@ -383,10 +383,10 @@ class GeminiResponse { required this.response, }); - factory GeminiResponse.fromJson(Map json) => + factory GeminiResponse.fromJson(Map json) => _$GeminiResponseFromJson(json); - Map toJson() => _$GeminiResponseToJson(this); + Map toJson() => _$GeminiResponseToJson(this); @override String toString() => 'GeminiResponse[response=$response]'; @@ -400,10 +400,10 @@ class OpenInIdxRequest { required this.code, }); - factory OpenInIdxRequest.fromJson(Map json) => + factory OpenInIdxRequest.fromJson(Map json) => _$OpenInIdxRequestFromJson(json); - Map toJson() => _$OpenInIdxRequestToJson(this); + Map toJson() => _$OpenInIdxRequestToJson(this); @override String toString() => 'OpenInIdxRequest [${code.substring(0, 10)} (...)'; @@ -417,10 +417,10 @@ class OpenInIdxResponse { required this.idxUrl, }); - factory OpenInIdxResponse.fromJson(Map json) => + factory OpenInIdxResponse.fromJson(Map json) => _$OpenInIdxResponseFromJson(json); - Map toJson() => _$OpenInIdxResponseToJson(this); + Map toJson() => _$OpenInIdxResponseToJson(this); @override String toString() => 'OpenInIdxResponse [$idxUrl]'; @@ -438,8 +438,8 @@ class PackageInfo { required this.supported, }); - factory PackageInfo.fromJson(Map json) => + factory PackageInfo.fromJson(Map json) => _$PackageInfoFromJson(json); - Map toJson() => _$PackageInfoToJson(this); + Map toJson() => _$PackageInfoToJson(this); } diff --git a/pkgs/dartpad_shared/lib/services.dart b/pkgs/dartpad_shared/lib/services.dart index 886f6b7eb..73047311d 100644 --- a/pkgs/dartpad_shared/lib/services.dart +++ b/pkgs/dartpad_shared/lib/services.dart @@ -53,7 +53,7 @@ class ServicesClient { Future _requestGet( String action, - T Function(Map json) responseFactory, + T Function(Map json) responseFactory, ) async { final response = await client.get(Uri.parse('${rootUrl}api/v3/$action')); @@ -62,7 +62,7 @@ class ServicesClient { } else { try { return responseFactory( - json.decode(response.body) as Map); + json.decode(response.body) as Map); } on FormatException catch (e) { throw ApiRequestError('$action: $e', response.body); } @@ -71,8 +71,8 @@ class ServicesClient { Future _requestPost( String action, - Map request, - T Function(Map json) responseFactory, + Map request, + T Function(Map json) responseFactory, ) async { final response = await client.post( Uri.parse('${rootUrl}api/v3/$action'), @@ -84,7 +84,7 @@ class ServicesClient { } else { try { return responseFactory( - json.decode(response.body) as Map); + json.decode(response.body) as Map); } on FormatException catch (e) { throw ApiRequestError('$action: $e', response.body); } diff --git a/pkgs/dartpad_shared/pubspec.yaml b/pkgs/dartpad_shared/pubspec.yaml index cca44fc81..80c362dde 100644 --- a/pkgs/dartpad_shared/pubspec.yaml +++ b/pkgs/dartpad_shared/pubspec.yaml @@ -3,7 +3,7 @@ description: Shared code between the DartPad frontend and backend. publish_to: none environment: - sdk: ^3.4.0 + sdk: ^3.5.0 dependencies: http: ^1.2.1 diff --git a/pkgs/dartpad_ui/analysis_options.yaml b/pkgs/dartpad_ui/analysis_options.yaml index ac5006b34..4bc94665a 100644 --- a/pkgs/dartpad_ui/analysis_options.yaml +++ b/pkgs/dartpad_ui/analysis_options.yaml @@ -9,6 +9,7 @@ analyzer: linter: rules: - directives_ordering + - invalid_runtime_check_with_js_interop_types - prefer_final_in_for_each - prefer_final_locals - prefer_relative_imports diff --git a/pkgs/dartpad_ui/lib/editor/editor.dart b/pkgs/dartpad_ui/lib/editor/editor.dart index 445126f37..1278cd2ae 100644 --- a/pkgs/dartpad_ui/lib/editor/editor.dart +++ b/pkgs/dartpad_ui/lib/editor/editor.dart @@ -39,7 +39,7 @@ web.Element _codeMirrorFactory(int viewId) { codeMirrorInstance = CodeMirror( div, - { + { 'lineNumbers': true, 'lineWrapping': true, 'mode': 'dart', diff --git a/pkgs/dartpad_ui/lib/embed.dart b/pkgs/dartpad_ui/lib/embed.dart index 820a3765e..97736d3a7 100644 --- a/pkgs/dartpad_ui/lib/embed.dart +++ b/pkgs/dartpad_ui/lib/embed.dart @@ -30,7 +30,7 @@ void handleEmbedMessage(AppServices services, {bool runOnInject = false}) { ); parent.postMessage( - ({'sender': web.window.name, 'type': 'ready'}).jsify(), + {'sender': web.window.name, 'type': 'ready'}.jsify(), '*'.toJS, ); } diff --git a/pkgs/dartpad_ui/lib/execution/frame.dart b/pkgs/dartpad_ui/lib/execution/frame.dart index 99db80804..795f96c9e 100644 --- a/pkgs/dartpad_ui/lib/execution/frame.dart +++ b/pkgs/dartpad_ui/lib/execution/frame.dart @@ -163,30 +163,25 @@ require(["dartpad_main", "dart_sdk"], function(dartpad_main, dart_sdk) { } void _initListener() { - web.window.addEventListener( - 'message', - (web.Event event) { - if (event is web.MessageEvent) { - final data = event.data.dartify() as Map; - if (data['sender'] != 'frame') { - return; - } - final type = data['type'] as String?; - - if (type == 'stderr') { - // Ignore any exceptions before the iframe has completed - // initialization. - if (_readyCompleter.isCompleted) { - _stdoutController.add(data['message'] as String); - } - } else if (type == 'ready' && !_readyCompleter.isCompleted) { - _readyCompleter.complete(); - } else if (data['message'] != null) { - _stdoutController.add(data['message'] as String); - } - } - }.toJS, - false.toJS); + web.window.onMessage.forEach((event) { + final data = event.data.dartify() as Map; + if (data['sender'] != 'frame') { + return; + } + final type = data['type'] as String?; + + if (type == 'stderr') { + // Ignore any exceptions before the iframe has completed + // initialization. + if (_readyCompleter.isCompleted) { + _stdoutController.add(data['message'] as String); + } + } else if (type == 'ready' && !_readyCompleter.isCompleted) { + _readyCompleter.complete(); + } else if (data['message'] != null) { + _stdoutController.add(data['message'] as String); + } + }); } } diff --git a/pkgs/dartpad_ui/lib/extensions.dart b/pkgs/dartpad_ui/lib/extensions.dart index 5065153d6..c7c198f53 100644 --- a/pkgs/dartpad_ui/lib/extensions.dart +++ b/pkgs/dartpad_ui/lib/extensions.dart @@ -9,8 +9,8 @@ extension GoRouteHelpers on GoRouter { /// [param] with [value]. If [value] is null, the parameter /// is removed. void replaceQueryParam(String param, String? value) { - final queryParameters = routeInformationProvider.value.uri.queryParameters; - final newQueryParameters = Map.from(queryParameters); + final currentUri = routeInformationProvider.value.uri; + final newQueryParameters = {...currentUri.queryParameters}; if (value == null) { newQueryParameters.remove(param); @@ -18,7 +18,6 @@ extension GoRouteHelpers on GoRouter { newQueryParameters[param] = value; } - final newUri = routeInformationProvider.value.uri; - go(newUri.replace(queryParameters: newQueryParameters).toString()); + go(currentUri.replace(queryParameters: newQueryParameters).toString()); } } diff --git a/pkgs/dartpad_ui/lib/flutter_samples.dart b/pkgs/dartpad_ui/lib/flutter_samples.dart index 42209c7d3..82c15fe72 100644 --- a/pkgs/dartpad_ui/lib/flutter_samples.dart +++ b/pkgs/dartpad_ui/lib/flutter_samples.dart @@ -13,8 +13,9 @@ class FlutterSampleLoader { }) async { // There are only two hosted versions of the docs: master/main and stable. final sampleUrl = switch (channel) { - 'master' => 'https://main-api.flutter.dev/snippets/$sampleId.dart', - 'main' => 'https://main-api.flutter.dev/snippets/$sampleId.dart', + 'master' || + 'main' => + 'https://main-api.flutter.dev/snippets/$sampleId.dart', _ => 'https://api.flutter.dev/snippets/$sampleId.dart', }; diff --git a/pkgs/dartpad_ui/lib/gists.dart b/pkgs/dartpad_ui/lib/gists.dart index c0056f568..c9b3b44e7 100644 --- a/pkgs/dartpad_ui/lib/gists.dart +++ b/pkgs/dartpad_ui/lib/gists.dart @@ -19,7 +19,7 @@ class GistLoader { '(${response.statusCode} ${response.reasonPhrase}})'); } - return Gist.fromJson(jsonDecode(response.body) as Map); + return Gist.fromJson(jsonDecode(response.body) as Map); } void dispose() { @@ -45,7 +45,7 @@ class Gist { _validateGist(); } - factory Gist.fromJson(Map json) { + factory Gist.fromJson(Map json) { /* { "id": "d3bd83918d21b6d5f778bdc69c3d36d6", "description": "Fibonacci", @@ -70,15 +70,15 @@ class Gist { } }, } */ - final owner = json['owner'] as Map; - final files = json['files'] as Map; + final owner = json['owner'] as Map; + final files = json['files'] as Map; return Gist( id: json['id'] as String, description: json['description'] as String?, owner: owner['login'] as String?, files: files.values - .cast>() + .cast>() .map(GistFile.fromJson) .toList(), ); @@ -123,7 +123,7 @@ class GistFile { required this.content, }); - factory GistFile.fromJson(Map json) { + factory GistFile.fromJson(Map json) { return GistFile( fileName: json['filename'] as String, truncated: json['truncated'] as bool, diff --git a/pkgs/dartpad_ui/lib/main.dart b/pkgs/dartpad_ui/lib/main.dart index c4aaf5ee3..bdf57530c 100644 --- a/pkgs/dartpad_ui/lib/main.dart +++ b/pkgs/dartpad_ui/lib/main.dart @@ -126,7 +126,6 @@ class _DartPadAppState extends State { final runOnLoad = state.uri.queryParameters['run'] == 'true'; return DartPadMainPage( - title: appName, path: path, initialChannel: channelParam, embedMode: embedMode, @@ -156,7 +155,7 @@ class _DartPadAppState extends State { ), brightness: Brightness.light, dividerColor: lightDividerColor, - dividerTheme: DividerThemeData( + dividerTheme: const DividerThemeData( color: lightDividerColor, ), scaffoldBackgroundColor: Colors.white, @@ -179,10 +178,10 @@ class _DartPadAppState extends State { ), brightness: Brightness.dark, dividerColor: darkDividerColor, - dividerTheme: DividerThemeData( + dividerTheme: const DividerThemeData( color: darkDividerColor, ), - textButtonTheme: TextButtonThemeData( + textButtonTheme: const TextButtonThemeData( style: ButtonStyle( foregroundColor: WidgetStatePropertyAll(darkLinkButtonColor), ), @@ -199,7 +198,6 @@ class _DartPadAppState extends State { } class DartPadMainPage extends StatefulWidget { - final String title; final String? initialChannel; final bool embedMode; final bool runOnLoad; @@ -208,8 +206,8 @@ class DartPadMainPage extends StatefulWidget { final String? builtinSampleId; final String? flutterSampleId; final String? path; + DartPadMainPage({ - required this.title, required this.initialChannel, required this.embedMode, required this.runOnLoad, @@ -901,10 +899,10 @@ class SectionWidget extends StatelessWidget { @override Widget build(BuildContext context) { - var c = child; + var finalChild = child; if (title != null || actions != null) { - c = Column( + finalChild = Column( children: [ Row( children: [ @@ -921,7 +919,7 @@ class SectionWidget extends StatelessWidget { return Padding( padding: const EdgeInsets.all(denseSpacing), - child: c, + child: finalChild, ); } } @@ -1148,9 +1146,7 @@ class ContinueInMenu extends StatelessWidget { ...[ MenuItemButton( trailingIcon: const Logo(type: 'idx'), - onPressed: () { - openInIdx(); - }, + onPressed: openInIdx, child: const Padding( padding: EdgeInsets.fromLTRB(0, 0, 32, 0), child: Text('IDX'), diff --git a/pkgs/dartpad_ui/lib/model.dart b/pkgs/dartpad_ui/lib/model.dart index a14e1badb..eb73ae351 100644 --- a/pkgs/dartpad_ui/lib/model.dart +++ b/pkgs/dartpad_ui/lib/model.dart @@ -370,9 +370,8 @@ class AppServices { // register the new if (_executionService != null) { - stdoutSub = _executionService!.onStdout.listen((event) { - appModel.appendLineToConsole(event); - }); + stdoutSub = + _executionService!.onStdout.listen(appModel.appendLineToConsole); } } diff --git a/pkgs/dartpad_ui/lib/problems.dart b/pkgs/dartpad_ui/lib/problems.dart index 92a69c636..c81514b1e 100644 --- a/pkgs/dartpad_ui/lib/problems.dart +++ b/pkgs/dartpad_ui/lib/problems.dart @@ -72,8 +72,7 @@ class ProblemWidget extends StatelessWidget { @override Widget build(BuildContext context) { - final theme = Theme.of(context); - final colorScheme = theme.colorScheme; + final colorScheme = Theme.of(context).colorScheme; final widget = Padding( padding: const EdgeInsets.only(bottom: _rowPadding), @@ -104,21 +103,22 @@ class ProblemWidget extends StatelessWidget { ) ], ), - if (issue.correction != null) const SizedBox(height: _rowPadding), - if (issue.correction != null) + if (issue.correction case final correction?) ...[ + const SizedBox(height: _rowPadding), Row( children: [ const SizedBox.square(dimension: smallIconSize), const SizedBox(width: denseSpacing), Expanded( child: Text( - issue.correction!, + correction, maxLines: 1, overflow: TextOverflow.ellipsis, ), ), ], ), + ], ], ), ); diff --git a/pkgs/dartpad_ui/lib/theme.dart b/pkgs/dartpad_ui/lib/theme.dart index 9cd38ca23..97932a8f1 100644 --- a/pkgs/dartpad_ui/lib/theme.dart +++ b/pkgs/dartpad_ui/lib/theme.dart @@ -21,28 +21,28 @@ const double toolbarHeight = 32.0; const double toolbarItemHeight = 40.0; -Color lightPrimaryColor = const Color(0xff1967D2); -Color lightSurfaceColor = const Color(0xFFF5F5F7); -Color lightSurfaceVariantColor = const Color(0xFFECECF1); -Color lightDividerColor = const Color(0xFFDCE2E8); -Color lightLinkButtonColor = lightPrimaryColor; -Color lightErrorColor = Colors.red.shade400; -Color lightWarningColor = Colors.yellow.shade700; -Color lightInfoColor = Colors.blue.shade400; -Color lightIssueColor = Colors.grey.shade400; - -Color darkPrimaryColor = const Color(0xFF1c2834); -Color darkSurfaceColor = const Color(0xFF1C2834); -Color darkSurfaceVariantColor = const Color(0xFF2B3B4F); -Color darkDividerColor = const Color(0xFF1C2834); -Color darkScaffoldColor = const Color(0xFF0C141D); -Color darkLinkButtonColor = Colors.white; -Color darkErrorColor = Colors.red.shade500; -Color darkWarningColor = Colors.yellow.shade500; -Color darkInfoColor = Colors.blue.shade500; -Color darkIssueColor = Colors.grey.shade700; - -Color runButtonColor = const Color(0xFF168afd); +const Color lightPrimaryColor = Color(0xff1967D2); +const Color lightSurfaceColor = Color(0xFFF5F5F7); +const Color lightSurfaceVariantColor = Color(0xFFECECF1); +const Color lightDividerColor = Color(0xFFDCE2E8); +const Color lightLinkButtonColor = lightPrimaryColor; +final Color lightErrorColor = Colors.red.shade400; +final Color lightWarningColor = Colors.yellow.shade700; +final Color lightInfoColor = Colors.blue.shade400; +final Color lightIssueColor = Colors.grey.shade400; + +const Color darkPrimaryColor = Color(0xFF1c2834); +const Color darkSurfaceColor = Color(0xFF1C2834); +const Color darkSurfaceVariantColor = Color(0xFF2B3B4F); +const Color darkDividerColor = Color(0xFF1C2834); +const Color darkScaffoldColor = Color(0xFF0C141D); +const Color darkLinkButtonColor = Colors.white; +final Color darkErrorColor = Colors.red.shade500; +final Color darkWarningColor = Colors.yellow.shade500; +final Color darkInfoColor = Colors.blue.shade500; +final Color darkIssueColor = Colors.grey.shade700; + +const Color runButtonColor = Color(0xFF168afd); const Color subtleColor = Colors.grey; diff --git a/pkgs/dartpad_ui/lib/utils.dart b/pkgs/dartpad_ui/lib/utils.dart index c35cc3edb..2243d6be6 100644 --- a/pkgs/dartpad_ui/lib/utils.dart +++ b/pkgs/dartpad_ui/lib/utils.dart @@ -89,7 +89,7 @@ class StatusController { }); // Finally, start the 'closing' animation. - Timer(duration, () => message.close()); + Timer(duration, message.close); } Message showMessage({required String initialText, String? name}) { diff --git a/pkgs/dartpad_ui/lib/widgets.dart b/pkgs/dartpad_ui/lib/widgets.dart index 84d060310..2b86324eb 100644 --- a/pkgs/dartpad_ui/lib/widgets.dart +++ b/pkgs/dartpad_ui/lib/widgets.dart @@ -67,8 +67,9 @@ class MiniIconButton extends StatelessWidget { @override Widget build(BuildContext context) { - final brightness = Theme.of(context).brightness; - final colorScheme = Theme.of(context).colorScheme; + final theme = Theme.of(context); + final brightness = theme.brightness; + final colorScheme = theme.colorScheme; final backgroundColor = switch (brightness) { Brightness.light => colorScheme.surface.darker, Brightness.dark => colorScheme.surface.lighter, @@ -79,8 +80,8 @@ class MiniIconButton extends StatelessWidget { waitDuration: tooltipDelay, child: IconButton( style: ButtonStyle( - shape: WidgetStateProperty.all(const CircleBorder()), - backgroundColor: WidgetStateProperty.all(backgroundColor), + shape: const WidgetStatePropertyAll(CircleBorder()), + backgroundColor: WidgetStatePropertyAll(backgroundColor), ), icon: Icon(icon), iconSize: small ? 16 : smallIconSize, @@ -104,8 +105,8 @@ class RunButton extends StatelessWidget { waitDuration: tooltipDelay, child: TextButton( style: ButtonStyle( - shape: WidgetStateProperty.all( - RoundedRectangleBorder(borderRadius: BorderRadius.circular(4.0))), + shape: const WidgetStatePropertyAll(RoundedRectangleBorder( + borderRadius: BorderRadius.all(Radius.circular(4)))), backgroundColor: WidgetStateProperty.resolveWith( (states) { if (states.contains(WidgetState.disabled)) { @@ -148,8 +149,9 @@ class StatusWidget extends StatelessWidget { @override Widget build(BuildContext context) { - final brightness = Theme.of(context).brightness; - final colorScheme = Theme.of(context).colorScheme; + final theme = Theme.of(context); + final brightness = theme.brightness; + final colorScheme = theme.colorScheme; final backgroundColor = switch (brightness) { Brightness.light => colorScheme.surface.darker, Brightness.dark => colorScheme.surface.lighter, @@ -201,12 +203,13 @@ class MediumDialog extends StatelessWidget { return LayoutBuilder(builder: (context, constraints) { final width = smaller ? 400.0 : 500.0; final height = smaller ? 325.0 : 400.0; + final theme = Theme.of(context); return PointerInterceptor( child: AlertDialog( - backgroundColor: Theme.of(context).scaffoldBackgroundColor, + backgroundColor: theme.scaffoldBackgroundColor, title: Text(title, maxLines: 1), - contentTextStyle: Theme.of(context).textTheme.bodyMedium, + contentTextStyle: theme.textTheme.bodyMedium, contentPadding: const EdgeInsets.fromLTRB(24, defaultSpacing, 24, 8), content: Column( mainAxisSize: MainAxisSize.min, @@ -241,7 +244,7 @@ class GoldenRatioCenter extends StatelessWidget { @override Widget build(BuildContext context) { - return Container( + return Align( alignment: const Alignment(0.0, -(1.618 / 4)), child: child, ); diff --git a/pkgs/dartpad_ui/test/gists_test.dart b/pkgs/dartpad_ui/test/gists_test.dart index c04bd725c..b63a9f4f1 100644 --- a/pkgs/dartpad_ui/test/gists_test.dart +++ b/pkgs/dartpad_ui/test/gists_test.dart @@ -11,7 +11,7 @@ void main() { group('gists', () { test('parses json', () { final gist = - Gist.fromJson(jsonDecode(jsonSample) as Map); + Gist.fromJson(jsonDecode(jsonSample) as Map); expect(gist.id, 'd3bd83918d21b6d5f778bdc69c3d36d6'); expect(gist.description, 'Fibonacci'); @@ -21,28 +21,28 @@ void main() { test('finds main.dart', () { final gist = - Gist.fromJson(jsonDecode(jsonSample) as Map); + Gist.fromJson(jsonDecode(jsonSample) as Map); expect(gist.mainDartSource, isNotNull); }); test('recognizes main.dart missing', () { final gist = - Gist.fromJson(jsonDecode(jsonSampleNoMain) as Map); + Gist.fromJson(jsonDecode(jsonSampleNoMain) as Map); expect(gist.mainDartSource, isNull); }); test('validates main.dart missing', () { final gist = - Gist.fromJson(jsonDecode(jsonSampleNoMain) as Map); + Gist.fromJson(jsonDecode(jsonSampleNoMain) as Map); expect(gist.validationIssues, isNotEmpty); }); test('validates unexpected dart content file', () { final gist = Gist.fromJson( - jsonDecode(jsonSampleAlternativeFile) as Map); + jsonDecode(jsonSampleAlternativeFile) as Map); expect(gist.validationIssues, isNotEmpty); });