Skip to content

Commit

Permalink
Remove the shared_preferences dependency from devtools_app (#8607)
Browse files Browse the repository at this point in the history
* Remove the `shared_preferences` dependency from `devtools_app`

* fix test and rename method
  • Loading branch information
kenzieschmoll authored Dec 6, 2024
1 parent 4b04f03 commit 6da26d2
Show file tree
Hide file tree
Showing 4 changed files with 14 additions and 17 deletions.
24 changes: 11 additions & 13 deletions packages/devtools_app/lib/src/framework/home_screen.dart
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,6 @@ import 'package:devtools_shared/devtools_shared.dart';
import 'package:flutter/foundation.dart';
import 'package:flutter/material.dart';
import 'package:provider/provider.dart';
import 'package:shared_preferences/shared_preferences.dart';

import '../service/connected_app/connection_info.dart';
import '../shared/analytics/analytics.dart' as ga;
Expand Down Expand Up @@ -159,28 +158,29 @@ class ConnectInput extends StatefulWidget {
class _ConnectInputState extends State<ConnectInput> with BlockingActionMixin {
late final TextEditingController connectDialogController;

SharedPreferences? _debugSharedPreferences;
static const _vmServiceUriKey = 'vmServiceUri';
/// The key for the VM Service URI we cache in storage for the purpose of
/// speeding up the DevTools development cycle.
static const _debugVmServiceUriKey = 'debug_vmServiceUri';

@override
void initState() {
super.initState();
connectDialogController = TextEditingController();
assert(() {
_debugInitSharedPreferences();
_debugInitVmServiceCache();
return true;
}());
}

void _debugInitSharedPreferences() async {
void _debugInitVmServiceCache() async {
// We only do this in debug mode as it speeds iteration for DevTools
// developers who tend to repeatedly restart DevTools to debug the same
// test application.
_debugSharedPreferences = await SharedPreferences.getInstance();
if (_debugSharedPreferences != null && mounted) {
final uri = _debugSharedPreferences!.getString(_vmServiceUriKey);
if (uri != null) {
final uri = await storage.getValue(_debugVmServiceUriKey);
if (uri != null) {
setState(() {
connectDialogController.text = uri;
}
});
}
}

Expand Down Expand Up @@ -262,9 +262,7 @@ class _ConnectInputState extends State<ConnectInput> with BlockingActionMixin {
}

assert(() {
if (_debugSharedPreferences != null) {
_debugSharedPreferences!.setString(_vmServiceUriKey, uri);
}
storage.setValue(_debugVmServiceUriKey, uri);
return true;
}());

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,11 +6,9 @@ import FlutterMacOS
import Foundation

import file_selector_macos
import shared_preferences_foundation
import url_launcher_macos

func RegisterGeneratedPlugins(registry: FlutterPluginRegistry) {
FileSelectorPlugin.register(with: registry.registrar(forPlugin: "FileSelectorPlugin"))
SharedPreferencesPlugin.register(with: registry.registrar(forPlugin: "SharedPreferencesPlugin"))
UrlLauncherPlugin.register(with: registry.registrar(forPlugin: "UrlLauncherPlugin"))
}
2 changes: 0 additions & 2 deletions packages/devtools_app/pubspec.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -44,8 +44,6 @@ dependencies:
path: ../../third_party/packages/perfetto_ui_compiled
pointer_interceptor: ^0.10.1+1
provider: ^6.0.2
# Only used for debug mode logic.
shared_preferences: ^2.0.15
source_map_stack_trace: ^2.1.2
source_maps: ^0.10.12
sse: ^4.1.2
Expand Down
3 changes: 3 additions & 0 deletions packages/devtools_app/test/framework/home_screen_test.dart
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,8 @@ import 'package:flutter/material.dart';
import 'package:flutter_test/flutter_test.dart';
import 'package:mockito/mockito.dart';

import '../test_infra/flutter_test_storage.dart';

void main() {
late FakeServiceConnectionManager fakeServiceConnection;

Expand All @@ -22,6 +24,7 @@ void main() {
fakeServiceConnection = FakeServiceConnectionManager(),
);
setGlobal(IdeTheme, IdeTheme());
setGlobal(Storage, FlutterTestStorage());
fakeServiceConnection.serviceManager.setConnectedState(false);
});

Expand Down

0 comments on commit 6da26d2

Please sign in to comment.