Skip to content

Commit b9fa43c

Browse files
committed
Render the "Import File" button.
1 parent 0dff44e commit b9fa43c

File tree

3 files changed

+98
-30
lines changed

3 files changed

+98
-30
lines changed

packages/devtools_app/lib/src/app_size/file_import_container.dart

Lines changed: 31 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,10 @@
22
// Use of this source code is governed by a BSD-style license that can be
33
// found in the LICENSE file.
44

5+
import 'dart:convert';
56
import 'package:flutter/material.dart';
7+
import 'package:flutter/foundation.dart';
8+
import 'package:file_selector/file_selector.dart';
69

710
import '../common_widgets.dart';
811
import '../config_specific/drag_and_drop/drag_and_drop.dart';
@@ -118,8 +121,7 @@ class _FileImportContainerState extends State<FileImportContainer> {
118121
child: _buildImportedFileDisplay(),
119122
),
120123
),
121-
// TODO(kenz): uncomment once file picker support is added
122-
// _buildImportButton(),
124+
if (_shouldShowImportButton) _buildImportButton(),
123125
// Horizontal spacer with flex value of 1.
124126
const Flexible(
125127
child: SizedBox(height: rowHeight),
@@ -138,18 +140,33 @@ class _FileImportContainerState extends State<FileImportContainer> {
138140
);
139141
}
140142

141-
// TODO(kenz): uncomment once file picker support is added
142-
// Widget _buildImportButton() {
143-
// return Row(
144-
// mainAxisAlignment: MainAxisAlignment.center,
145-
// children: [
146-
// OutlinedButton(
147-
// onPressed: () {},
148-
// child: const MaterialIconLabel(Icons.file_upload, 'Import File'),
149-
// ),
150-
// ],
151-
// );
152-
// }
143+
Widget _buildImportButton() {
144+
return Row(
145+
mainAxisAlignment: MainAxisAlignment.center,
146+
children: [
147+
OutlinedButton(
148+
onPressed: () async {
149+
final acceptedTypeGroups = [
150+
XTypeGroup(extensions: ['.json']),
151+
];
152+
final file = await openFile(acceptedTypeGroups: acceptedTypeGroups);
153+
final json = jsonDecode(await file.readAsString());
154+
final devToolsJsonFile = DevToolsJsonFile(
155+
name: file.name,
156+
lastModifiedTime: await file.lastModified(),
157+
data: json,
158+
);
159+
_handleImportedFile(devToolsJsonFile);
160+
},
161+
child: const MaterialIconLabel(Icons.file_upload, 'Import File'),
162+
),
163+
],
164+
);
165+
}
166+
167+
// Only show the import button in web and macOS
168+
bool get _shouldShowImportButton =>
169+
kIsWeb || defaultTargetPlatform == TargetPlatform.macOS;
153170

