Skip to content

Commit 0042da7

Browse files
authored
[xdg_directories] Add example app (#4554)
Created a demo app for the xdg_directories package to showcase some of the basic functionalities. <img width="1440" alt="Screenshot 2023-08-01 at 11 45 31 a m" src="https://github.com/flutter/packages/assets/36830415/95adbcde-f554-4fce-ace9-e385cb66db3c"> Fixes: [#128698](flutter/flutter#128698)
1 parent 7bfcc0e commit 0042da7

File tree

16 files changed

+540
-1
lines changed

16 files changed

+540
-1
lines changed

packages/xdg_directories/CHANGELOG.md

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,7 @@
1+
## 1.0.2
2+
3+
* Adds example app to demonstrate how to use the package.
4+
15
## 1.0.1
26

37
* Removes `process` dependency.
Lines changed: 44 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,44 @@
1+
# Miscellaneous
2+
*.class
3+
*.log
4+
*.pyc
5+
*.swp
6+
.DS_Store
7+
.atom/
8+
.buildlog/
9+
.history
10+
.svn/
11+
migrate_working_dir/
12+
13+
# IntelliJ related
14+
*.iml
15+
*.ipr
16+
*.iws
17+
.idea/
18+
19+
# The .vscode folder contains launch configuration and tasks you configure in
20+
# VS Code which you may wish to be included in version control, so this line
21+
# is commented out by default.
22+
#.vscode/
23+
24+
# Flutter/Dart/Pub related
25+
**/doc/api/
26+
**/ios/Flutter/.last_build_id
27+
.dart_tool/
28+
.flutter-plugins
29+
.flutter-plugins-dependencies
30+
.packages
31+
.pub-cache/
32+
.pub/
33+
/build/
34+
35+
# Symbolication related
36+
app.*.symbols
37+
38+
# Obfuscation related
39+
app.*.map.json
40+
41+
# Android Studio will place build artifacts here
42+
/android/app/debug
43+
/android/app/profile
44+
/android/app/release
Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
buildFlags:
2+
_pluginToolsConfigGlobalKey:
3+
- "--no-tree-shake-icons"
4+
- "--dart-define=buildmode=testing"
Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
# XDG Directories Demo
2+
3+
## Description
4+
5+
This is a simple demo of the xdg_directories package.
Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,37 @@
1+
// Copyright 2013 The Flutter Authors. All rights reserved.
2+
// Use of this source code is governed by a BSD-style license that can be
3+
// found in the LICENSE file.
4+
5+
import 'dart:io';
6+
import 'package:flutter_test/flutter_test.dart';
7+
import 'package:integration_test/integration_test.dart';
8+
import 'package:xdg_directories/xdg_directories.dart';
9+
import 'package:xdg_directories_example/main.dart';
10+
11+
void main() {
12+
IntegrationTestWidgetsFlutterBinding.ensureInitialized();
13+
14+
testWidgets('xdg_directories_demo', (WidgetTester _) async {
15+
// Build our app and trigger a frame.
16+
await _.pumpWidget(const MyApp());
17+
18+
expect(find.textContaining(dataHome.path), findsWidgets);
19+
expect(find.textContaining(configHome.path), findsWidgets);
20+
expect(
21+
find.textContaining(
22+
dataDirs.map((Directory directory) => directory.path).join('\n')),
23+
findsWidgets);
24+
expect(
25+
find.textContaining(
26+
configDirs.map((Directory directory) => directory.path).join('\n')),
27+
findsWidgets);
28+
29+
expect(
30+
find.textContaining(cacheHome.path, skipOffstage: false),
31+
findsWidgets,
32+
);
33+
34+
expect(find.textContaining(runtimeDir?.path ?? '', skipOffstage: false),
35+
findsWidgets);
36+
});
37+
}
Lines changed: 78 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,78 @@
1+
// Copyright 2013 The Flutter Authors. All rights reserved.
2+
// Use of this source code is governed by a BSD-style license that can be
3+
// found in the LICENSE file.
4+
5+
// ignore_for_file: public_member_api_docs
6+
7+
import 'dart:io';
8+
import 'package:flutter/material.dart';
9+
import 'package:xdg_directories/xdg_directories.dart';
10+
11+
void main() {
12+
runApp(const MyApp());
13+
}
14+
15+
class MyApp extends StatelessWidget {
16+
const MyApp({super.key});
17+
18+
@override
19+
Widget build(BuildContext context) {
20+
return const MaterialApp(
21+
title: 'XDG Directories Demo',
22+
home: MyHomePage(title: 'XDG Directories Demo'),
23+
color: Colors.blue,
24+
);
25+
}
26+
}
27+
28+
class MyHomePage extends StatefulWidget {
29+
const MyHomePage({super.key, required this.title});
30+
31+
final String title;
32+
33+
@override
34+
State<MyHomePage> createState() => _MyHomePageState();
35+
}
36+
37+
class _MyHomePageState extends State<MyHomePage> {
38+
final Set<String> userDirectoryNames = getUserDirectoryNames();
39+
String selectedUserDirectory = '';
40+
41+
@override
42+
Widget build(BuildContext context) {
43+
return Scaffold(
44+
appBar: AppBar(
45+
title: Text(widget.title),
46+
),
47+
body: Center(
48+
child: ListView(
49+
padding: const EdgeInsets.only(left: 20),
50+
shrinkWrap: true,
51+
children: <Widget>[
52+
const SizedBox(
53+
height: 20,
54+
),
55+
ListView.builder(
56+
shrinkWrap: true,
57+
itemCount: userDirectoryNames.length,
58+
itemBuilder: (BuildContext context, int index) => Text(
59+
'${userDirectoryNames.elementAt(index)}: \n${getUserDirectory(userDirectoryNames.elementAt(index))?.path}\n',
60+
),
61+
),
62+
Text('Data Home: \n${dataHome.path}\n'),
63+
Text('Config Home: \n${configHome.path}\n'),
64+
Text(
65+
'Data Directories: \n${dataDirs.map((Directory directory) => directory.path).toList().join('\n')}\n'),
66+
Text(
67+
'Config Directories: \n${configDirs.map((Directory directory) => directory.path).toList().join('\n')}\n'),
68+
Text('Cache Home: \n${cacheHome.path}\n'),
69+
Text('Runtime Directory: \n${runtimeDir?.path}\n'),
70+
const SizedBox(
71+
height: 100,
72+
),
73+
],
74+
),
75+
),
76+
);
77+
}
78+
}
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
flutter/ephemeral
Lines changed: 139 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,139 @@
1+
# Project-level configuration.
2+
cmake_minimum_required(VERSION 3.10)
3+
project(runner LANGUAGES CXX)
4+
5+
# The name of the executable created for the application. Change this to change
6+
# the on-disk name of your application.
7+
set(BINARY_NAME "xdg_directories_demo")
8+
# The unique GTK application identifier for this application. See:
9+
# https://wiki.gnome.org/HowDoI/ChooseApplicationID
10+
set(APPLICATION_ID "com.example.example")
11+
12+
# Explicitly opt in to modern CMake behaviors to avoid warnings with recent
13+
# versions of CMake.
14+
cmake_policy(SET CMP0063 NEW)
15+
16+
# Load bundled libraries from the lib/ directory relative to the binary.
17+
set(CMAKE_INSTALL_RPATH "$ORIGIN/lib")
18+
19+
# Root filesystem for cross-building.
20+
if(FLUTTER_TARGET_PLATFORM_SYSROOT)
21+
set(CMAKE_SYSROOT ${FLUTTER_TARGET_PLATFORM_SYSROOT})
22+
set(CMAKE_FIND_ROOT_PATH ${CMAKE_SYSROOT})
23+
set(CMAKE_FIND_ROOT_PATH_MODE_PROGRAM NEVER)
24+
set(CMAKE_FIND_ROOT_PATH_MODE_PACKAGE ONLY)
25+
set(CMAKE_FIND_ROOT_PATH_MODE_LIBRARY ONLY)
26+
set(CMAKE_FIND_ROOT_PATH_MODE_INCLUDE ONLY)
27+
endif()
28+
29+
# Define build configuration options.
30+
if(NOT CMAKE_BUILD_TYPE AND NOT CMAKE_CONFIGURATION_TYPES)
31+
set(CMAKE_BUILD_TYPE "Debug" CACHE
32+
STRING "Flutter build mode" FORCE)
33+
set_property(CACHE CMAKE_BUILD_TYPE PROPERTY STRINGS
34+
"Debug" "Profile" "Release")
35+
endif()
36+
37+
# Compilation settings that should be applied to most targets.
38+
#
39+
# Be cautious about adding new options here, as plugins use this function by
40+
# default. In most cases, you should add new options to specific targets instead
41+
# of modifying this function.
42+
function(APPLY_STANDARD_SETTINGS TARGET)
43+
target_compile_features(${TARGET} PUBLIC cxx_std_14)
44+
target_compile_options(${TARGET} PRIVATE -Wall -Werror)
45+
target_compile_options(${TARGET} PRIVATE "$<$<NOT:$<CONFIG:Debug>>:-O3>")
46+
target_compile_definitions(${TARGET} PRIVATE "$<$<NOT:$<CONFIG:Debug>>:NDEBUG>")
47+
endfunction()
48+
49+
# Flutter library and tool build rules.
50+
set(FLUTTER_MANAGED_DIR "${CMAKE_CURRENT_SOURCE_DIR}/flutter")
51+
add_subdirectory(${FLUTTER_MANAGED_DIR})
52+
53+
# System-level dependencies.
54+
find_package(PkgConfig REQUIRED)
55+
pkg_check_modules(GTK REQUIRED IMPORTED_TARGET gtk+-3.0)
56+
57+
add_definitions(-DAPPLICATION_ID="${APPLICATION_ID}")
58+
59+
# Define the application target. To change its name, change BINARY_NAME above,
60+
# not the value here, or `flutter run` will no longer work.
61+
#
62+
# Any new source files that you add to the application should be added here.
63+
add_executable(${BINARY_NAME}
64+
"main.cc"
65+
"my_application.cc"
66+
"${FLUTTER_MANAGED_DIR}/generated_plugin_registrant.cc"
67+
)
68+
69+
# Apply the standard set of build settings. This can be removed for applications
70+
# that need different build settings.
71+
apply_standard_settings(${BINARY_NAME})
72+
73+
# Add dependency libraries. Add any application-specific dependencies here.
74+
target_link_libraries(${BINARY_NAME} PRIVATE flutter)
75+
target_link_libraries(${BINARY_NAME} PRIVATE PkgConfig::GTK)
76+
77+
# Run the Flutter tool portions of the build. This must not be removed.
78+
add_dependencies(${BINARY_NAME} flutter_assemble)
79+
80+
# Only the install-generated bundle's copy of the executable will launch
81+
# correctly, since the resources must in the right relative locations. To avoid
82+
# people trying to run the unbundled copy, put it in a subdirectory instead of
83+
# the default top-level location.
84+
set_target_properties(${BINARY_NAME}
85+
PROPERTIES
86+
RUNTIME_OUTPUT_DIRECTORY "${CMAKE_BINARY_DIR}/intermediates_do_not_run"
87+
)
88+
89+
90+
# Generated plugin build rules, which manage building the plugins and adding
91+
# them to the application.
92+
include(flutter/generated_plugins.cmake)
93+
94+
95+
# === Installation ===
96+
# By default, "installing" just makes a relocatable bundle in the build
97+
# directory.
98+
set(BUILD_BUNDLE_DIR "${PROJECT_BINARY_DIR}/bundle")
99+
if(CMAKE_INSTALL_PREFIX_INITIALIZED_TO_DEFAULT)
100+
set(CMAKE_INSTALL_PREFIX "${BUILD_BUNDLE_DIR}" CACHE PATH "..." FORCE)
101+
endif()
102+
103+
# Start with a clean build bundle directory every time.
104+
install(CODE "
105+
file(REMOVE_RECURSE \"${BUILD_BUNDLE_DIR}/\")
106+
" COMPONENT Runtime)
107+
108+
set(INSTALL_BUNDLE_DATA_DIR "${CMAKE_INSTALL_PREFIX}/data")
109+
set(INSTALL_BUNDLE_LIB_DIR "${CMAKE_INSTALL_PREFIX}/lib")
110+
111+
install(TARGETS ${BINARY_NAME} RUNTIME DESTINATION "${CMAKE_INSTALL_PREFIX}"
112+
COMPONENT Runtime)
113+
114+
install(FILES "${FLUTTER_ICU_DATA_FILE}" DESTINATION "${INSTALL_BUNDLE_DATA_DIR}"
115+
COMPONENT Runtime)
116+
117+
install(FILES "${FLUTTER_LIBRARY}" DESTINATION "${INSTALL_BUNDLE_LIB_DIR}"
118+
COMPONENT Runtime)
119+
120+
foreach(bundled_library ${PLUGIN_BUNDLED_LIBRARIES})
121+
install(FILES "${bundled_library}"
122+
DESTINATION "${INSTALL_BUNDLE_LIB_DIR}"
123+
COMPONENT Runtime)
124+
endforeach(bundled_library)
125+
126+
# Fully re-copy the assets directory on each build to avoid having stale files
127+
# from a previous install.
128+
set(FLUTTER_ASSET_DIR_NAME "flutter_assets")
129+
install(CODE "
130+
file(REMOVE_RECURSE \"${INSTALL_BUNDLE_DATA_DIR}/${FLUTTER_ASSET_DIR_NAME}\")
131+
" COMPONENT Runtime)
132+
install(DIRECTORY "${PROJECT_BUILD_DIR}/${FLUTTER_ASSET_DIR_NAME}"
133+
DESTINATION "${INSTALL_BUNDLE_DATA_DIR}" COMPONENT Runtime)
134+
135+
# Install the AOT library on non-Debug builds only.
136+
if(NOT CMAKE_BUILD_TYPE MATCHES "Debug")
137+
install(FILES "${AOT_LIBRARY}" DESTINATION "${INSTALL_BUNDLE_LIB_DIR}"
138+
COMPONENT Runtime)
139+
endif()

0 commit comments

Comments
 (0)