Thanks to visit codestin.com
Credit goes to github.com

Skip to content
This repository was archived by the owner on Feb 22, 2023. It is now read-only.

[file_selector] Implement for Windows #3265

Closed
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions packages/file_selector/file_selector_windows/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
.packages
.flutter-plugins
pubspec.lock
10 changes: 10 additions & 0 deletions packages/file_selector/file_selector_windows/.metadata
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
# This file tracks properties of this Flutter project.
# Used by Flutter tool to assess capabilities and perform upgrades etc.
#
# This file should be version controlled and should not be manually edited.

version:
revision: 6d1c244b79f3a2747281f718297ce248bd5ad099
channel: master

project_type: plugin
3 changes: 3 additions & 0 deletions packages/file_selector/file_selector_windows/CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
## 0.0.1

* Initial Windows implementation of `file_selector`.
25 changes: 25 additions & 0 deletions packages/file_selector/file_selector_windows/LICENSE
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
Copyright 2020 The Flutter Authors. All rights reserved.

Redistribution and use in source and binary forms, with or without modification,
are permitted provided that the following conditions are met:

* Redistributions of source code must retain the above copyright
notice, this list of conditions and the following disclaimer.
* Redistributions in binary form must reproduce the above
copyright notice, this list of conditions and the following
disclaimer in the documentation and/or other materials provided
with the distribution.
* Neither the name of Google Inc. nor the names of its
contributors may be used to endorse or promote products derived
from this software without specific prior written permission.

THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR
ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
(INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON
ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
(INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
42 changes: 42 additions & 0 deletions packages/file_selector/file_selector_windows/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
# file_selector_windows

The Windows implementation of [`file_selector`][1].

## Backward compatible 1.0.0 version is coming
The plugin has reached a stable API, we guarantee that version `1.0.0` will be backward compatible with `0.0.y+z`. If you use
file_selector_windows directly, rather than as an implementation detail
of `file_selector`, please use `file_selector_windows: '>=0.0.y+x <2.0.0'`
as your dependency constraint to allow a smoother ecosystem migration.
For more details see: https://github.com/flutter/flutter/wiki/Package-migration-to-1.0.0

## Usage

### Import the package

This package has not yet been endorsed, meaning that you need to add `file_selector_windows`
as a dependency in your `pubspec.yaml`. It will be not yet be automatically included in your app
when you depend on `package:file_selector`.

This is what the above means to your `pubspec.yaml`:

```yaml
...
dependencies:
...
file_selector: ^0.7.0
file_selector_windows: ^0.0.1
...
```

If you wish to use the Windows package only, you can add `file_selector_windows` as a
dependency:

```yaml
...
dependencies:
...
file_selector_windows: ^0.0.1
...
```

[1]: ../file_selector/file_selector
41 changes: 41 additions & 0 deletions packages/file_selector/file_selector_windows/example/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
# Miscellaneous
*.class
*.log
*.pyc
*.swp
.DS_Store
.atom/
.buildlog/
.history
.svn/

# IntelliJ related
*.iml
*.ipr
*.iws
.idea/

# The .vscode folder contains launch configuration and tasks you configure in
# VS Code which you may wish to be included in version control, so this line
# is commented out by default.
#.vscode/

# Flutter/Dart/Pub related
**/doc/api/
**/ios/Flutter/.last_build_id
.dart_tool/
.flutter-plugins
.flutter-plugins-dependencies
.packages
.pub-cache/
.pub/
/build/

# Web related
lib/generated_plugin_registrant.dart

# Symbolication related
app.*.symbols

# Obfuscation related
app.*.map.json
10 changes: 10 additions & 0 deletions packages/file_selector/file_selector_windows/example/.metadata
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
# This file tracks properties of this Flutter project.
# Used by Flutter tool to assess capabilities and perform upgrades etc.
#
# This file should be version controlled and should not be manually edited.

version:
revision: 6d1c244b79f3a2747281f718297ce248bd5ad099
channel: master

project_type: app
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
# file_selector_windows_example

Demonstrates the file_selector_windows plugin.
175 changes: 175 additions & 0 deletions packages/file_selector/file_selector_windows/example/lib/main.dart
Original file line number Diff line number Diff line change
@@ -0,0 +1,175 @@
// Copyright 2017 The Chromium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.

// ignore_for_file: public_member_api_docs

import 'dart:async';
import 'package:flutter/material.dart';
import 'package:file_selector_platform_interface/file_selector_platform_interface.dart';

void main() {
runApp(MyApp());
}

class MyApp extends StatelessWidget {
@override
Widget build(BuildContext context) {
return MaterialApp(
title: 'File Selector',
theme: ThemeData(
primarySwatch: Colors.blue,
),
home: MyHomePage(title: 'File Selector'),
);
}
}

class MyHomePage extends StatefulWidget {
MyHomePage({Key key, this.title}) : super(key: key);
final String title;

@override
_MyHomePageState createState() => _MyHomePageState();
}

class _MyHomePageState extends State<MyHomePage> {
Future<dynamic> _selectorResult;

Widget _showResult(BuildContext context, AsyncSnapshot<dynamic> snapshot) {
if (snapshot.hasError) {
return Text('Error: ${snapshot.error}');
} else {
String text;
if (!snapshot.hasData) {
return Text('');
} else if (snapshot.data is String) {
text = snapshot.data;
} else if (snapshot.data is XFile) {
text = (snapshot.data as XFile).path;
} else if (snapshot.data is List<XFile>) {
text = (snapshot.data as List<XFile>).map((e) => e.path).join(', ');
} else {
text = 'Unexpected return type: ${snapshot.data}';
}
return Text(text);
}
}

@override
Widget build(BuildContext context) {
return Scaffold(
appBar: AppBar(
title: Text(widget.title),
),
body: ListView(
children: <Widget>[
Column(
mainAxisAlignment: MainAxisAlignment.center,
children: <Widget>[
ButtonBar(
alignment: MainAxisAlignment.center,
children: <Widget>[
RaisedButton(
child: Padding(
padding: const EdgeInsets.all(8.0),
child: const Text('SAVE'),
),
onPressed: () {
setState(() {
_selectorResult =
FileSelectorPlatform.instance.getSavePath(
suggestedName: 'a_file.txt',
initialDirectory: r'C:\Users',
confirmButtonText: 'Save It',
);
});
},
),
RaisedButton(
child: Padding(
padding: const EdgeInsets.all(8.0),
child: const Text('OPEN MULTIPLE'),
),
onPressed: () {
setState(() {
_selectorResult =
FileSelectorPlatform.instance.openFiles(
initialDirectory: r'C:\',
confirmButtonText: 'Open All',
acceptedTypeGroups: <XTypeGroup>[
XTypeGroup(label: 'Any'),
XTypeGroup(
label: 'Text',
extensions: <String>[
'txt',
'rtf',
],
),
],
);
});
},
),
RaisedButton(
child: Padding(
padding: const EdgeInsets.all(8.0),
child: const Text('OPEN SINGLE MEDIA'),
),
onPressed: () {
setState(() {
_selectorResult =
FileSelectorPlatform.instance.openFile(
acceptedTypeGroups: <XTypeGroup>[
XTypeGroup(
label: 'Images',
extensions: <String>[
'bmp',
'gif',
'jpeg',
'jpg',
'png',
'tiff',
'webp',
],
),
XTypeGroup(
label: 'Video',
extensions: <String>[
'webm',
'mpg',
'mpeg',
'mov',
],
),
],
);
});
},
),
RaisedButton(
child: Padding(
padding: const EdgeInsets.all(8.0),
child: const Text('OPEN DIRECTORY'),
),
onPressed: () {
setState(() {
_selectorResult =
FileSelectorPlatform.instance.getDirectoryPath(
initialDirectory: r'C:\Users',
confirmButtonText: 'Open Directory',
);
});
},
),
],
),
FutureBuilder<void>(
future: _selectorResult, builder: _showResult),
],
),
],
),
);
}
}
17 changes: 17 additions & 0 deletions packages/file_selector/file_selector_windows/example/pubspec.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
name: file_selector_example
description: Demonstrates the Windows implementation of the file_selector plugin.

dependencies:
flutter:
sdk: flutter
file_selector_platform_interface: any
file_selector_windows:
path: ../

dev_dependencies:
flutter_driver:
sdk: flutter
pedantic: ^1.8.0

flutter:
uses-material-design: true
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
flutter/ephemeral/

# Visual Studio user-specific files.
*.suo
*.user
*.userosscache
*.sln.docstates

# Visual Studio build-related files.
x64/
x86/

# Visual Studio cache files
# files ending in .cache can be ignored
*.[Cc]ache
# but keep track of directories ending in .cache
!*.[Cc]ache/
Loading