common.dart 3.8 KB

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