You cannot select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
112 lines
3.1 KiB
Dart
112 lines
3.1 KiB
Dart
import 'package:flutter/material.dart';
|
|
import 'package:hmg_patient_app_new/core/utils/size_utils.dart';
|
|
import 'package:hmg_patient_app_new/extensions/string_extensions.dart';
|
|
|
|
Widget buildTime(Duration duration, {bool isHomePage = false}) {
|
|
String twoDigits(int n) => n.toString().padLeft(2, '0');
|
|
final hours = twoDigits(duration.inHours);
|
|
final minutes = twoDigits(duration.inMinutes.remainder(60));
|
|
final seconds = twoDigits(duration.inSeconds.remainder(60));
|
|
|
|
return Row(
|
|
mainAxisAlignment: MainAxisAlignment.center,
|
|
children: [
|
|
buildTimeColumn(hours, "Hours".needTranslation),
|
|
buildTimeColumn(minutes, "Mins".needTranslation),
|
|
buildTimeColumn(seconds, "Secs".needTranslation, isLast: true),
|
|
],
|
|
);
|
|
}
|
|
|
|
Widget buildTimeColumn(String time, String label, {bool isLast = false}) {
|
|
return Column(
|
|
mainAxisAlignment: MainAxisAlignment.center,
|
|
children: [
|
|
Row(
|
|
children: [
|
|
buildDigit(time[0]),
|
|
buildDigit(time[1]),
|
|
if (!isLast) buildTimeSeparator(),
|
|
],
|
|
),
|
|
buildLabel(label),
|
|
],
|
|
);
|
|
}
|
|
|
|
Widget buildDigit(String digit) {
|
|
return Container(
|
|
padding: const EdgeInsets.symmetric(horizontal: 10, vertical: 4),
|
|
// margin: const EdgeInsets.symmetric(horizontal: 2),
|
|
decoration: BoxDecoration(
|
|
color: Colors.white,
|
|
borderRadius: BorderRadius.circular(8),
|
|
),
|
|
child: ClipRect(
|
|
child: AnimatedSwitcher(
|
|
duration: const Duration(milliseconds: 600),
|
|
switchInCurve: Curves.easeOutExpo,
|
|
switchOutCurve: Curves.easeInExpo,
|
|
transitionBuilder: (Widget child, Animation<double> animation) {
|
|
return Stack(
|
|
children: <Widget>[
|
|
SlideTransition(
|
|
position: Tween<Offset>(
|
|
begin: const Offset(0, -1),
|
|
end: const Offset(0, 1),
|
|
).animate(CurvedAnimation(
|
|
parent: animation,
|
|
curve: Curves.easeOutCubic,
|
|
)),
|
|
child: FadeTransition(
|
|
opacity: animation,
|
|
child: child,
|
|
),
|
|
),
|
|
SlideTransition(
|
|
position: Tween<Offset>(
|
|
begin: const Offset(0, -1),
|
|
end: const Offset(0, 0),
|
|
).animate(CurvedAnimation(
|
|
parent: animation,
|
|
curve: Curves.bounceIn,
|
|
)),
|
|
child: FadeTransition(
|
|
opacity: animation,
|
|
child: child,
|
|
),
|
|
),
|
|
],
|
|
);
|
|
},
|
|
child: Text(
|
|
digit,
|
|
key: ValueKey<String>(digit),
|
|
style: TextStyle(
|
|
fontWeight: FontWeight.bold,
|
|
color: Colors.black,
|
|
fontSize: 14.f,
|
|
),
|
|
),
|
|
),
|
|
),
|
|
);
|
|
}
|
|
|
|
Widget buildLabel(String label) {
|
|
return label.toText12(isBold: true);
|
|
}
|
|
|
|
Widget buildTimeSeparator() {
|
|
return const Padding(
|
|
padding: EdgeInsets.symmetric(horizontal: 2.0),
|
|
child: Text(
|
|
":",
|
|
style: TextStyle(
|
|
color: Colors.black,
|
|
fontSize: 20,
|
|
),
|
|
),
|
|
);
|
|
}
|