Flutter task 1 Music Player App

Simran Lodhi
3 min readOct 28, 2020

Flutter is an open-source mobile SDK developer can use to build native-looking Android and iOS applications from the same code base. Flutter is a cross-platform development tool. That means software developers can use the same code base for building an iOS and Android app.

In this blog ,you will learn how to implement a music player into your flutter app, play from assets file.

I have created main.dart and in UI folder I have created home.dart.In home.dart I have imported the file :

import ‘package:audioplayers/audioplayers.dart’;

import ‘package:audioplayers/audio_cache.dart’;

These packages comes from the dependency called audioplayers: ^0.15.1

We can install these dependencies from pub.dev in pubspec.yaml file.

We have to create a assets folder. An asset is a file that is bundled and deployed with your app, and is accessible at runtime. Flutter uses the pubspec.yaml file, to identify assets required by an app for this we have to create assets folder in our app and provide the the location of asset folder in pubspec.yaml file.

Lets come to the coding part of main.dart. I use statelesswidget for this. A stateless widget is a widget that describes part of the user interface by building a constellation of other widgets that describe the user interface more concretely.

This is the main.dart file.

You can access home.dart file from Github link which I wrote at the end of the blog.

After running the code the home screen look like

In home screen I provided three button:

  1. Play: It play the audio when we click on play button.
  2. pause: It pause the audio when we click on pause button.
  3. stop: It will stop the audio when we click on stop button.

The video of the music player app is:

The github link of the code is:

THANK YOU

--

--