frosty/lib/widgets/uptime.dart
Tommy Chow 9570d43e43
Add auto PiP on Android and redesign stream overlay (#218)
* Improve PiP behavior (Android)
Added the ability to enter PiP mode when leaving the app on Android.

* Add automatic PiP option

* Redesign video overlay

* Update stream card uptime counter

* Use gradient for overlay opacity

* Restore play button when paused on iOS

* Restore refresh button on overlay

* Prefer above for category tooltip

* Increase default overlay opacity to 80%

* Improve pip behavior

* Fix uptime setState after dispose

* Remove automatic pip option
Redundant since you can disable it in system settings

* Check if `setAutoEnterEnabled` is available

* Fix missing pip auto enter

* Disable auto pip when leaving channel

* Fix pip exception on iOS
2022-12-27 23:47:55 -05:00

44 lines
1,009 B
Dart

import 'dart:async';
import 'dart:ui';
import 'package:flutter/material.dart';
/// A widget that displays a timer representing the time since the given start time.
/// The timer is updated every second.
class Uptime extends StatefulWidget {
final String startTime;
final TextStyle? style;
const Uptime({
Key? key,
required this.startTime,
this.style,
}) : super(key: key);
@override
State<Uptime> createState() => _UptimeState();
}
class _UptimeState extends State<Uptime> {
Timer? _timer;
@override
void initState() {
super.initState();
_timer = Timer.periodic(const Duration(seconds: 1), (timer) => setState(() {}));
}
@override
Widget build(BuildContext context) {
return Text(
DateTime.now().difference(DateTime.parse(widget.startTime)).toString().split('.')[0],
style: widget.style?.copyWith(fontFeatures: [const FontFeature.tabularFigures()]),
);
}
@override
void dispose() {
_timer?.cancel();
super.dispose();
}
}