mirror of
https://github.com/foss42/apidash.git
synced 2025-08-06 05:32:26 +08:00
Merge pull request #334 from Yousef-Rabia/elapsed-time-by-request
Elapsed time by request
This commit is contained in:
@ -1,3 +1,4 @@
|
||||
import 'dart:async';
|
||||
import 'package:flutter/foundation.dart';
|
||||
import 'package:flutter/material.dart';
|
||||
import 'package:http_parser/http_parser.dart';
|
||||
@ -33,18 +34,80 @@ class NotSentWidget extends StatelessWidget {
|
||||
}
|
||||
}
|
||||
|
||||
class SendingWidget extends StatelessWidget {
|
||||
const SendingWidget({super.key});
|
||||
class SendingWidget extends StatefulWidget {
|
||||
final DateTime? startSendingTime;
|
||||
const SendingWidget({
|
||||
super.key,
|
||||
required this.startSendingTime,
|
||||
});
|
||||
|
||||
@override
|
||||
State<SendingWidget> createState() => _SendingWidgetState();
|
||||
}
|
||||
|
||||
class _SendingWidgetState extends State<SendingWidget> {
|
||||
int _millisecondsElapsed = 0;
|
||||
Timer? _timer;
|
||||
|
||||
@override
|
||||
void initState() {
|
||||
super.initState();
|
||||
if (widget.startSendingTime != null) {
|
||||
_millisecondsElapsed =
|
||||
(DateTime.now().difference(widget.startSendingTime!).inMilliseconds ~/
|
||||
100) *
|
||||
100;
|
||||
_timer = Timer.periodic(const Duration(milliseconds: 100), _updateTimer);
|
||||
}
|
||||
}
|
||||
|
||||
void _updateTimer(Timer timer) {
|
||||
setState(() {
|
||||
_millisecondsElapsed += 100;
|
||||
});
|
||||
}
|
||||
|
||||
@override
|
||||
void dispose() {
|
||||
if (_timer != null && _timer!.isActive) _timer?.cancel();
|
||||
super.dispose();
|
||||
}
|
||||
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
return Center(
|
||||
child: Column(
|
||||
mainAxisAlignment: MainAxisAlignment.center,
|
||||
children: [
|
||||
Lottie.asset(kAssetSendingLottie),
|
||||
],
|
||||
),
|
||||
return Stack(
|
||||
children: [
|
||||
Center(
|
||||
child: Lottie.asset(kAssetSendingLottie),
|
||||
),
|
||||
Padding(
|
||||
padding: kPh20t40,
|
||||
child: Visibility(
|
||||
visible: _millisecondsElapsed >= 0,
|
||||
child: Row(
|
||||
mainAxisAlignment: MainAxisAlignment.center,
|
||||
children: [
|
||||
Icon(
|
||||
Icons.alarm,
|
||||
color: Theme.of(context).colorScheme.onSurfaceVariant,
|
||||
),
|
||||
const SizedBox(
|
||||
width: 10,
|
||||
),
|
||||
Text(
|
||||
'Time elapsed: ${humanizeDuration(Duration(milliseconds: _millisecondsElapsed))}',
|
||||
textAlign: TextAlign.center,
|
||||
overflow: TextOverflow.fade,
|
||||
softWrap: false,
|
||||
style: kTextStyleButton.copyWith(
|
||||
color: Theme.of(context).colorScheme.onSurfaceVariant,
|
||||
),
|
||||
),
|
||||
],
|
||||
),
|
||||
),
|
||||
),
|
||||
],
|
||||
);
|
||||
}
|
||||
}
|
||||
|
Reference in New Issue
Block a user