spotifyclient 0.0.8

  • Readme
  • Changelog
  • Example
  • Installing
  • 53

This Project is now migrated/renamed as spotify_auth_player #

0.0.7 #

  • TODO: Describe initial release.

example/lib/main.dart

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

import 'package:flutter/services.dart';
import 'package:spotifyclient/spotifyclient.dart';

void main() => runApp(MyApp());

class MyApp extends StatefulWidget {
  @override
  _MyAppState createState() => _MyAppState();

  
}

class _MyAppState extends State<MyApp> {
  Music _music;
 int totaldurationinmilli = 0;
  bool ispaused = false;
  @override
  void initState() {
    super.initState();

    initPlatformState();
  }

  Future<void> initPlatformState() async {
    await Spotifire.init(clientid: "Your client id");

    if (!mounted) return;

    Spotifire.musicStream.listen((music) {
      // print("Music" + music.runtimeType.toString());
      if (mounted)
        setState(() {
          totaldurationinmilli = music.duration.inMilliseconds;
         print(music.duration);
          _music = music;
        });
    }).onError((error) {
      print(error);
    });

  }

double val=0.01;
  @override
  Widget build(BuildContext context) {
    return MaterialApp(
      home: Scaffold(
        appBar: AppBar(
          backgroundColor: Colors.black87,
          title: const Text('Spotifire'),
        ),
        body: Stack(
          children: <Widget>[
            Container(
              height: 900,
              // width: MediaQuery.of(context).size.width,
              decoration: BoxDecoration(
                  gradient: LinearGradient(
                      begin: AlignmentDirectional.topStart,
                      end: AlignmentDirectional.bottomEnd,
                      colors: <Color>[
                    Color.fromRGBO(29, 185, 84, 1.0),
                    Color.fromRGBO(25, 20, 20, 1.0)
                  ])),
            ),
            ListView(
              padding: const EdgeInsets.all(12),
              children: <Widget>[
                Column(
                  children: <Widget>[
                    if (_music != null)
                      Material(
                          elevation: 7.0,
                          child: Image.memory(_music.musicImage)),
                    Text(_music != null ? _music.name : "Loding ... ",
                        style: Theme.of(context).textTheme.display1.copyWith(
                          color:Colors.white.withOpacity(0.95)
                        )),
                    Text(
                      _music != null ? _music.album : "Loding ... ",
                      style: Theme.of(context)
                          .textTheme
                          .headline
                          .copyWith(color: Colors.white70),
                    ),
                    Padding(
                      padding: const EdgeInsets.only(left: 228.0),
                      child: Text(_music != null
                          ? _music.duration.toString()
                          : "Loding ... ",style: TextStyle(
                            color:Colors.white54
                          ),),
                    ),
                    SizedBox(
                      height: 17,
                    ),
StreamBuilder<Duration>(
  stream: Spotifire.positonStream,
  initialData: Duration.zero,
  builder: (context, snapshot) {
   
           val = snapshot.hasData ?  _getValue(snapshot.data.inMilliseconds) : val;  
    
    if(!snapshot.hasData)
    Slider.adaptive(value: 0.0,onChanged: null,);

    return     Slider.adaptive(value: val, onChanged: (double cv)async{

   final int skd= (totaldurationinmilli * cv).floor() ;
   final Duration dur = Duration(milliseconds:skd);
   await   Spotifire.seekTo(seekDuration: dur, totalDuration: Duration(
        milliseconds: totaldurationinmilli
      ));

    });
  }
),

                    Row(
                      mainAxisAlignment: MainAxisAlignment.spaceEvenly,
                      children: <Widget>[
                        IconButton(
                            icon: Icon(Icons.skip_previous, size: 40,color: Colors.white70,),
                            onPressed: () async {
                              await Spotifire.skipPrevious;
                            }),
                        AnimatedCrossFade(
                            firstChild: IconButton(
                                icon: Icon(
                                  Icons.play_arrow
                                  ,color: Colors.white
,                                  size: 40,
                                ),
                                onPressed: () async {
                                  await Spotifire.resumeMusic.whenComplete(() {
                                    setState(() {
                                      ispaused = false;
                                    });
                                  });
                                }),
                            secondChild: IconButton(
                                icon: Icon(Icons.pause, size: 40,color: Colors.white),
                                onPressed: () async {
                                  await Spotifire.pauseMusic.whenComplete(() {
                                    setState(() {
                                      ispaused = true;
                                    });
                                  });
                                }),
                            crossFadeState: ispaused
                                ? CrossFadeState.showFirst
                                : CrossFadeState.showSecond,
                            duration: const Duration(milliseconds: 700)),
                        IconButton(
                            icon: Icon(Icons.skip_next, size: 40,color: Colors.white70),
                            onPressed: () async {
                              await Spotifire.skipNext;
                            }),
                      ],
                    )
                  ],
                )
              ],
            ),
          ],
        ),
        floatingActionButton: FloatingActionButton(
            child: Icon(
              Icons.playlist_play,
              size: 35,
            ),
            onPressed: () async {
              await Spotifire.getAccessToken.then(print);

              await Spotifire.connectRemote
                  .then(print)
                  .whenComplete(() => print("compl"));
              try {
                if (await Spotifire.isRemoteConnected)
                  await Spotifire.playPlaylist(
                      playlistUri: "spotify:playlist:37i9dQZF1DX3rxVfibe1L0");
              } catch (e) {
                print(e);
              }
            }),
      ),
    );
  }

double  _getValue(int milliseconds){
        double percentage = (milliseconds/totaldurationinmilli) *100;

        print(percentage.toString() + " % ");

        double tpo = (percentage / 100) * 1.0;
    return tpo;
}

