on_audio_query 2.1.0 copy "on_audio_query: ^2.1.0" to clipboard
on_audio_query: ^2.1.0 copied to clipboard

outdated

Flutter Plugin used to query audios/songs infos [title, artist, album, etc..] from device storage.

example/lib/main.dart

/*
=============
Author: Lucas Josino
Github: https://github.com/LucasPJS
Website: https://lucasjosino.com/
=============
Plugin/Id: on_audio_query#0
Homepage: https://github.com/LucasPJS/on_audio_query
Pub: https://pub.dev/packages/on_audio_query
License: https://github.com/LucasPJS/on_audio_query/blob/main/LICENSE
Copyright: © 2021, Lucas Josino. All rights reserved.
=============
*/

import 'package:flutter/material.dart';
import 'package:on_audio_query/on_audio_query.dart';

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

class Songs extends StatefulWidget {
  @override
  _SongsState createState() => _SongsState();
}

class _SongsState extends State<Songs> {
  OnAudioQuery audioQuery = OnAudioQuery();

  // @override
  // void initState() {
  //   super.initState();
  //   requestPermission();
  // }

  // requestPermission() async {
  //   bool permissionStatus = await audioQuery.permissionsStatus();
  //   if (!permissionStatus) {
  //     await audioQuery.permissionsRequest();
  //   }
  //   setState(() {});
  // }

  @override
  Widget build(BuildContext context) {
    return MaterialApp(
      home: Scaffold(
        appBar: AppBar(
          title: Text("OnAudioQueryExample"),
          elevation: 2,
        ),
        body: FutureBuilder<List<SongModel>>(
          future: OnAudioQuery().querySongs(
            sortType: SongSortType.DEFAULT,
            orderType: OrderType.ASC_OR_SMALLER,
            uriType: UriType.EXTERNAL,
          ),
          builder: (context, item) {
            if (item.data == null) return CircularProgressIndicator();

            // When you try "query" without asking for [READ] or [Library] permission
            // the plugin will return a [Empty] list.
            if (item.data!.isEmpty) return Text("Nothing found!");

            // You can use [item.data!] direct or you can create a:
            // List<SongModel> songs = item.data!;
            return ListView.builder(
              itemCount: item.data!.length,
              itemBuilder: (context, index) {
                return ListTile(
                  title: Text(item.data![index].title),
                  subtitle: Text(item.data![index].artist ?? "No Artist"),
                  trailing: Icon(Icons.arrow_forward_rounded),
                  // This Widget will query/load image. Just add the id and type.
                  // You can use/create your own widget/method using [queryArtwork].
                  leading: QueryArtworkWidget(
                    id: item.data![index].id,
                    type: ArtworkType.AUDIO,
                  ),
                );
              },
            );
          },
        ),
      ),
    );
  }
}
177
likes
0
points
1.61k
downloads

Publisher

verified publisherlucasjosino.com

Weekly Downloads

Flutter Plugin used to query audios/songs infos [title, artist, album, etc..] from device storage.

Repository (GitHub)
View/report issues

License

unknown (license)

Dependencies

flutter, on_audio_query_platform_interface, on_audio_query_web

More

Packages that depend on on_audio_query