common.dart 3.9 KB

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