  @override
  void dispose() {
    Spotifire.close();

    super.dispose();
  }
}

Use this package as a library

1. Depend on it

Add this to your package's pubspec.yaml file:


dependencies:
  spotifyclient: ^0.0.8

2. Install it

You can install packages from the command line:

with Flutter:


$ flutter pub get

Alternatively, your editor might support flutter pub get. Check the docs for your editor to learn more.

3. Import it

Now in your Dart code, you can use:


import 'package:spotifyclient/spotifyclient.dart';
  
Popularity:
Describes how popular the package is relative to other packages. [more]
11
Health:
Code health derived from static analysis. [more]
100
Maintenance:
Reflects how tidy and up-to-date the package is. [more]
90
Overall:
Weighted score of the above. [more]
53
Learn more about scoring.

We analyzed this package on Jul 10, 2020, and provided a score, details, and suggestions below. Analysis was completed with status completed using:

  • Dart: 2.8.4
  • pana: 0.13.14
  • Flutter: 1.17.5

Analysis suggestions

Package does not support Flutter platform linux

Because:

  • package:spotifyclient/spotifyclient.dart that declares support for platforms: android, ios

Package does not support Flutter platform macos

Because:

  • package:spotifyclient/spotifyclient.dart that declares support for platforms: android, ios

Package does not support Flutter platform web

Because:

  • package:spotifyclient/spotifyclient.dart that declares support for platforms: android, ios

Package does not support Flutter platform windows

Because:

  • package:spotifyclient/spotifyclient.dart that declares support for platforms: android, ios

Package not compatible with SDK dart

Because:

  • spotifyclient that is a package requiring null.

Health issues and suggestions

Document public APIs. (-0.32 points)

42 out of 43 API elements have no dartdoc comment.Providing good documentation for libraries, classes, functions, and other API elements improves code readability and helps developers find and use your API.

Format lib/spotifyclient.dart.

Run flutter format to format lib/spotifyclient.dart.

Maintenance suggestions

Package is pre-v0.1 release. (-10 points)

While nothing is inherently wrong with versions of 0.0.*, it might mean that the author is still experimenting with the general direction of the API.

Dependencies

Package Constraint Resolved Available
Direct dependencies
Dart SDK >=2.1.0 <3.0.0
flutter 0.0.0
Transitive dependencies
collection 1.14.12 1.14.13
meta 1.1.8 1.2.2
sky_engine 0.0.99
typed_data 1.1.6 1.2.0
vector_math 2.0.8 2.1.0-nullsafety
Dev dependencies
flutter_test