-
Notifications
You must be signed in to change notification settings - Fork 361
More fixes from enabling all of code metrics #4931
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
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -112,21 +112,21 @@ class DevToolsAppState extends State<DevToolsApp> with AutoDisposeMixin { | |
| }); | ||
|
|
||
| _isDarkThemeEnabled = preferences.darkModeTheme.value; | ||
| preferences.darkModeTheme.addListener(() { | ||
| addAutoDisposeListener(preferences.darkModeTheme, () { | ||
| setState(() { | ||
| _isDarkThemeEnabled = preferences.darkModeTheme.value; | ||
| }); | ||
| }); | ||
|
|
||
| _vmDeveloperModeEnabled = preferences.vmDeveloperModeEnabled.value; | ||
| preferences.vmDeveloperModeEnabled.addListener(() { | ||
| addAutoDisposeListener(preferences.vmDeveloperModeEnabled, () { | ||
| setState(() { | ||
| _vmDeveloperModeEnabled = preferences.vmDeveloperModeEnabled.value; | ||
| }); | ||
| }); | ||
|
|
||
| _denseModeEnabled = preferences.denseModeEnabled.value; | ||
| preferences.denseModeEnabled.addListener(() { | ||
| addAutoDisposeListener(preferences.denseModeEnabled, () { | ||
| setState(() { | ||
| _denseModeEnabled = preferences.denseModeEnabled.value; | ||
| }); | ||
|
|
@@ -191,10 +191,10 @@ class DevToolsAppState extends State<DevToolsApp> with AutoDisposeMixin { | |
| } | ||
|
|
||
| Widget _buildTabbedPage( | ||
| BuildContext context, | ||
| BuildContext _, | ||
|
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. the lint about unused parameters was great although I wish it was a bit smarter about methods that were torn off in the same file.
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Could you give more details, how smarter you want it to be?
Looks like a bug to me, since the rule should ignore any amount of
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. _buildTabbedPage is private and the only use is within this file is where it torn off. Glad to hear any number of
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Do I understand correctly: you mean that for private methods used as tear off the rule should not check for unused parameters?
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. correct as the unused parameters were only there to match the signature required to use it as a tearoff. Its similar to why you shouldn't complain about unused parameters for an @OverRide
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Thank you! Added to backlog, will ship in the next release |
||
| String? page, | ||
| Map<String, String?> params, | ||
| DevToolsNavigationState? state, | ||
| DevToolsNavigationState? __, | ||
| ) { | ||
| final vmServiceUri = params['uri']; | ||
|
|
||
|
|
@@ -234,7 +234,8 @@ class DevToolsAppState extends State<DevToolsApp> with AutoDisposeMixin { | |
| .where((p) => !hide.contains(p.screenId)) | ||
| .toList(); | ||
| if (screens.isEmpty) return child ?? const SizedBox.shrink(); | ||
| return _providedControllers( | ||
| return MultiProvider( | ||
| providers: _providedControllers(), | ||
| child: DevToolsScaffold( | ||
| embed: embed, | ||
| ideTheme: ideTheme, | ||
|
|
@@ -277,8 +278,8 @@ class DevToolsAppState extends State<DevToolsApp> with AutoDisposeMixin { | |
| return DevToolsScaffold.withChild( | ||
| key: UniqueKey(), | ||
| ideTheme: ideTheme, | ||
| child: _providedControllers( | ||
| offline: true, | ||
| child: MultiProvider( | ||
|
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. @kenzieschmoll not sure if this is clearer.
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. The only downside of pulling the MultiProvider out of the helper is that this creates some duplicated code where we have to manually specify MultiProvider wherever _providedControllers is used, but I do see how _providedControllers already sounds like it should return a List as is. Why did
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. The lint is one to guide you towards creating widgets rather than creating functions that return widgets. It catches a lot of ugly code (particularly cases where the BuildContext was passed around) as well as some false positives like this.
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I wonder if the duplicate code is a little more idiomatic in that it is clear what we are doing is injecting providers.
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. @incendial this was the case where I couldn't keep the code idiomatic and avoid the lint about functions returning widgets. Seems odd the lint ever fires for functions returning Lists of widgets. Notice that the lint still fires with my fix here as it is upset about the method called that returns a List of all providers for the class.
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I see, never seen this case before, tbh 😅. If I change the rule to ignore Providers, will this be enough? The more I look at this case, the more I don't understand how a possible "right way" without a method could look like.
Very common case is when people create a private method returning List and then spread it in the widget's Column or Row.
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. So far the only case that is really blocking me is the provider case. The Column and Row cases are interesting. I do buy that those cases are probably usually bugs.
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Thank you! Added to backlog, will ship in the next release |
||
| providers: _providedControllers(offline: true), | ||
| child: SnapshotScreenBody(snapshotArgs, _screens), | ||
| ), | ||
| ); | ||
|
|
@@ -292,7 +293,8 @@ class DevToolsAppState extends State<DevToolsApp> with AutoDisposeMixin { | |
| ReportFeedbackButton(), | ||
| OpenAboutAction(), | ||
| ], | ||
| child: _providedControllers( | ||
| child: MultiProvider( | ||
| providers: _providedControllers(), | ||
| child: const AppSizeBody(), | ||
| ), | ||
| ); | ||
|
|
@@ -308,18 +310,13 @@ class DevToolsAppState extends State<DevToolsApp> with AutoDisposeMixin { | |
|
|
||
| List<Screen> _visibleScreens() => _screens.where(shouldShowScreen).toList(); | ||
|
|
||
| Widget _providedControllers({required Widget child, bool offline = false}) { | ||
| final _providers = widget.screens | ||
| List<Provider> _providedControllers({bool offline = false}) { | ||
| return widget.screens | ||
| .where( | ||
| (s) => s.providesController && (offline ? s.supportsOffline : true), | ||
| ) | ||
| .map((s) => s.controllerProvider(routerDelegate)) | ||
| .toList(); | ||
|
|
||
| return MultiProvider( | ||
| providers: _providers, | ||
| child: child, | ||
| ); | ||
| } | ||
|
|
||
| @override | ||
|
|
@@ -456,7 +453,7 @@ class OpenSettingsAction extends StatelessWidget { | |
| return DevToolsTooltip( | ||
| message: 'Settings', | ||
| child: InkWell( | ||
| onTap: () async { | ||
| onTap: () { | ||
|
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. here and elsewhere the lints caught a ton of cases where we were pretending we were doing useful async things when we weren't. Fyi @pq
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. @kenzieschmoll let me know if these cases where we are doing async stuff in tap handlers is useful or noise.
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
This rule initially was created for models mapping, when you can have like 2 String fields and then accidentally pass same value to both fields. Maybe it should be restricted somehow to not trigger on widgets, but I'm not sure.
Thank you, answered above.
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Maybe it should only apply to certain types of parameters. Seems most relevant for string fields where there is more of a sign of duplicate logic than for num fields or arbitrary class fields.
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Good point, I'll take some time to think |
||
| unawaited( | ||
| showDialog( | ||
| context: context, | ||
|
|
@@ -505,7 +502,8 @@ class SettingsDialog extends StatelessWidget { | |
| CheckboxSetting( | ||
| label: const Text('Enable analytics'), | ||
| listenable: analyticsController.analyticsEnabled, | ||
| toggle: analyticsController.toggleAnalyticsEnabled, | ||
| toggle: (enable) => | ||
| unawaited(analyticsController.toggleAnalyticsEnabled(enable)), | ||
| gaItem: gac.analytics, | ||
| ), | ||
| CheckboxSetting( | ||
|
|
@@ -537,7 +535,7 @@ class CheckboxSetting extends StatelessWidget { | |
|
|
||
| final ValueListenable<bool> listenable; | ||
|
|
||
| final Function(bool) toggle; | ||
| final void Function(bool) toggle; | ||
|
|
||
| final String gaItem; | ||
|
|
||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -19,8 +19,9 @@ import '../shared/primitives/utils.dart'; | |
| import '../shared/scripts/script_manager.dart'; | ||
| import '../shared/survey.dart'; | ||
|
|
||
| typedef ErrorReporter = void Function(String title, dynamic error); | ||
| typedef ErrorReporter = void Function(String title, Object error); | ||
|
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. lints were good at catching a ton of uses of dynamic that were left in our code. |
||
|
|
||
| // TODO(jacobr): refactor this class to not use static members. | ||
| // ignore: avoid_classes_with_only_static_members | ||
| class FrameworkCore { | ||
| static void initGlobals() { | ||
|
|
||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Fyi @polina-c this caught some cases where were adding listeners but never removing.