Skip to content

Commit

Permalink
Packages: Cleanup and code improvements
Browse files Browse the repository at this point in the history
  • Loading branch information
gokadzev committed Aug 8, 2023
1 parent b1af444 commit 043696f
Show file tree
Hide file tree
Showing 7 changed files with 38 additions and 44 deletions.
6 changes: 3 additions & 3 deletions packages/audio_service/audio_service/analysis_options.yaml
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
include: package:flutter_lints/flutter.yaml

analyzer:
strong-mode:
implicit-casts: false
implicit-dynamic: false
language:
strict-casts: false
strict-raw-types: false

linter:
rules:
Expand Down
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
include: package:flutter_lints/flutter.yaml

analyzer:
strong-mode:
implicit-casts: false
implicit-dynamic: false
language:
strict-casts: false
strict-raw-types: false
exclude:
- '**/*.mocks.dart'

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,8 +12,6 @@ Copyright: © 2021, Lucas Josino. All rights reserved.
=============
*/

import 'dart:typed_data';

import 'package:flutter/material.dart';
import 'package:flutter/services.dart';
import 'package:on_audio_query_platform_interface/on_audio_query_platform_interface.dart';
Expand Down Expand Up @@ -60,7 +58,7 @@ class QueryArtworkWidget extends StatelessWidget {
///
/// Important:
///
/// * If [quality] is null, will be set to [100].
/// * If [quality] is null, will be set to [50].
final int quality;

/// Used to define the artwork [border radius].
Expand Down Expand Up @@ -327,7 +325,7 @@ class QueryArtworkWidget extends StatelessWidget {

@override
Widget build(BuildContext context) {
if (quality != null && quality! > 100) {
if (quality > 100) {
throw Exception(
'[quality] value cannot be greater than [100]',
);
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
import 'dart:convert';
import 'dart:typed_data';

import 'package:flutter/services.dart';
import 'package:on_audio_query_platform_interface/on_audio_query_platform_interface.dart';
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
import 'dart:convert';
import 'dart:io';
import 'dart:typed_data';

import 'package:flutter/services.dart';
import 'package:on_audio_query_platform_interface/on_audio_query_platform_interface.dart';
Expand Down
49 changes: 24 additions & 25 deletions packages/receive_sharing_intent/lib/receive_sharing_intent.dart
Original file line number Diff line number Diff line change
Expand Up @@ -5,11 +5,11 @@ import 'package:flutter/services.dart';

class ReceiveSharingIntent {
static const MethodChannel _mChannel =
const MethodChannel('receive_sharing_intent/messages');
MethodChannel('receive_sharing_intent/messages');
static const EventChannel _eChannelMedia =
const EventChannel("receive_sharing_intent/events-media");
EventChannel('receive_sharing_intent/events-media');
static const EventChannel _eChannelLink =
const EventChannel("receive_sharing_intent/events-text");
EventChannel('receive_sharing_intent/events-text');

static Stream<List<SharedMediaFile>>? _streamMedia;
static Stream<String>? _streamLink;
Expand All @@ -25,17 +25,15 @@ class ReceiveSharingIntent {
final json = await _mChannel.invokeMethod('getInitialMedia');
if (json == null) return [];
final encoded = jsonDecode(json);
return encoded
.map<SharedMediaFile>((file) => SharedMediaFile.fromJson(file))
.toList();
return encoded.map<SharedMediaFile>(SharedMediaFile.fromJson).toList();
}

/// Returns a [Future], which completes to one of the following:
///
/// * the initially stored link (possibly null), on successful invocation;
/// * a [PlatformException], if the invocation failed in the platform plugin.
static Future<String?> getInitialText() async {
return await _mChannel.invokeMethod('getInitialText');
return _mChannel.invokeMethod('getInitialText');
}

/// A convenience method that returns the initially stored link
Expand Down Expand Up @@ -68,18 +66,21 @@ class ReceiveSharingIntent {
static Stream<List<SharedMediaFile>> getMediaStream() {
if (_streamMedia == null) {
final stream =
_eChannelMedia.receiveBroadcastStream("media").cast<String?>();
_eChannelMedia.receiveBroadcastStream('media').cast<String?>();
_streamMedia = stream.transform<List<SharedMediaFile>>(
new StreamTransformer<String?, List<SharedMediaFile>>.fromHandlers(
StreamTransformer<String?, List<SharedMediaFile>>.fromHandlers(
handleData: (String? data, EventSink<List<SharedMediaFile>> sink) {
if (data == null) {
sink.add([]);
} else {
final encoded = jsonDecode(data);
sink.add(encoded
.map<SharedMediaFile>(
(file) => SharedMediaFile.fromJson(file))
.toList());
sink.add(
encoded
.map<SharedMediaFile>(
SharedMediaFile.fromJson,
)
.toList(),
);
}
},
),
Expand All @@ -105,9 +106,7 @@ class ReceiveSharingIntent {
/// If the app was started by a link intent or user activity the stream will
/// not emit that initial one - query either the `getInitialText` instead.
static Stream<String> getTextStream() {
if (_streamLink == null) {
_streamLink = _eChannelLink.receiveBroadcastStream("text").cast<String>();
}
_streamLink ??= _eChannelLink.receiveBroadcastStream('text').cast<String>();
return _streamLink!;
}

Expand All @@ -122,7 +121,7 @@ class ReceiveSharingIntent {
/// not emit that initial uri - query either the `getInitialTextAsUri` instead.
static Stream<Uri> getTextStreamAsUri() {
return getTextStream().transform<Uri>(
new StreamTransformer<String, Uri>.fromHandlers(
StreamTransformer<String, Uri>.fromHandlers(
handleData: (String data, EventSink<Uri> sink) {
sink.add(Uri.parse(data));
},
Expand All @@ -138,6 +137,14 @@ class ReceiveSharingIntent {
}

class SharedMediaFile {
SharedMediaFile(this.path, this.thumbnail, this.duration, this.type);

SharedMediaFile.fromJson(Map<String, dynamic> json)
: path = json['path'],
thumbnail = json['thumbnail'],
duration = json['duration'],
type = SharedMediaType.values[json['type']];

/// Image or Video path.
/// NOTE. for iOS only the file is always copied
final String path;
Expand All @@ -150,14 +157,6 @@ class SharedMediaFile {

/// Whether its a video or image or file
final SharedMediaType type;

SharedMediaFile(this.path, this.thumbnail, this.duration, this.type);

SharedMediaFile.fromJson(Map<String, dynamic> json)
: path = json['path'],
thumbnail = json['thumbnail'],
duration = json['duration'],
type = SharedMediaType.values[json['type']];
}

enum SharedMediaType { IMAGE, VIDEO, FILE }
Original file line number Diff line number Diff line change
Expand Up @@ -3,17 +3,16 @@ import 'package:flutter_test/flutter_test.dart';
import 'package:receive_sharing_intent/receive_sharing_intent.dart';

void main() {
const MethodChannel channel =
const MethodChannel('receive_sharing_intent/messages');
const channel = MethodChannel('receive_sharing_intent/messages');

const _testUriString = "content://media/external/images/media/43993";
const _testUriString = 'content://media/external/images/media/43993';

setUp(() {
channel.setMockMethodCallHandler((MethodCall methodCall) async {
switch (methodCall.method) {
case "getInitialText":
case 'getInitialText':
return _testUriString;
case "getInitialTextAsUri":
case 'getInitialTextAsUri':
return Uri.parse(_testUriString);
default:
throw UnimplementedError();
Expand All @@ -26,12 +25,12 @@ void main() {
});

test('getInitialText', () async {
var actual = await ReceiveSharingIntent.getInitialText();
final actual = await ReceiveSharingIntent.getInitialText();
expect(actual, _testUriString);
});

test('getInitialTextAsUri', () async {
var actual = await ReceiveSharingIntent.getInitialTextAsUri();
final actual = await ReceiveSharingIntent.getInitialTextAsUri();
expect(actual, Uri.parse(_testUriString));
});
}

0 comments on commit 043696f

Please sign in to comment.