amseekbar 0.1.2 amseekbar: ^0.1.2 copied to clipboard
A seekbar for audio/video players. It shows the current time and the duration time directly in the seeker.
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();
}
},
),
),
);
}
}