154171
Widget _buildActionButton() {
155172
return Column(

packages/devtools_app/pubspec.lock

Lines changed: 49 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -176,6 +176,13 @@ packages:
176176
url: "https://pub.dartlang.org"
177177
source: hosted
178178
version: "0.14.2"
179+
cross_file:
180+
dependency: transitive
181+
description:
182+
name: cross_file
183+
url: "https://pub.dartlang.org"
184+
source: hosted
185+
version: "0.1.0"
179186
crypto:
180187
dependency: transitive
181188
description:
@@ -232,6 +239,41 @@ packages:
232239
url: "https://pub.dartlang.org"
233240
source: hosted
234241
version: "5.2.1"
242+
file_selector:
243+
dependency: "direct main"
244+
description:
245+
name: file_selector
246+
url: "https://pub.dartlang.org"
247+
source: hosted
248+
version: "0.7.0+2"
249+
file_selector_linux:
250+
dependency: "direct main"
251+
description:
252+
name: file_selector_linux
253+
url: "https://pub.dartlang.org"
254+
source: hosted
255+
version: "0.0.1"
256+
file_selector_macos:
257+
dependency: "direct main"
258+
description:
259+
name: file_selector_macos
260+
url: "https://pub.dartlang.org"
261+
source: hosted
262+
version: "0.0.1"
263+
file_selector_platform_interface:
264+
dependency: transitive
265+
description:
266+
name: file_selector_platform_interface
267+
url: "https://pub.dartlang.org"
268+
source: hosted
269+
version: "1.0.2"
270+
file_selector_web:
271+
dependency: "direct main"
272+
description:
273+
name: file_selector_web
274+
url: "https://pub.dartlang.org"
275+
source: hosted
276+
version: "0.7.0+1"
235277
fixnum:
236278
dependency: transitive
237279
description:
@@ -408,6 +450,13 @@ packages:
408450
url: "https://pub.dartlang.org"
409451
source: hosted
410452
version: "1.10.0-nullsafety.3"
453+
platform_detect:
454+
dependency: transitive
455+
description:
456+
name: platform_detect
457+
url: "https://pub.dartlang.org"
458+
source: hosted
459+
version: "1.4.0"
411460
plugin_platform_interface:
412461
dependency: transitive
413462
description:

packages/devtools_app/pubspec.yaml

Lines changed: 18 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -11,23 +11,26 @@ version: 0.9.6
1111
homepage: https://github.com/flutter/devtools
1212

1313
environment:
14-
sdk: '>=2.10.0 <3.0.0'
14+
sdk: ">=2.10.0 <3.0.0"
1515
# The flutter desktop support interacts with build scripts on the Flutter
1616
# side that are not yet stable, so it requires a very recent version of
1717
# Flutter. This version will increase regularly as the build scripts change.
18-
flutter: '>=1.10.0'
18+
flutter: ">=1.10.0"
1919

2020
dependencies:
21-
ansi_up:
22-
^0.0.2
21+
ansi_up: ^0.0.2
2322
# path: ../../third_party/packages/ansi_up
2423
# Pin ansicolor to version before pre-NNBD version 1.1.0, should be ^1.0.5
25-
# See https://github.com/flutter/devtools/issues/2530
24+
# See https://github.com/flutter/devtools/issues/2530
2625
ansicolor: 1.0.5
27-
async: ^2.0.0
26+
async: ^2.0.0
2827
collection: ^1.15.0-nnbd
2928
devtools_shared: 0.9.6
3029
file: ^5.1.0
30+
file_selector: ^0.7.0
31+
file_selector_macos: ^0.0.1
32+
file_selector_linux: ^0.0.1
33+
file_selector_web: ^0.7.0
3134
flutter:
3235
sdk: flutter
3336
flutter_web_plugins:
@@ -59,8 +62,7 @@ dev_dependencies:
5962
# (temporary home for canonical lints)
6063
simple_lint_rules: ^1.0.0
6164
test: any # This version is pinned by Flutter so we don't need to set one explicitly.
62-
webkit_inspection_protocol: '>=0.5.0 <0.8.0'
63-
65+
webkit_inspection_protocol: ">=0.5.0 <0.8.0"
6466

6567
flutter:
6668
uses-material-design: true
@@ -113,12 +115,12 @@ flutter:
113115
- asset: fonts/Octicons.ttf
114116

115117
dependency_overrides:
116-
# The "#OVERRIDE_FOR_DEVELOPMENT" lines are stripped out when we publish.
117-
# All overriden dependencies are published together so there is no harm
118-
# in treating them like they are part of a mono-repo while developing.
118+
# The "#OVERRIDE_FOR_DEVELOPMENT" lines are stripped out when we publish.
119+
# All overriden dependencies are published together so there is no harm
120+
# in treating them like they are part of a mono-repo while developing.
119121
devtools_server: #OVERRIDE_FOR_DEVELOPMENT
120-
path: ../devtools_server #OVERRIDE_FOR_DEVELOPMENT
121-
devtools_shared: #OVERRIDE_FOR_DEVELOPMENT
122-
path: ../devtools_shared #OVERRIDE_FOR_DEVELOPMENT
123-
devtools_testing: #OVERRIDE_FOR_DEVELOPMENT
124-
path: ../devtools_testing #OVERRIDE_FOR_DEVELOPMENT
122+
path: ../devtools_server #OVERRIDE_FOR_DEVELOPMENT
123+
devtools_shared: #OVERRIDE_FOR_DEVELOPMENT
124+
path: ../devtools_shared #OVERRIDE_FOR_DEVELOPMENT
125+
devtools_testing: #OVERRIDE_FOR_DEVELOPMENT
126+
path: ../devtools_testing #OVERRIDE_FOR_DEVELOPMENT

0 commit comments

Comments
 (0)