view.dart 4.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137
  1. import 'package:electronic_assistant/base/base_page.dart';
  2. import 'package:electronic_assistant/resource/assets.gen.dart';
  3. import 'package:electronic_assistant/resource/colors.gen.dart';
  4. import 'package:electronic_assistant/resource/string.gen.dart';
  5. import 'package:electronic_assistant/utils/expand.dart';
  6. import 'package:flutter/material.dart';
  7. import 'package:flutter_screenutil/flutter_screenutil.dart';
  8. import 'package:get/get.dart';
  9. import 'controller.dart';
  10. class HomePage extends BasePage<HomePageController> {
  11. const HomePage({super.key});
  12. @override
  13. Widget? buildBody(BuildContext context) {
  14. return Stack(
  15. children: [
  16. buildBgBox(),
  17. buildTopGradient(),
  18. SafeArea(
  19. child: Column(
  20. children: [
  21. Container(
  22. width: 1.sw,
  23. padding: const EdgeInsets.all(12).w,
  24. child: buildOperationBar(),
  25. ),
  26. Expanded(
  27. child: CustomScrollView(
  28. slivers: [
  29. SliverToBoxAdapter(
  30. child: Container(
  31. padding: EdgeInsets.all(16),
  32. color: Colors.blue,
  33. child: Text('头部', style: TextStyle(color: Colors.white)),
  34. ),
  35. ),
  36. SliverList(
  37. delegate: SliverChildBuilderDelegate(
  38. (context, index) {
  39. return ListTile(
  40. title: Text('Item $index'),
  41. );
  42. },
  43. childCount: 20, // 列表项的数量
  44. ),
  45. ),
  46. SliverToBoxAdapter(
  47. child: Container(
  48. padding: EdgeInsets.all(16),
  49. color: Colors.green,
  50. child: Text('尾部', style: TextStyle(color: Colors.white)),
  51. ),
  52. ),
  53. ],
  54. ))
  55. ],
  56. ),
  57. )
  58. ],
  59. );
  60. }
  61. Row buildOperationBar() {
  62. return Row(children: [
  63. GestureDetector(
  64. onTap: () {},
  65. child: Row(
  66. children: [
  67. SizedBox(
  68. width: 0.1.sw,
  69. height: 0.1.sw,
  70. child: Assets.images.iconHomeLogged.image()),
  71. SizedBox(width: 8.w),
  72. Text(StringName.homeGoLogin.tr,
  73. style: TextStyle(
  74. fontWeight: FontWeight.bold,
  75. fontSize: 15.sp,
  76. color: ColorName.commonTxtColor))
  77. ],
  78. ),
  79. ),
  80. const Spacer(),
  81. GestureDetector(
  82. child: DecoratedBox(
  83. decoration: BoxDecoration(
  84. color: Colors.white,
  85. borderRadius: BorderRadius.circular(16),
  86. ),
  87. child: Padding(
  88. padding:
  89. const EdgeInsets.symmetric(horizontal: 8, vertical: 2).w,
  90. child: Row(
  91. children: [
  92. SizedBox(
  93. width: 28.w,
  94. height: 28.w,
  95. child: Assets.images.iconCharge.image()),
  96. SizedBox(width: 4.w),
  97. SizedBox(
  98. width: 28.w,
  99. child: Assets.images.iconChargeTxt.image()),
  100. SizedBox(
  101. width: 12.w,
  102. height: 12.w,
  103. child: Assets.images.iconChargeArrow.image()),
  104. ],
  105. ),
  106. )),
  107. onTap: () {})
  108. ]);
  109. }
  110. Container buildTopGradient() {
  111. return Container(
  112. width: 1.sw,
  113. height: 0.4444444444444444.sw,
  114. decoration: BoxDecoration(
  115. gradient: LinearGradient(
  116. colors: ['#E8EBFF'.toColor(), '#00E8EBFF'.toColor()],
  117. begin: Alignment.topCenter,
  118. end: Alignment.bottomCenter,
  119. stops: const [0.3, 1.0],
  120. ),
  121. ) // 其他子小部件
  122. );
  123. }
  124. DecoratedBox buildBgBox() {
  125. return DecoratedBox(
  126. decoration: BoxDecoration(color: '#F6F6F6'.toColor()),
  127. child: Container(
  128. height: double.infinity,
  129. ));
  130. }
  131. }