amseekbar 0.1.2

seekbar #

A seekbar for audio/video player with current time and duration time display

Based on this project

alt text

Getting Started #

class TestSeekBarPage extends StatefulWidget {
  @override
  _TestSeekBarPageState createState() {
    return _TestSeekBarPageState();
  }
}

class _TestSeekBarPageState extends State<TestSeekBarPage> {
  double _value = 0.0;
  double _totalTime = 1 * 3600 + 48.0 * 60 + 23;

  Timer _progressTimer;

  bool _done = false;

  @override
  void initState() {
    _resumeProgressTimer();
    super.initState();
  }

  _resumeProgressTimer() {
    _progressTimer = Timer.periodic(const Duration(milliseconds: 1000), (_) {
      setState(() {
        _value += 1;

        if (_value >= _totalTime) {
          _value = _totalTime;
          _progressTimer.cancel();
          _done = true;
        }
      });
    });
  }

  @override
  void dispose() {
    _progressTimer?.cancel();
    super.dispose();
  }

  @override
  Widget build(BuildContext context) {
    return Scaffold(
      body: Container(
        padding: EdgeInsets.symmetric(horizontal: 5),
        alignment: Alignment.center,
        color: Colors.black87,
        child: SeekBar(
          currentTime: _value,
          durationTime: _totalTime,
          onStartTrackingTouch: () {
            if (!_done) {
              _progressTimer?.cancel();
            }
          },
          onProgressChanged: (value) {
            _value = value * _totalTime;
          },
          onStopTrackingTouch: () {
            if (!_done) {
              _resumeProgressTimer();
            }
          },
        ),
      ),
    );
  }
}

[0.0.1] - Initial version.

  • Working version

[0.1.0] - Release v0.1

  • Includes example

[0.1.1] - Bug fix

  • Progress update fix when clicking

[0.1.2] - Bug fix

  • Do not take into account the changes of currentTime when drag is in progress

example/main.dart

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

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

class MyApp extends StatelessWidget {
  // This widget is the root of your application.
  @override
  Widget build(BuildContext context) {
    return MaterialApp(
      title: 'Flutter Demo',
      theme: ThemeData(
        // This is the theme of your application.
        //
        // Try running your application with "flutter run". You'll see the
        // application has a blue toolbar. Then, without quitting the app, try
        // changing the primarySwatch below to Colors.green and then invoke
        // "hot reload" (press "r" in the console where you ran "flutter run",
        // or simply save your changes to "hot reload" in a Flutter IDE).
        // Notice that the counter didn't reset back to zero; the application
        // is not restarted.
        primarySwatch: Colors.blue,
      ),
      home: TestSeekBarPage(),
    );
  }
}

class TestSeekBarPage extends StatefulWidget {
  @override
  _TestSeekBarPageState createState() {
    return _TestSeekBarPageState();
  }
}

class _TestSeekBarPageState extends State<TestSeekBarPage> {
  double _value = 0.0;
  double _totalTime = 1 * 3600 + 48.0 * 60 + 23;

  Timer _progressTimer;

  bool _done = false;

  @override
  void initState() {
    _resumeProgressTimer();
    super.initState();
  }

  _resumeProgressTimer() {
    _progressTimer = Timer.periodic(const Duration(milliseconds: 1000), (_) {
      setState(() {
        _value += 1;

        if (_value >= _totalTime) {
          _value = _totalTime;
          _progressTimer.cancel();
          _done = true;
        }
      });
    });
  }

  @override
  void dispose() {
    _progressTimer?.cancel();
    super.dispose();
  }

  @override
  Widget build(BuildContext context) {
    return Scaffold(
      body: Container(
        padding: EdgeInsets.symmetric(horizontal: 5),
        alignment: Alignment.center,
        color: Colors.black87,
        child: SeekBar(
          currentTime: _value,
          durationTime: _totalTime,
          onStartTrackingTouch: () {
            if (!_done) {
              _progressTimer?.cancel();
            }
          },
          onProgressChanged: (value) {
            _value = value * _totalTime;
          },
          onStopTrackingTouch: () {
            if (!_done) {
              _resumeProgressTimer();
            }
          },
        ),
      ),
    );
  }
}

Use this package as a library

1. Depend on it

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


dependencies:
  amseekbar: ^0.1.2

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:amseekbar/amseekbar.dart';
  
Popularity:
Describes how popular the package is relative to other packages. [more]
28
Health:
Code health derived from static analysis. [more]
100
Maintenance:
Reflects how tidy and up-to-date the package is. [more]
100
Overall:
Weighted score of the above. [more]
64
Learn more about scoring.

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

  • Dart: 2.7.1
  • pana: 0.13.5
  • Flutter: 1.12.13+hotfix.7

Health suggestions

Format lib/amseekbar.dart.

Run flutter format to format lib/amseekbar.dart.

Dependencies

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