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';
|
2021-05-10 19:19:54 +02:00
|
|
|
import 'package:get_it/get_it.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 {
|
2021-06-20 13:49:21 +02:00
|
|
|
const TimeProgressIndicator({Key? key}) : super(key: key);
|
2020-03-20 16:17:02 +01:00
|
|
|
|
|
|
|
@override
|
|
|
|
Widget build(BuildContext context) {
|
2021-05-10 19:19:54 +02:00
|
|
|
final AudioStore audioStore = GetIt.I<AudioStore>();
|
2020-04-11 20:23:02 +02:00
|
|
|
|
|
|
|
return Observer(
|
|
|
|
builder: (BuildContext context) {
|
2021-02-26 22:07:18 +01:00
|
|
|
final duration =
|
|
|
|
Duration(milliseconds: audioStore.currentSongStream.value?.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(
|
2021-06-20 13:49:21 +02:00
|
|
|
msToTimeString(
|
|
|
|
audioStore.currentPositionStream.value ?? const Duration(seconds: 0),
|
|
|
|
),
|
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(
|
2021-06-20 13:49:21 +02:00
|
|
|
(audioStore.currentPositionStream.value?.inMilliseconds ?? 0) /
|
|
|
|
duration.inMilliseconds,
|
2021-02-26 22:07:18 +01:00
|
|
|
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
|
|
|
);
|
|
|
|
}
|
|
|
|
}
|