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

[file_selector] Convert XTypeGroup to const #6476

Merged
Merged
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
Original file line number Diff line number Diff line change
@@ -1,3 +1,7 @@
## 2.2.0

* Makes `XTypeGroup`'s constructor constant.

## 2.1.1

* Updates imports for `prefer_relative_imports`.
Expand Down
Original file line number Diff line number Diff line change
@@ -1,37 +1,43 @@
// Copyright 2013 The Flutter Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
import 'package:flutter/foundation.dart' show immutable;

/// A set of allowed XTypes
/// A set of allowed XTypes.
@immutable
class XTypeGroup {
/// Creates a new group with the given label and file extensions.
///
/// A group with none of the type options provided indicates that any type is
/// allowed.
XTypeGroup({
const XTypeGroup({
this.label,
List<String>? extensions,
this.mimeTypes,
this.macUTIs,
this.webWildCards,
}) : extensions = _removeLeadingDots(extensions);
}) : _extensions = extensions;

/// The 'name' or reference to this group of types
/// The 'name' or reference to this group of types.
final String? label;

/// The extensions for this group
final List<String>? extensions;

/// The MIME types for this group
/// The MIME types for this group.
final List<String>? mimeTypes;

/// The UTIs for this group
/// The UTIs for this group.
final List<String>? macUTIs;

/// The web wild cards for this group (ex: image/*, video/*)
/// The web wild cards for this group (ex: image/*, video/*).
final List<String>? webWildCards;

/// Converts this object into a JSON formatted object
final List<String>? _extensions;

/// The extensions for this group.
List<String>? get extensions {
return _removeLeadingDots(_extensions);
}

/// Converts this object into a JSON formatted object.
Map<String, dynamic> toJSON() {
return <String, dynamic>{
'label': label,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ repository: https://github.com/flutter/plugins/tree/main/packages/file_selector/
issue_tracker: https://github.com/flutter/flutter/issues?q=is%3Aissue+is%3Aopen+label%3A%22p%3A+file_selector%22
# NOTE: We strongly prefer non-breaking changes, even at the expense of a
# less-clean API. See https://flutter.dev/go/platform-interface-breaking-changes
version: 2.1.1
version: 2.2.0

environment:
sdk: ">=2.12.0 <3.0.0"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,14 +26,14 @@ void main() {

group('#openFile', () {
test('passes the accepted type groups correctly', () async {
final XTypeGroup group = XTypeGroup(
const XTypeGroup group = XTypeGroup(
label: 'text',
extensions: <String>['txt'],
mimeTypes: <String>['text/plain'],
macUTIs: <String>['public.text'],
);

final XTypeGroup groupTwo = XTypeGroup(
const XTypeGroup groupTwo = XTypeGroup(
label: 'image',
extensions: <String>['jpg'],
mimeTypes: <String>['image/jpg'],
Expand Down Expand Up @@ -91,14 +91,14 @@ void main() {
});
group('#openFiles', () {
test('passes the accepted type groups correctly', () async {
final XTypeGroup group = XTypeGroup(
const XTypeGroup group = XTypeGroup(
label: 'text',
extensions: <String>['txt'],
mimeTypes: <String>['text/plain'],
macUTIs: <String>['public.text'],
);

final XTypeGroup groupTwo = XTypeGroup(
const XTypeGroup groupTwo = XTypeGroup(
label: 'image',
extensions: <String>['jpg'],
mimeTypes: <String>['image/jpg'],
Expand Down Expand Up @@ -157,14 +157,14 @@ void main() {

group('#getSavePath', () {
test('passes the accepted type groups correctly', () async {
final XTypeGroup group = XTypeGroup(
const XTypeGroup group = XTypeGroup(
label: 'text',
extensions: <String>['txt'],
mimeTypes: <String>['text/plain'],
macUTIs: <String>['public.text'],
);

final XTypeGroup groupTwo = XTypeGroup(
const XTypeGroup groupTwo = XTypeGroup(
label: 'image',
extensions: <String>['jpg'],
mimeTypes: <String>['image/jpg'],
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ void main() {
});

test('A wildcard group can be created', () {
final XTypeGroup group = XTypeGroup(
const XTypeGroup group = XTypeGroup(
label: 'Any',
);

Expand All @@ -44,7 +44,7 @@ void main() {
});

test('allowsAny treats empty arrays the same as null', () {
final XTypeGroup group = XTypeGroup(
const XTypeGroup group = XTypeGroup(
label: 'Any',
extensions: <String>[],
mimeTypes: <String>[],
Expand All @@ -56,13 +56,13 @@ void main() {
});

test('allowsAny returns false if anything is set', () {
final XTypeGroup extensionOnly =
const XTypeGroup extensionOnly =
XTypeGroup(label: 'extensions', extensions: <String>['txt']);
final XTypeGroup mimeOnly =
const XTypeGroup mimeOnly =
XTypeGroup(label: 'mime', mimeTypes: <String>['text/plain']);
final XTypeGroup utiOnly =
const XTypeGroup utiOnly =
XTypeGroup(label: 'utis', macUTIs: <String>['public.text']);
final XTypeGroup webOnly =
const XTypeGroup webOnly =
XTypeGroup(label: 'web', webWildCards: <String>['.txt']);

expect(extensionOnly.allowsAny, false);
Expand Down