common.dart 3.9 KB

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