common.dart 3.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138
  1. import 'package:common_pub/common_pub.dart';
  2. import 'package:flutter/material.dart';
  3. import 'package:get/get.dart';
  4. import 'package:track_offical/generated/assets.dart';
  5. class AppTopBar extends StatelessWidget implements PreferredSizeWidget {
  6. const AppTopBar(
  7. {super.key,
  8. required this.title,
  9. required this.hasBackText,
  10. required this.height});
  11. final double height;
  12. final String title;
  13. final bool hasBackText;
  14. Widget bkText(
  15. String text,
  16. double fontSizeRpx,
  17. double alpha,
  18. BuildContext context,
  19. double xP,
  20. double yP,
  21. ) {
  22. return Positioned(
  23. left: context.width * xP,
  24. top: height * yP,
  25. child: Text(text,
  26. style: TextStyle(
  27. color: const Color(0xFFade0ff).withAlpha((alpha * 255).round()),
  28. fontWeight: FontWeight.w500,
  29. fontSize: context.wp(fontSizeRpx),
  30. )));
  31. }
  32. @override
  33. Widget build(BuildContext context) {
  34. final children = <Widget>[];
  35. if (hasBackText) {
  36. children.addAll([
  37. bkText('Orienting', 47.92, 0.6, context, 0.1, 0.2),
  38. bkText('定目标', 37.5, 0.58, context, 0.7, 0.18),
  39. bkText('Targeting', 56.25, 0.2, context, 0.52, 0.26),
  40. bkText('定向', 54.17, 0.6, context, 0.3, 0.33),
  41. bkText('定位', 31.25, 0.5, context, 0.08, 0.4),
  42. bkText('Locating', 45.83, 0.4, context, 0.12, 0.52),
  43. bkText('到达目标', 37.5, 0.5, context, 0.53, 0.48),
  44. bkText('Reaching', 33.33, 0.5, context, 0.6, 0.6),
  45. ]);
  46. }
  47. children.add(Positioned(
  48. left: context.wp(54.17),
  49. bottom: context.wp(58.33),
  50. child: Text(title,
  51. style: TextStyle(
  52. color: Colors.white,
  53. fontSize: context.wp(58.33),
  54. fontWeight: FontWeight.w400,
  55. ))));
  56. return Container(
  57. width: double.infinity,
  58. height: height,
  59. decoration: const BoxDecoration(
  60. image: DecorationImage(
  61. image: AssetImage(Assets.imagesBkLogin),
  62. alignment: Alignment.topCenter,
  63. fit: BoxFit.fitWidth)),
  64. child: Stack(
  65. children: children,
  66. ),
  67. );
  68. }
  69. @override
  70. Size get preferredSize => Size.fromHeight(height);
  71. }
  72. Widget button(BuildContext context ,String text, VoidCallback onPressed) {
  73. return SizedBox(
  74. width: double.infinity,
  75. height: context.wp(3.19),
  76. child: FilledButton(
  77. style: FilledButton.styleFrom(
  78. backgroundColor: const Color(0xffffb40b),
  79. shape: RoundedRectangleBorder(borderRadius: BorderRadius.circular(context.wp(0.42)))
  80. ),
  81. onPressed: onPressed,
  82. child: Text(
  83. text,
  84. style: const TextStyle(color: Colors.black, fontSize: 15),
  85. )));
  86. }
  87. class TextDecoration extends InputDecoration {
  88. const TextDecoration({required String hintText})
  89. : super(
  90. hintText: hintText,
  91. border: const OutlineInputBorder(),
  92. isDense: true,
  93. );
  94. }
  95. class GetCodeButton extends StatelessWidget {
  96. final Duration codeRetryLeft;
  97. final VoidCallback onPressed;
  98. const GetCodeButton(
  99. { super.key,
  100. required this.codeRetryLeft,
  101. required this.onPressed});
  102. @override
  103. Widget build(BuildContext context) {
  104. final isEnable = codeRetryLeft.inSeconds <= 0;
  105. final onPressed = isEnable ?
  106. this.onPressed
  107. : () {};
  108. final bkColor = isEnable? const Color(0xffefefef): const Color(0xffc2c2c2);
  109. final foregroundColor = isEnable? Colors.black: Colors.white;
  110. final text = isEnable ? '获取验证码' : '请稍后(${codeRetryLeft
  111. .inSeconds})';
  112. return ElevatedButton(
  113. onPressed: onPressed,
  114. style: ElevatedButton.styleFrom(
  115. backgroundColor: bkColor,
  116. shape: RoundedRectangleBorder(
  117. borderRadius: BorderRadius.circular(2.0)),
  118. foregroundColor: foregroundColor,
  119. padding: EdgeInsets.zero),
  120. child: Text(text));
  121. }
  122. }