92 lines
2.2 KiB
Dart
92 lines
2.2 KiB
Dart
import 'dart:async';
|
|
|
|
import 'package:flutter/material.dart';
|
|
|
|
class BackwardSeekIndicator extends StatefulWidget {
|
|
final void Function(Duration) onChanged;
|
|
final void Function(Duration) onSubmitted;
|
|
const BackwardSeekIndicator({
|
|
Key? key,
|
|
required this.onChanged,
|
|
required this.onSubmitted,
|
|
}) : super(key: key);
|
|
|
|
@override
|
|
State<BackwardSeekIndicator> createState() => BackwardSeekIndicatorState();
|
|
}
|
|
|
|
class BackwardSeekIndicatorState extends State<BackwardSeekIndicator> {
|
|
Duration value = const Duration(seconds: 10);
|
|
|
|
Timer? timer;
|
|
|
|
@override
|
|
void setState(VoidCallback fn) {
|
|
if (mounted) {
|
|
super.setState(fn);
|
|
}
|
|
}
|
|
|
|
@override
|
|
void initState() {
|
|
super.initState();
|
|
timer = Timer(const Duration(milliseconds: 200), () {
|
|
widget.onSubmitted.call(value);
|
|
});
|
|
}
|
|
|
|
void increment() {
|
|
timer?.cancel();
|
|
timer = Timer(const Duration(milliseconds: 200), () {
|
|
widget.onSubmitted.call(value);
|
|
});
|
|
widget.onChanged.call(value);
|
|
// 重复点击 快退秒数累加10
|
|
setState(() {
|
|
value += const Duration(seconds: 10);
|
|
});
|
|
}
|
|
|
|
@override
|
|
Widget build(BuildContext context) {
|
|
return Container(
|
|
decoration: const BoxDecoration(
|
|
gradient: LinearGradient(
|
|
colors: [
|
|
Color(0x88767676),
|
|
Color(0x00767676),
|
|
],
|
|
begin: Alignment.centerLeft,
|
|
end: Alignment.centerRight,
|
|
),
|
|
),
|
|
child: InkWell(
|
|
splashColor: const Color(0x44767676),
|
|
onTap: increment,
|
|
child: Center(
|
|
child: Column(
|
|
mainAxisSize: MainAxisSize.min,
|
|
mainAxisAlignment: MainAxisAlignment.center,
|
|
crossAxisAlignment: CrossAxisAlignment.center,
|
|
children: [
|
|
const Icon(
|
|
Icons.fast_rewind,
|
|
size: 24.0,
|
|
color: Color(0xFFFFFFFF),
|
|
),
|
|
const SizedBox(height: 8.0),
|
|
Text(
|
|
'快退${value.inSeconds}秒',
|
|
style: const TextStyle(
|
|
fontSize: 12.0,
|
|
color: Color(0xFFFFFFFF),
|
|
),
|
|
),
|
|
],
|
|
),
|
|
),
|
|
),
|
|
);
|
|
}
|
|
}
|