diff --git a/example/analysis_options.yaml b/example/analysis_options.yaml new file mode 100644 index 0000000..61b6c4d --- /dev/null +++ b/example/analysis_options.yaml @@ -0,0 +1,29 @@ +# This file configures the analyzer, which statically analyzes Dart code to +# check for errors, warnings, and lints. +# +# The issues identified by the analyzer are surfaced in the UI of Dart-enabled +# IDEs (https://dart.dev/tools#ides-and-editors). The analyzer can also be +# invoked from the command line by running `flutter analyze`. + +# The following line activates a set of recommended lints for Flutter apps, +# packages, and plugins designed to encourage good coding practices. +include: package:flutter_lints/flutter.yaml + +linter: + # The lint rules applied to this project can be customized in the + # section below to disable rules from the `package:flutter_lints/flutter.yaml` + # included above or to enable additional rules. A list of all available lints + # and their documentation is published at + # https://dart-lang.github.io/linter/lints/index.html. + # + # Instead of disabling a lint rule for the entire project in the + # section below, it can also be suppressed for a single line of code + # or a specific dart file by using the `// ignore: name_of_lint` and + # `// ignore_for_file: name_of_lint` syntax on the line or in the file + # producing the lint. + rules: + # avoid_print: false # Uncomment to disable the `avoid_print` rule + # prefer_single_quotes: true # Uncomment to enable the `prefer_single_quotes` rule + +# Additional information about this file can be found at +# https://dart.dev/guides/language/analysis-options diff --git a/example/lib/main.dart b/example/lib/main.dart index 916a983..498f621 100644 --- a/example/lib/main.dart +++ b/example/lib/main.dart @@ -1,12 +1,11 @@ import 'dart:io'; +import 'package:flutter/foundation.dart'; import 'package:flutter/material.dart'; import 'package:flutter/services.dart'; import 'package:file_picker/file_picker.dart'; import 'package:flutter_media_metadata/flutter_media_metadata.dart'; -const kPluginName = 'flutter_media_metadata'; - void main() { SystemChrome.setSystemUIOverlayStyle( SystemUiOverlayStyle( @@ -18,8 +17,6 @@ void main() { ); runApp( MaterialApp( - darkTheme: ThemeData.dark(), - themeMode: ThemeMode.dark, home: MyApp(), ), ); @@ -38,10 +35,9 @@ class _MyAppState extends State { return Scaffold( appBar: AppBar( title: Text( - kPluginName, + 'flutter_media_metadata', ), ), - backgroundColor: Color(0xFF121212), floatingActionButton: FloatingActionButton( onPressed: () { FilePicker.platform.pickFiles() @@ -49,177 +45,37 @@ class _MyAppState extends State { (result) { if (result == null) return; if (result.count == 0) return; - MetadataRetriever.fromFile( - File(result.files.first.path!), - ) - ..then( - (metadata) { + if (kIsWeb) { + /// Use [MetadataRetriever.fromBytes] on Web. + MetadataRetriever.fromBytes( + result.files.first.bytes!, + ) + ..then( + (metadata) { + showData(metadata); + }, + ) + ..catchError((_) { setState(() { - _child = ListView( - scrollDirection: MediaQuery.of(context).size.height > - MediaQuery.of(context).size.width - ? Axis.vertical - : Axis.horizontal, - children: [ - metadata.albumArt == null - ? Container( - alignment: Alignment.center, - height: MediaQuery.of(context).size.height > - MediaQuery.of(context).size.width - ? MediaQuery.of(context).size.width - : 256.0, - width: MediaQuery.of(context).size.height > - MediaQuery.of(context).size.width - ? MediaQuery.of(context).size.width - : 256.0, - child: Text('null'), - ) - : Image.memory( - metadata.albumArt!, - height: MediaQuery.of(context).size.height > - MediaQuery.of(context).size.width - ? MediaQuery.of(context).size.width - : 256.0, - width: MediaQuery.of(context).size.height > - MediaQuery.of(context).size.width - ? MediaQuery.of(context).size.width - : 256.0, - ), - SizedBox( - width: 16.0, - ), - SingleChildScrollView( - scrollDirection: - MediaQuery.of(context).size.height > - MediaQuery.of(context).size.width - ? Axis.horizontal - : Axis.vertical, - child: DataTable( - columns: [ - DataColumn( - label: Text( - 'Property', - style: TextStyle( - fontWeight: FontWeight.w600, - ), - ), - ), - DataColumn( - label: Text( - 'Value', - style: TextStyle( - fontWeight: FontWeight.w600, - ), - ), - ), - ], - rows: [ - DataRow( - cells: [ - DataCell(Text('trackName')), - DataCell(Text('${metadata.trackName}')), - ], - ), - DataRow( - cells: [ - DataCell(Text('trackArtistNames')), - DataCell( - Text('${metadata.trackArtistNames}')), - ], - ), - DataRow( - cells: [ - DataCell(Text('albumName')), - DataCell(Text('${metadata.albumName}')), - ], - ), - DataRow( - cells: [ - DataCell(Text('albumArtistName')), - DataCell( - Text('${metadata.albumArtistName}')), - ], - ), - DataRow( - cells: [ - DataCell(Text('trackNumber')), - DataCell(Text('${metadata.trackNumber}')), - ], - ), - DataRow( - cells: [ - DataCell(Text('albumLength')), - DataCell(Text('${metadata.albumLength}')), - ], - ), - DataRow( - cells: [ - DataCell(Text('year')), - DataCell(Text('${metadata.year}')), - ], - ), - DataRow( - cells: [ - DataCell(Text('genre')), - DataCell(Text('${metadata.genre}')), - ], - ), - DataRow( - cells: [ - DataCell(Text('authorName')), - DataCell(Text('${metadata.authorName}')), - ], - ), - DataRow( - cells: [ - DataCell(Text('writerName')), - DataCell(Text('${metadata.writerName}')), - ], - ), - DataRow( - cells: [ - DataCell(Text('discNumber')), - DataCell(Text('${metadata.discNumber}')), - ], - ), - DataRow( - cells: [ - DataCell(Text('mimeType')), - DataCell(Text('${metadata.mimeType}')), - ], - ), - DataRow( - cells: [ - DataCell(Text('trackDuration')), - DataCell( - Text('${metadata.trackDuration}')), - ], - ), - DataRow( - cells: [ - DataCell(Text('bitrate')), - DataCell(Text('${metadata.bitrate}')), - ], - ), - DataRow( - cells: [ - DataCell(Text('filePath')), - DataCell(Text('${metadata.filePath}')), - ], - ), - ], - ), - ) - ], - ); + _child = Text('Couldn\'t extract metadata'); }); - }, + }); + } else { + /// Use [MetadataRetriever.fromFile] on Windows, Linux, macOS, Android or iOS. + MetadataRetriever.fromFile( + File(result.files.first.path!), ) - ..catchError((_) { - setState(() { - _child = Text('Couldn\'t extract metadata'); + ..then( + (metadata) { + showData(metadata); + }, + ) + ..catchError((_) { + setState(() { + _child = Text('Couldn\'t extract metadata'); + }); }); - }); + } }, ) ..catchError((_) { @@ -235,4 +91,167 @@ class _MyAppState extends State { ), ); } + + void showData(Metadata metadata) { + setState(() { + _child = ListView( + scrollDirection: MediaQuery.of(context).size.height > + MediaQuery.of(context).size.width + ? Axis.vertical + : Axis.horizontal, + children: [ + if (MediaQuery.of(context).size.height <= + MediaQuery.of(context).size.width) + SizedBox( + width: 16.0, + ), + metadata.albumArt == null + ? Container( + alignment: Alignment.center, + height: MediaQuery.of(context).size.height > + MediaQuery.of(context).size.width + ? MediaQuery.of(context).size.width + : 256.0, + width: MediaQuery.of(context).size.height > + MediaQuery.of(context).size.width + ? MediaQuery.of(context).size.width + : 256.0, + child: Text('null'), + ) + : Image.memory( + metadata.albumArt!, + height: MediaQuery.of(context).size.height > + MediaQuery.of(context).size.width + ? MediaQuery.of(context).size.width + : 256.0, + width: MediaQuery.of(context).size.height > + MediaQuery.of(context).size.width + ? MediaQuery.of(context).size.width + : 256.0, + ), + SizedBox( + width: 16.0, + ), + SingleChildScrollView( + scrollDirection: MediaQuery.of(context).size.height > + MediaQuery.of(context).size.width + ? Axis.horizontal + : Axis.vertical, + child: DataTable( + columns: [ + DataColumn( + label: Text( + 'Property', + style: TextStyle( + fontWeight: FontWeight.w600, + ), + ), + ), + DataColumn( + label: Text( + 'Value', + style: TextStyle( + fontWeight: FontWeight.w600, + ), + ), + ), + ], + rows: [ + DataRow( + cells: [ + DataCell(Text('trackName')), + DataCell(Text('${metadata.trackName}')), + ], + ), + DataRow( + cells: [ + DataCell(Text('trackArtistNames')), + DataCell(Text('${metadata.trackArtistNames}')), + ], + ), + DataRow( + cells: [ + DataCell(Text('albumName')), + DataCell(Text('${metadata.albumName}')), + ], + ), + DataRow( + cells: [ + DataCell(Text('albumArtistName')), + DataCell(Text('${metadata.albumArtistName}')), + ], + ), + DataRow( + cells: [ + DataCell(Text('trackNumber')), + DataCell(Text('${metadata.trackNumber}')), + ], + ), + DataRow( + cells: [ + DataCell(Text('albumLength')), + DataCell(Text('${metadata.albumLength}')), + ], + ), + DataRow( + cells: [ + DataCell(Text('year')), + DataCell(Text('${metadata.year}')), + ], + ), + DataRow( + cells: [ + DataCell(Text('genre')), + DataCell(Text('${metadata.genre}')), + ], + ), + DataRow( + cells: [ + DataCell(Text('authorName')), + DataCell(Text('${metadata.authorName}')), + ], + ), + DataRow( + cells: [ + DataCell(Text('writerName')), + DataCell(Text('${metadata.writerName}')), + ], + ), + DataRow( + cells: [ + DataCell(Text('discNumber')), + DataCell(Text('${metadata.discNumber}')), + ], + ), + DataRow( + cells: [ + DataCell(Text('mimeType')), + DataCell(Text('${metadata.mimeType}')), + ], + ), + DataRow( + cells: [ + DataCell(Text('trackDuration')), + DataCell(Text('${metadata.trackDuration}')), + ], + ), + DataRow( + cells: [ + DataCell(Text('bitrate')), + DataCell(Text('${metadata.bitrate}')), + ], + ), + DataRow( + cells: [ + DataCell(Text('filePath')), + DataCell(Text('${metadata.filePath}')), + ], + ), + ], + ), + ) + ], + ); + }); + } } diff --git a/example/linux/flutter/generated_plugin_registrant.cc b/example/linux/flutter/generated_plugin_registrant.cc index 7e1cede..cc360b0 100644 --- a/example/linux/flutter/generated_plugin_registrant.cc +++ b/example/linux/flutter/generated_plugin_registrant.cc @@ -2,6 +2,8 @@ // Generated file. Do not edit. // +// clang-format off + #include "generated_plugin_registrant.h" #include diff --git a/example/linux/flutter/generated_plugin_registrant.h b/example/linux/flutter/generated_plugin_registrant.h index 9bf7478..e0f0a47 100644 --- a/example/linux/flutter/generated_plugin_registrant.h +++ b/example/linux/flutter/generated_plugin_registrant.h @@ -2,6 +2,8 @@ // Generated file. Do not edit. // +// clang-format off + #ifndef GENERATED_PLUGIN_REGISTRANT_ #define GENERATED_PLUGIN_REGISTRANT_ diff --git a/example/macos/Runner/Configs/AppInfo.xcconfig b/example/macos/Runner/Configs/AppInfo.xcconfig index c0dfb99..ac32227 100644 --- a/example/macos/Runner/Configs/AppInfo.xcconfig +++ b/example/macos/Runner/Configs/AppInfo.xcconfig @@ -11,4 +11,4 @@ PRODUCT_NAME = example PRODUCT_BUNDLE_IDENTIFIER = com.alexmercerind.example // The copyright displayed in application information -PRODUCT_COPYRIGHT = Copyright © 2021 com.alexmercerind. All rights reserved. +PRODUCT_COPYRIGHT = Copyright © 2021-2022 com.alexmercerind. All rights reserved. diff --git a/example/pubspec.lock b/example/pubspec.lock index 02df00c..d73009e 100644 --- a/example/pubspec.lock +++ b/example/pubspec.lock @@ -82,7 +82,7 @@ packages: path: ".." relative: true source: path - version: "0.1.3" + version: "1.0.0" flutter_plugin_android_lifecycle: dependency: transitive description: diff --git a/example/web/favicon.png b/example/web/favicon.png new file mode 100644 index 0000000..8aaa46a Binary files /dev/null and b/example/web/favicon.png differ diff --git a/example/web/icons/Icon-192.png b/example/web/icons/Icon-192.png new file mode 100644 index 0000000..b749bfe Binary files /dev/null and b/example/web/icons/Icon-192.png differ diff --git a/example/web/icons/Icon-512.png b/example/web/icons/Icon-512.png new file mode 100644 index 0000000..88cfd48 Binary files /dev/null and b/example/web/icons/Icon-512.png differ diff --git a/example/web/icons/Icon-maskable-192.png b/example/web/icons/Icon-maskable-192.png new file mode 100644 index 0000000..eb9b4d7 Binary files /dev/null and b/example/web/icons/Icon-maskable-192.png differ diff --git a/example/web/icons/Icon-maskable-512.png b/example/web/icons/Icon-maskable-512.png new file mode 100644 index 0000000..d69c566 Binary files /dev/null and b/example/web/icons/Icon-maskable-512.png differ diff --git a/example/web/index.html b/example/web/index.html new file mode 100644 index 0000000..2e1a2d4 --- /dev/null +++ b/example/web/index.html @@ -0,0 +1,102 @@ + + + + + + + + + + + + + + + + + flutter_media_metadata_example + + + + + + + + diff --git a/example/web/manifest.json b/example/web/manifest.json new file mode 100644 index 0000000..f9bf3aa --- /dev/null +++ b/example/web/manifest.json @@ -0,0 +1,35 @@ +{ + "name": "flutter_media_metadata_example", + "short_name": "flutter_media_metadata_example", + "start_url": ".", + "display": "standalone", + "background_color": "#0175C2", + "theme_color": "#0175C2", + "description": "Demonstrates how to use the flutter_media_metadata plugin.", + "orientation": "portrait-primary", + "prefer_related_applications": false, + "icons": [ + { + "src": "icons/Icon-192.png", + "sizes": "192x192", + "type": "image/png" + }, + { + "src": "icons/Icon-512.png", + "sizes": "512x512", + "type": "image/png" + }, + { + "src": "icons/Icon-maskable-192.png", + "sizes": "192x192", + "type": "image/png", + "purpose": "maskable" + }, + { + "src": "icons/Icon-maskable-512.png", + "sizes": "512x512", + "type": "image/png", + "purpose": "maskable" + } + ] +} diff --git a/example/windows/flutter/generated_plugin_registrant.cc b/example/windows/flutter/generated_plugin_registrant.cc index 08c09c5..e1222a2 100644 --- a/example/windows/flutter/generated_plugin_registrant.cc +++ b/example/windows/flutter/generated_plugin_registrant.cc @@ -2,6 +2,8 @@ // Generated file. Do not edit. // +// clang-format off + #include "generated_plugin_registrant.h" #include diff --git a/example/windows/flutter/generated_plugin_registrant.h b/example/windows/flutter/generated_plugin_registrant.h index 9846246..dc139d8 100644 --- a/example/windows/flutter/generated_plugin_registrant.h +++ b/example/windows/flutter/generated_plugin_registrant.h @@ -2,6 +2,8 @@ // Generated file. Do not edit. // +// clang-format off + #ifndef GENERATED_PLUGIN_REGISTRANT_ #define GENERATED_PLUGIN_REGISTRANT_ diff --git a/example/windows/runner/Runner.rc b/example/windows/runner/Runner.rc index 79ec295..12374cc 100644 --- a/example/windows/runner/Runner.rc +++ b/example/windows/runner/Runner.rc @@ -93,7 +93,7 @@ BEGIN VALUE "FileDescription", "Demonstrates how to use the flutter_media_metadata plugin." "\0" VALUE "FileVersion", VERSION_AS_STRING "\0" VALUE "InternalName", "flutter_media_metadata_example" "\0" - VALUE "LegalCopyright", "Copyright (C) 2021 com.alexmercerind. All rights reserved." "\0" + VALUE "LegalCopyright", "Copyright (C) 2021-2022 com.alexmercerind. All rights reserved." "\0" VALUE "OriginalFilename", "flutter_media_metadata_example.exe" "\0" VALUE "ProductName", "flutter_media_metadata_example" "\0" VALUE "ProductVersion", VERSION_AS_STRING "\0"