Browse Source

[path_provider_aurora] Update example apps, add fun in PathProviderAurora

merge-requests/1/head
Vitaliy Zarubin 2 years ago
parent
commit
013c4a6a81
  1. 6
      packages/path_provider/path_provider_aurora/README.md
  2. 213
      packages/path_provider/path_provider_aurora/example/lib/main.dart
  3. 8
      packages/path_provider/path_provider_aurora/example/pubspec.lock
  4. 53
      packages/path_provider/path_provider_aurora/lib/path_provider_aurora.dart
  5. 16
      packages/path_provider/path_provider_aurora/pubspec.yaml
  6. 224
      packages/xdga_directories/example/lib/main.dart
  7. 3
      packages/xdga_directories/lib/xdga_directories.dart
  8. 10
      packages/xdga_directories/lib/xdga_directories_bindings_generated.dart
  9. 5
      packages/xdga_directories/src/xdga_directories.cpp
  10. 2
      packages/xdga_directories/src/xdga_directories.h

6
packages/path_provider/path_provider_aurora/README.md

@ -24,8 +24,8 @@ import 'package:path_provider/path_provider.dart';
- [x] `getTemporaryDirectory`
- [ ] `getApplicationSupportDirectory`
- [ ] `getLibraryDirectory`
- [ ] `getApplicationDocumentsDirectory`
- [x] `getApplicationDocumentsDirectory`
- [ ] `getExternalStorageDirectory`
- [ ] `getExternalCacheDirectories`
- [ ] `getExternalStorageDirectories`
- [ ] `getDownloadsDirectory`
- [x] `getExternalStorageDirectories` (There is no concept of External in Aurora OS, but this interface allows you to get the pictures/music/movies directory)
- [x] `getDownloadsDirectory`

213
packages/path_provider/path_provider_aurora/example/lib/main.dart

