📜  package:mp3 player play pause button.dart (1)

📅  最后修改于: 2023-12-03 15:03:27.630000             🧑  作者: Mango

Package: MP3 Player Play Pause Button

The mp3_player_play_pause_button package is a simple Flutter package that provides a customizable play and pause button for an MP3 player.

Usage

To use this package, add mp3_player_play_pause_button as a dependency in your pubspec.yaml file.

Then, simply import the package and use the MP3PlayerPlayPauseButton widget as follows:

import 'package:mp3_player_play_pause_button/mp3_player_play_pause_button.dart';

MP3PlayerPlayPauseButton(
  onPressed: () {
    // Do something when the button is pressed
  },
  isPlaying: true, // true if the MP3 is currently playing, false otherwise
  color: Colors.blue, // the color of the button
  backgroundColor: Colors.black, // the background color of the button
  duration: Duration(seconds: 1), // the duration of the button animation
);
Properties

The MP3PlayerPlayPauseButton widget has the following properties:

  • onPressed: The function to call when the button is pressed.
  • isPlaying: A boolean indicating whether the MP3 is currently playing or not (default is false).
  • color: The color of the button (default is Colors.black).
  • backgroundColor: The background color of the button (default is Colors.white).
  • duration: The duration of the button animation (default is Duration(milliseconds: 500)).
Example

Here is an example of how to use the MP3PlayerPlayPauseButton widget:

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

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

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

class _MyAppState extends State<MyApp> {
  bool _isPlaying = false;

  void _togglePlayPause() {
    setState(() {
      _isPlaying = !_isPlaying;
    });
  }

  @override
  Widget build(BuildContext context) {
    return MaterialApp(
      home: Scaffold(
        appBar: AppBar(
          title: Text('MP3 Player Play Pause Button'),
        ),
        body: Center(
          child: MP3PlayerPlayPauseButton(
            onPressed: _togglePlayPause,
            isPlaying: _isPlaying,
            color: Colors.blue,
            backgroundColor: Colors.black,
            duration: Duration(milliseconds: 500),
          ),
        ),
      ),
    );
  }
}

In this example, a Scaffold is created with an AppBar and a Center widget that contains a MP3PlayerPlayPauseButton. The isPlaying property is set to _isPlaying, which toggles between false and true whenever the button is pressed.