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