@ -16,57 +16,204 @@ class MyApp extends StatefulWidget {
}
class _MyAppState extends State<MyApp> {
Future<Directory?>? _tempDirectory;
String? _error;
String? _pathApplicationSupportDirectory;
String? _pathTempDirectory;
String? _pathApplicationDocumentsPath;
String? _pathDownloadsPath;
String? _pathPictures;
String? _pathMusic;
String? _pathMovies;
@override
void initState() {
super.initState();
// @todo it's work
// PathProviderAurora.registerWith();
PathProviderAurora.registerWith();
// Get directories from path_provider
loadPathDirectory();
}
void _requestTempDirectory() {
setState(() {
_tempDirectory = getTemporaryDirectory();
});
}
/// Asynchronous function receiving directory paths
Future<void> loadPathDirectory() async {
try {
// Get directories
Directory? applicationSupportDirectory = await getApplicationSupportDirectory();
Directory? tempDirectory = await getTemporaryDirectory();
Directory? pathApplicationDocumentsPath = await getApplicationDocumentsDirectory();
Directory? pathDownloadsPath = await getDownloadsDirectory();
List<Directory>? pathPictures = await getExternalStorageDirectories(type: StorageDirectory.pictures);
List<Directory>? pathMusic = await getExternalStorageDirectories(type: StorageDirectory.music);
List<Directory>? pathMovies = await getExternalStorageDirectories(type: StorageDirectory.movies);
Widget _buildDirectory(
BuildContext context, AsyncSnapshot<Directory?> snapshot) {
Text text = const Text('');
if (snapshot.connectionState == ConnectionState.done) {
if (snapshot.hasError) {
text = Text('Error: ${snapshot.error}');
} else if (snapshot.hasData) {
text = Text('path: ${snapshot.data!.path}');
} else {
text = const Text('path unavailable');
}
// Update state variable
setState(() {
_pathApplicationSupportDirectory = applicationSupportDirectory.path;
_pathTempDirectory = tempDirectory.path;
_pathApplicationDocumentsPath = pathApplicationDocumentsPath.path;
_pathDownloadsPath = pathDownloadsPath?.path;
_pathPictures = pathPictures?.first.path;
_pathMusic = pathMusic?.first.path;
_pathMovies = pathMovies?.first.path;
});
} on Exception catch (e) {
setState(() {
_error = e.toString();
});
}
return Padding(padding: const EdgeInsets.all(16.0), child: text);
}
@override
Widget build(BuildContext context) {
const textStyleWhite = TextStyle(fontSize: 18, color: Colors.white);
const textStyleTitle = TextStyle(fontSize: 20, color: Colors.black);
const textStylePath = TextStyle(fontSize: 18, color: Colors.black54);
const spaceMedium = SizedBox(height: 20);
const spaceSmall = SizedBox(height: 10);
return MaterialApp(
home: Scaffold(
appBar: AppBar(
title: const Text('Plugin example app'),
),
body: Column(
children: [
FutureBuilder<Directory?>(
future: _tempDirectory,
builder: _buildDirectory,
appBar: AppBar(
title: const Text('Example path_provider'),
),
body: Stack(
children: [
// Error message
Visibility(
visible: _error != null,
child: Center(
child: Padding(
padding: const EdgeInsets.all(16),
child: Container(
padding: const EdgeInsets.all(20),
decoration: const BoxDecoration(
color: Colors.redAccent,
borderRadius: BorderRadius.all(Radius.circular(10.0)),
),
child: Text(
_error ?? '',
style: textStyleWhite,
),
),
),
),
ElevatedButton(
onPressed: _requestTempDirectory,
child: const Text(
'Get Temporary Directory',
),
// List directories path
Visibility(
visible: _error == null,
child: SingleChildScrollView(
child: Padding(
padding: const EdgeInsets.all(16),
child: Center(
child: Column(
children: [
// Info
Container(
padding: const EdgeInsets.all(20),
decoration: const BoxDecoration(
color: Colors.green,
borderRadius: BorderRadius.all(Radius.circular(10.0)),
),
child: const Text(
'Demo application demonstration implementation of path_provider',
style: textStyleWhite,
textAlign: TextAlign.center,
),
),
const SizedBox(height: 30),
// TempDirectory
const Text(
'ApplicationSupportDirectory',
style: textStyleTitle,
),
spaceSmall,
Text(
_pathApplicationSupportDirectory ?? 'Not found.',
style: textStylePath,
),
spaceMedium,
// TempDirectory
const Text(
'TempDirectory',
style: textStyleTitle,
),
spaceSmall,
Text(
_pathTempDirectory ?? 'Not found.',
style: textStylePath,
),
spaceMedium,
// ApplicationDocumentsPath
const Text(
'ApplicationDocumentsPath',
style: textStyleTitle,
),
spaceSmall,
Text(
_pathApplicationDocumentsPath ?? 'Not found.',
style: textStylePath,
),
spaceMedium,
// DownloadsPath
const Text(
'DownloadsPath',
style: textStyleTitle,
),
spaceSmall,
Text(
_pathDownloadsPath ?? 'Not found.',
style: textStylePath,
),
spaceMedium,
// Pictures
const Text(
'Pictures',
style: textStyleTitle,
),
spaceSmall,
Text(
_pathPictures ?? 'Not found.',
style: textStylePath,
),
spaceMedium,
// Music
const Text(
'Music',
style: textStyleTitle,
),
spaceSmall,
Text(
_pathMusic ?? 'Not found.',
style: textStylePath,
),
spaceMedium,
// Movies
const Text(
'Movies',
style: textStyleTitle,
),
spaceSmall,
Text(
_pathMovies ?? 'Not found.',
style: textStylePath,
),
],
),
),
),
),
],
)),
),
],
),
),
);
}
}

8
packages/path_provider/path_provider_aurora/example/pubspec.lock

@ -257,11 +257,9 @@ packages:
xdga_directories:
dependency: transitive
description:
path: "packages/xdga_directories"
ref: xdga_directories
resolved-ref: fb19ee472cac234c924a2f222ecc66a03a808ce2
url: "git@os-git.omprussia.ru:non-oss/flutter/flutter-plugins.git"
source: git
path: "../../../xdga_directories"
relative: true
source: path
version: "0.0.1"
sdks:
dart: ">=2.18.6 <3.0.0"

53
packages/path_provider/path_provider_aurora/lib/path_provider_aurora.dart

@ -11,7 +11,54 @@ class PathProviderAurora extends PathProviderPlatform {
PathProviderPlatform.instance = PathProviderAurora();
}
/// Path to a directory where the application may place application support files.
@override
Future<String> getTemporaryPath() async =>
xdga_directories.getCacheLocation();
}
Future<String?> getApplicationSupportPath() async {
return xdga_directories.getAppDataLocation();
}
/// Path to the temporary directory on the device that is not backed up and is
/// suitable for storing caches of downloaded files.
@override
Future<String> getTemporaryPath() async {
// QStandardPaths::CacheLocation
return xdga_directories.getCacheLocation();
}
/// Path to a directory where the application may place data that is
/// user-generated, or that cannot otherwise be recreated by your application.
@override
Future<String> getApplicationDocumentsPath() async {
// QStandardPaths::DocumentsLocation
return xdga_directories.getDocumentsLocation();
}
/// Path to the directory where downloaded files can be stored.
/// This is typically only relevant on desktop operating systems.
@override
Future<String> getDownloadsPath() async {
// QStandardPaths::DownloadLocation
return xdga_directories.getDownloadLocation();
}
/// Paths to directories where application specific data can be stored.
/// These paths typically reside on external storage like separate partitions
/// or SD cards. Phones may have multiple storage directories available.
@override
Future<List<String>?> getExternalStoragePaths({
/// Optional parameter. See [StorageDirectory] for more informations on
/// how this type translates to Android storage directories.
StorageDirectory? type,
}) async {
switch (type) {
case StorageDirectory.pictures:
return [xdga_directories.getPicturesLocation()]; // QStandardPaths::PicturesLocation
case StorageDirectory.music:
return [xdga_directories.getMusicLocation()]; // QStandardPaths::MusicLocation
case StorageDirectory.movies:
return [xdga_directories.getMoviesLocation()]; // QStandardPaths::MoviesLocation
default:
throw UnimplementedError('Type "$type" not supported.');
}
}
}

16
packages/path_provider/path_provider_aurora/pubspec.yaml

@ -18,13 +18,17 @@ dependencies:
flutter:
sdk: flutter
path_provider_platform_interface: ^2.0.6
## @todo
## Publishable packages can't have 'git' dependencies
xdga_directories:
## @todo
## Publishable packages can't have 'git' dependencies
git:
url: git@os-git.omprussia.ru:non-oss/flutter/flutter-plugins.git
ref: xdga_directories
path: packages/xdga_directories
## from folder
path: ../../xdga_directories
## from git
# xdga_directories:
# git:
# url: git@os-git.omprussia.ru:non-oss/flutter/flutter-plugins.git
# ref: xdga_directories
# path: packages/xdga_directories
dev_dependencies:
flutter_test:

224
packages/xdga_directories/example/lib/main.dart

@ -13,6 +13,7 @@ class MyApp extends StatefulWidget {
}
class _MyAppState extends State<MyApp> {
late String appDataLocation;
late String cacheLocation;
late String documentsLocation;
late String downloadLocation;
@ -24,6 +25,8 @@ class _MyAppState extends State<MyApp> {
@override
void initState() {
super.initState();
// Get paths
appDataLocation = xdga_directories.getAppDataLocation();
cacheLocation = xdga_directories.getCacheLocation();
documentsLocation = xdga_directories.getDocumentsLocation();
downloadLocation = xdga_directories.getDownloadLocation();
@ -35,120 +38,135 @@ class _MyAppState extends State<MyApp> {
@override
Widget build(BuildContext context) {
const textStyleNormal = TextStyle(fontSize: 20);
final textStyleSmall = const TextStyle(fontSize: 18).copyWith(color: Colors.black54);
const textStyleWhite = TextStyle(fontSize: 18, color: Colors.white);
const textStyleTitle = TextStyle(fontSize: 20, color: Colors.black);
const textStylePath = TextStyle(fontSize: 18, color: Colors.black54);
const spacerNormal = SizedBox(height: 16);
const spaceMedium = SizedBox(height: 16);
const spacerSmall = SizedBox(height: 8);
return MaterialApp(
home: Scaffold(
appBar: AppBar(
title: const Text('Directories Example'),
title: const Text('Example XDGA'),
),
body: SingleChildScrollView(
child: Container(
padding: const EdgeInsets.all(10),
child: Column(
children: [
Container(
decoration: const BoxDecoration(
child: Center(
child: Container(
padding: const EdgeInsets.all(10),
child: Column(
children: [
Container(
decoration: const BoxDecoration(
color: Colors.green,
borderRadius: BorderRadius.all(Radius.circular(10.0))),
child: Padding(
padding: const EdgeInsets.all(20),
child: Text(
'A Dart package for reading directory path on Aurora OS.',
style: textStyleNormal.copyWith(color: Colors.white),
textAlign: TextAlign.center,
borderRadius: BorderRadius.all(Radius.circular(10.0)),
),
child: const Padding(
padding: EdgeInsets.all(20),
child: Text(
'A Dart package for reading directory path on Aurora OS.',
style: textStyleWhite,
),
),
),
const SizedBox(height: 30),
// getAppDataLocation
const Text(
'getAppDataLocation()',
style: textStyleTitle,
),
spacerSmall,
Text(
appDataLocation,
style: textStylePath,
),
spaceMedium,
// getCacheLocation
const Text(
'getCacheLocation()',
style: textStyleTitle,
),
spacerSmall,
Text(
cacheLocation,
style: textStylePath,
),
spaceMedium,
// getDocumentsLocation
const Text(
'getDocumentsLocation()',
style: textStyleTitle,
),
spacerSmall,
Text(
documentsLocation,
style: textStylePath,
),
spaceMedium,
// getDocumentsLocation
const Text(
'getDownloadLocation()',
style: textStyleTitle,
),
spacerSmall,
Text(
downloadLocation,
style: textStylePath,
),
spaceMedium,
// getDocumentsLocation
const Text(
'getMusicLocation()',
style: textStyleTitle,
),
spacerSmall,
Text(
musicLocation,
style: textStylePath,
),
spaceMedium,
// getDocumentsLocation
const Text(
'getPicturesLocation()',
style: textStyleTitle,
),
spacerSmall,
Text(
picturesLocation,
style: textStylePath,
),
spaceMedium,
// getDocumentsLocation
const Text(
'getGenericDataLocation()',
style: textStyleTitle,
),
spacerSmall,
Text(
genericDataLocation,
style: textStylePath,
),
spaceMedium,
// getDocumentsLocation
const Text(
'getMoviesLocation()',
style: textStyleTitle,
),
spacerSmall,
Text(
moviesLocation,
style: textStylePath,
),
),
const SizedBox(height: 30),
const Text(
'getCacheLocation()',
style: textStyleNormal,
textAlign: TextAlign.center,
),
spacerSmall,
Text(
cacheLocation,
style: textStyleSmall,
textAlign: TextAlign.center,
),
spacerNormal,
const Text(
'getDocumentsLocation()',
style: textStyleNormal,
textAlign: TextAlign.center,
),
spacerSmall,
Text(
documentsLocation,
style: textStyleSmall,
textAlign: TextAlign.center,
),
spacerNormal,
const Text(
'getDownloadLocation()',
style: textStyleNormal,
textAlign: TextAlign.center,
),
spacerSmall,
Text(
downloadLocation,
style: textStyleSmall,
textAlign: TextAlign.center,
),
spacerNormal,
const Text(
'getMusicLocation()',
style: textStyleNormal,
textAlign: TextAlign.center,
),
spacerSmall,
Text(
musicLocation,
style: textStyleSmall,
textAlign: TextAlign.center,
),
spacerNormal,
const Text(
'getPicturesLocation()',
style: textStyleNormal,
textAlign: TextAlign.center,
),
spacerSmall,
Text(
picturesLocation,
style: textStyleSmall,
textAlign: TextAlign.center,
),
spacerNormal,
const Text(
'getGenericDataLocation()',
style: textStyleNormal,
textAlign: TextAlign.center,
),
spacerSmall,
Text(
genericDataLocation,
style: textStyleSmall,
textAlign: TextAlign.center,
),
spacerNormal,
const Text(
'getMoviesLocation()',
style: textStyleNormal,
textAlign: TextAlign.center,
),
spacerSmall,
Text(
moviesLocation,
style: textStyleSmall,
textAlign: TextAlign.center,
),
],
],
),
),
),
),

3
packages/xdga_directories/lib/xdga_directories.dart

@ -17,6 +17,9 @@ final XdgaDirectoriesBindings _bindings = XdgaDirectoriesBindings(_dylib);
/// QStandardPaths::CacheLocation
String getCacheLocation() => _bindings.getCacheLocation().cast<Utf8>().toDartString();
/// QStandardPaths::AppDataLocation
String getAppDataLocation() => _bindings.getAppDataLocation().cast<Utf8>().toDartString();
/// QStandardPaths::DocumentsLocation
String getDocumentsLocation() => _bindings.getDocumentsLocation().cast<Utf8>().toDartString();

10
packages/xdga_directories/lib/xdga_directories_bindings_generated.dart

@ -32,6 +32,16 @@ class XdgaDirectoriesBindings {
late final _getCacheLocation =
_getCacheLocationPtr.asFunction<ffi.Pointer<ffi.Char> Function()>();
ffi.Pointer<ffi.Char> getAppDataLocation() {
return _getAppDataLocation();
}
late final _getAppDataLocationPtr =
_lookup<ffi.NativeFunction<ffi.Pointer<ffi.Char> Function()>>(
'getAppDataLocation');
late final _getAppDataLocation =
_getAppDataLocationPtr.asFunction<ffi.Pointer<ffi.Char> Function()>();
ffi.Pointer<ffi.Char> getDocumentsLocation() {
return _getDocumentsLocation();
}

5
packages/xdga_directories/src/xdga_directories.cpp

@ -7,6 +7,11 @@ char *getCacheLocation()
return QStandardPaths::writableLocation(QStandardPaths::CacheLocation).toUtf8().data();
}
char *getAppDataLocation()
{
return QStandardPaths::writableLocation(QStandardPaths::AppDataLocation).toUtf8().data();
}
char *getDocumentsLocation()
{
return QStandardPaths::writableLocation(QStandardPaths::DocumentsLocation).toUtf8().data();

2
packages/xdga_directories/src/xdga_directories.h

@ -4,6 +4,8 @@ extern "C" {
char *getCacheLocation();
char *getAppDataLocation();
char *getDocumentsLocation();
char *getDownloadLocation();

Loading…
Cancel
Save