2020-12-13 12:37:08 +01:00
|
|
|
import 'dart:math';
|
|
|
|
|
2020-03-20 16:17:02 +01:00
|
|
|
import 'package:flutter/material.dart';
|
2020-04-11 20:23:02 +02:00
|
|
|
import 'package:flutter_mobx/flutter_mobx.dart';
|
|
|
|
import 'package:provider/provider.dart';
|
2020-03-20 16:17:02 +01:00
|
|
|
|
2020-04-11 20:23:02 +02:00
|
|
|
import '../state/audio_store.dart';
|
|
|
|
import '../utils.dart';
|
2020-03-20 16:17:02 +01:00
|
|
|
|
2020-04-11 20:23:02 +02:00
|
|
|
class TimeProgressIndicator extends StatelessWidget {
|
|
|
|
const TimeProgressIndicator({Key key}) : super(key: key);
|
2020-03-20 16:17:02 +01:00
|
|
|
|
|
|
|
@override
|
|
|
|
Widget build(BuildContext context) {
|
2020-04-11 20:23:02 +02:00
|
|
|
final AudioStore audioStore = Provider.of<AudioStore>(context);
|
|
|
|
|
|
|
|
return Observer(
|
|
|
|
builder: (BuildContext context) {
|
2020-11-15 16:36:50 +01:00
|
|
|
final int duration = audioStore.currentSong?.duration ?? 1000;
|
2020-08-24 12:01:01 +02:00
|
|
|
|
2020-12-10 20:55:37 +01:00
|
|
|
return Row(
|
|
|
|
children: [
|
|
|
|
Container(
|
|
|
|
width: 48,
|
|
|
|
child: Text(
|
|
|
|
msToTimeString(audioStore.currentPositionStream.value),
|
2020-04-11 20:23:02 +02:00
|
|
|
),
|
2020-12-10 20:55:37 +01:00
|
|
|
),
|
|
|
|
Expanded(
|
|
|
|
child: Container(
|
|
|
|
width: double.infinity,
|
|
|
|
height: 3.0,
|
|
|
|
decoration: const BoxDecoration(
|
|
|
|
color: Colors.white10,
|
|
|
|
borderRadius: BorderRadius.all(Radius.circular(2)),
|
|
|
|
),
|
|
|
|
alignment: Alignment.centerLeft,
|
|
|
|
child: FractionallySizedBox(
|
2020-12-13 12:37:08 +01:00
|
|
|
widthFactor: min(
|
|
|
|
audioStore.currentPositionStream.value / duration, 1.0),
|
2020-12-10 20:55:37 +01:00
|
|
|
heightFactor: 1.0,
|
|
|
|
child: Container(
|
|
|
|
height: double.infinity,
|
|
|
|
decoration: const BoxDecoration(
|
|
|
|
color: Colors.white,
|
|
|
|
borderRadius: BorderRadius.all(Radius.circular(2)),
|
|
|
|
),
|
|
|
|
),
|
2020-04-11 20:23:02 +02:00
|
|
|
),
|
|
|
|
),
|
2020-12-10 20:55:37 +01:00
|
|
|
),
|
|
|
|
Container(
|
|
|
|
width: 48,
|
|
|
|
alignment: Alignment.centerRight,
|
|
|
|
child: Text(msToTimeString(duration)),
|
|
|
|
),
|
|
|
|
],
|
|
|
|
mainAxisAlignment: MainAxisAlignment.spaceEvenly,
|
2020-04-11 20:23:02 +02:00
|
|
|
);
|
|
|
|
},
|
2020-03-20 16:17:02 +01:00
|
|
|
);
|
|
|
|
}
|
|
|
|
}
|