Skip to content

Commit

Permalink
Improve loading state and support for windows paths
Browse files Browse the repository at this point in the history
  • Loading branch information
dam5s committed Jun 21, 2024
1 parent ef8bed5 commit 0f91e92
Show file tree
Hide file tree
Showing 11 changed files with 78 additions and 37 deletions.
4 changes: 3 additions & 1 deletion disk_space_usage/lib/directory_navigation_bar.dart
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
import 'dart:io';

import 'package:flutter/material.dart';

import 'package:disk_space_usage/widgets/square_text_button.dart';
Expand Down Expand Up @@ -43,7 +45,7 @@ class _DirectoryNavigationBarState extends State<DirectoryNavigationBar> {
final navChildren = itemsInNav
.expand(
(navItem) => <Widget>[
const Text('/'),
Text(Platform.pathSeparator),
SquareTextButton(
padding: 20,
onPressed: () => widget.navigateToDiskItem(navItem),
Expand Down
6 changes: 5 additions & 1 deletion disk_space_usage/lib/directory_selector.dart
Original file line number Diff line number Diff line change
Expand Up @@ -4,16 +4,19 @@ import 'package:disk_space_usage/disk_item/disk_item.dart';
import 'package:disk_space_usage/disk_item/disk_item_navigation.dart';

final class SelectedDirectory {
final String path;
final Stream<String> loadingPaths;
final Future<ParentedDiskItem> diskItemFuture;

SelectedDirectory({required this.loadingPaths, required this.diskItemFuture});
SelectedDirectory({required this.path, required this.loadingPaths, required this.diskItemFuture});

SelectedDirectory copy({
String? path,
Stream<String>? loadingPaths,
Future<ParentedDiskItem>? diskItemFuture,
}) =>
SelectedDirectory(
path: path ?? this.path,
loadingPaths: loadingPaths ?? this.loadingPaths,
diskItemFuture: diskItemFuture ?? this.diskItemFuture,
);
Expand All @@ -34,6 +37,7 @@ final class SystemDirectorySelector implements DirectorySelector {
final (loadingStream, diskItemFuture) = loadDirectory(directoryPath);

return SelectedDirectory(
path: directoryPath,
loadingPaths: loadingStream,
diskItemFuture: diskItemFuture.then((diskItem) => ParentedDiskItem(diskItem)),
);
Expand Down
2 changes: 1 addition & 1 deletion disk_space_usage/lib/disk_item/disk_item.dart
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ Future<DiskItem> _loadFileSystemEntity(
) async {
final parentPath = entity.parent.absolute.path;
final entityPath = entity.absolute.path;
final name = entityPath.replaceFirst('$parentPath/', '');
final name = entityPath.replaceFirst('$parentPath${Platform.pathSeparator}', '');

onProgress(entityPath);

Expand Down
4 changes: 2 additions & 2 deletions disk_space_usage/lib/disk_item/disk_item_colors.dart
Original file line number Diff line number Diff line change
Expand Up @@ -10,9 +10,9 @@ class DiskItemColors {
_currentIndex++;

return switch (_currentIndex % 7) {
0 => colorScheme.background,
0 => colorScheme.surface,
1 => colorScheme.surface,
2 => colorScheme.surfaceVariant,
2 => colorScheme.surfaceContainerHighest,
3 => colorScheme.surfaceTint,
4 => colorScheme.secondaryContainer,
5 => colorScheme.tertiaryContainer,
Expand Down
4 changes: 2 additions & 2 deletions disk_space_usage/lib/disk_item/disk_item_widget.dart
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ class _DiskItemBranchWidget extends StatelessWidget {

final BoxConstraints(:maxWidth, :maxHeight) = constraints;

if (maxWidth < 50 || maxHeight < 50) {
if (maxWidth < 50 || maxHeight < 60) {
return _BlankDiskItem(colors: colors);
}

Expand Down Expand Up @@ -212,7 +212,7 @@ class DiskItemWidget extends StatelessWidget {
),
Expanded(
child: ColoredBox(
color: colorScheme.background.withOpacity(0.25),
color: colorScheme.surface.withOpacity(0.25),
child: _DiskItemDetailsWidget(
parentedDiskItem: parentedDiskItem,
colors: colors,
Expand Down
10 changes: 5 additions & 5 deletions disk_space_usage/lib/disk_space_usage_page.dart
Original file line number Diff line number Diff line change
Expand Up @@ -72,18 +72,18 @@ class _DiskSpaceUsagePageState extends State<DiskSpaceUsagePage> {
future: selectedDirectory.diskItemFuture,
builder: (context, snapshot) {
final data = snapshot.data;
return data == null
? _loadingWidget(selectedDirectory.loadingPaths)
: _loadedWidget(context, data);
return data == null ? _loadingWidget(selectedDirectory) : _loadedWidget(context, data);
},
);

Widget _loadingWidget(Stream<String> loadingStream) => Center(
Widget _loadingWidget(SelectedDirectory selectedDirectory) => Center(
child: Column(
mainAxisAlignment: MainAxisAlignment.center,
children: [
Text(selectedDirectory.path, maxLines: 1, overflow: TextOverflow.ellipsis),
const SizedBox(height: 64),
StreamBuilder<String>(
stream: loadingStream,
stream: selectedDirectory.loadingPaths,
builder: (context, snapshot) {
final path = snapshot.data ?? '';
return Text(path, maxLines: 1, overflow: TextOverflow.ellipsis);
Expand Down
4 changes: 2 additions & 2 deletions disk_space_usage/lib/widgets/square_text_button.dart
Original file line number Diff line number Diff line change
Expand Up @@ -15,8 +15,8 @@ class SquareTextButton extends StatelessWidget {
@override
Widget build(BuildContext context) => TextButton(
style: ButtonStyle(
shape: MaterialStateProperty.all(const LinearBorder()),
padding: MaterialStateProperty.all(EdgeInsets.all(padding)),
shape: WidgetStateProperty.all(const LinearBorder()),
padding: WidgetStateProperty.all(EdgeInsets.all(padding)),
),
onPressed: onPressed,
child: child,
Expand Down
68 changes: 46 additions & 22 deletions disk_space_usage/pubspec.lock
Original file line number Diff line number Diff line change
Expand Up @@ -77,10 +77,10 @@ packages:
dependency: transitive
description:
name: collection
sha256: f092b211a4319e98e5ff58223576de6c2803db36221657b46c82574721240687
sha256: ee67cb0715911d28db6bf4af1026078bd6f0128b07a5f66fb2ed94ec6783c09a
url: "https://pub.dev"
source: hosted
version: "1.17.2"
version: "1.18.0"
cross_file:
dependency: transitive
description:
Expand Down Expand Up @@ -257,6 +257,30 @@ packages:
url: "https://pub.dev"
source: hosted
version: "0.6.7"
leak_tracker:
dependency: transitive
description:
name: leak_tracker
sha256: "7f0df31977cb2c0b88585095d168e689669a2cc9b97c309665e3386f3e9d341a"
url: "https://pub.dev"
source: hosted
version: "10.0.4"
leak_tracker_flutter_testing:
dependency: transitive
description:
name: leak_tracker_flutter_testing
sha256: "06e98f569d004c1315b991ded39924b21af84cf14cc94791b8aea337d25b57f8"
url: "https://pub.dev"
source: hosted
version: "3.0.3"
leak_tracker_testing:
dependency: transitive
description:
name: leak_tracker_testing
sha256: "6ba465d5d76e67ddf503e1161d1f4a6bc42306f9d66ca1e8f079a47290fb06d3"
url: "https://pub.dev"
source: hosted
version: "3.0.1"
lints:
dependency: transitive
description:
Expand All @@ -277,26 +301,26 @@ packages:
dependency: transitive
description:
name: matcher
sha256: "1803e76e6653768d64ed8ff2e1e67bea3ad4b923eb5c56a295c3e634bad5960e"
sha256: d2323aa2060500f906aa31a895b4030b6da3ebdcc5619d14ce1aada65cd161cb
url: "https://pub.dev"
source: hosted
version: "0.12.16"
version: "0.12.16+1"
material_color_utilities:
dependency: transitive
description:
name: material_color_utilities
sha256: "9528f2f296073ff54cb9fee677df673ace1218163c3bc7628093e7eed5203d41"
sha256: "0e0a020085b65b6083975e499759762399b4475f766c21668c4ecca34ea74e5a"
url: "https://pub.dev"
source: hosted
version: "0.5.0"
version: "0.8.0"
meta:
dependency: transitive
description:
name: meta
sha256: "3c74dbf8763d36539f114c799d8a2d87343b5067e9d796ca22b5eb8437090ee3"
sha256: "7687075e408b093f36e6bbf6c91878cc0d4cd10f409506f7bc996f68220b9136"
url: "https://pub.dev"
source: hosted
version: "1.9.1"
version: "1.12.0"
nested:
dependency: transitive
description:
Expand All @@ -309,10 +333,10 @@ packages:
dependency: transitive
description:
name: path
sha256: "8829d8a55c13fc0e37127c29fedf290c102f4e40ae94ada574091fe0ff96c917"
sha256: "087ce49c3f0dc39180befefc60fdb4acd8f8620e5682fe2476afd0b3688bb4af"
url: "https://pub.dev"
source: hosted
version: "1.8.3"
version: "1.9.0"
plugin_platform_interface:
dependency: transitive
description:
Expand Down Expand Up @@ -346,18 +370,18 @@ packages:
dependency: transitive
description:
name: stack_trace
sha256: c3c7d8edb15bee7f0f74debd4b9c5f3c2ea86766fe4178eb2a18eb30a0bdaed5
sha256: "73713990125a6d93122541237550ee3352a2d84baad52d375a4cad2eb9b7ce0b"
url: "https://pub.dev"
source: hosted
version: "1.11.0"
version: "1.11.1"
stream_channel:
dependency: transitive
description:
name: stream_channel
sha256: "83615bee9045c1d322bbbd1ba209b7a749c2cbcdcb3fdd1df8eb488b3279c1c8"
sha256: ba2aa5d8cc609d96bbb2899c28934f9e1af5cddbd60a827822ea467161eb54e7
url: "https://pub.dev"
source: hosted
version: "2.1.1"
version: "2.1.2"
string_scanner:
dependency: transitive
description:
Expand All @@ -378,10 +402,10 @@ packages:
dependency: transitive
description:
name: test_api
sha256: "75760ffd7786fffdfb9597c35c5b27eaeec82be8edfb6d71d32651128ed7aab8"
sha256: "9955ae474176f7ac8ee4e989dadfb411a58c30415bcfb648fa04b2b8a03afa7f"
url: "https://pub.dev"
source: hosted
version: "0.6.0"
version: "0.7.0"
typed_data:
dependency: transitive
description:
Expand All @@ -398,14 +422,14 @@ packages:
url: "https://pub.dev"
source: hosted
version: "2.1.4"
web:
vm_service:
dependency: transitive
description:
name: web
sha256: dc8ccd225a2005c1be616fe02951e2e342092edf968cf0844220383757ef8f10
name: vm_service
sha256: "3923c89304b715fb1eb6423f017651664a03bf5f4b29983627c4da791f74a4ec"
url: "https://pub.dev"
source: hosted
version: "0.1.4-beta"
version: "14.2.1"
win32:
dependency: transitive
description:
Expand All @@ -415,5 +439,5 @@ packages:
source: hosted
version: "3.1.4"
sdks:
dart: ">=3.1.0-185.0.dev <4.0.0"
flutter: ">=3.3.0"
dart: ">=3.3.0 <4.0.0"
flutter: ">=3.18.0-18.0.pre.54"
1 change: 1 addition & 0 deletions disk_space_usage/test/disk_space_usage_page_test.dart
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ import 'test_support/test_directory_selector.dart';
void main() {
testWidgets('Loading some disk items', (WidgetTester tester) async {
final selected = SelectedDirectory(
path: 'C:\\Users\\damo',
loadingPaths: Stream.value('some/path'),
diskItemFuture: Future.value(ParentedDiskItem(
DiskItem(
Expand Down
7 changes: 6 additions & 1 deletion disk_space_usage/windows/flutter/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,11 @@ include(${EPHEMERAL_DIR}/generated_config.cmake)
# https://github.com/flutter/flutter/issues/57146.
set(WRAPPER_ROOT "${EPHEMERAL_DIR}/cpp_client_wrapper")

# Set fallback configurations for older versions of the flutter tool.
if (NOT DEFINED FLUTTER_TARGET_PLATFORM)
set(FLUTTER_TARGET_PLATFORM "windows-x64")
endif()

# === Flutter Library ===
set(FLUTTER_LIBRARY "${EPHEMERAL_DIR}/flutter_windows.dll")

Expand Down Expand Up @@ -92,7 +97,7 @@ add_custom_command(
COMMAND ${CMAKE_COMMAND} -E env
${FLUTTER_TOOL_ENVIRONMENT}
"${FLUTTER_ROOT}/packages/flutter_tools/bin/tool_backend.bat"
windows-x64 $<CONFIG>
${FLUTTER_TARGET_PLATFORM} $<CONFIG>
VERBATIM
)
add_custom_target(flutter_assemble DEPENDS
Expand Down
5 changes: 5 additions & 0 deletions disk_space_usage/windows/runner/flutter_window.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,11 @@ bool FlutterWindow::OnCreate() {
this->Show();
});

// Flutter can complete the first frame before the "show window" callback is
// registered. The following call ensures a frame is pending to ensure the
// window is shown. It is a no-op if the first frame hasn't completed yet.
flutter_controller_->ForceRedraw();

return true;
}

Expand Down

0 comments on commit 0f91e92

Please sign in to comment.