|
@@ -4,11 +4,12 @@ import 'package:flutter/material.dart';
|
4
|
4
|
import 'package:flutter_screenutil/flutter_screenutil.dart';
|
5
|
5
|
import 'package:get/get.dart';
|
6
|
6
|
import 'package:get/get_core/src/get_main.dart';
|
|
7
|
+import '../../../../models/entities/banner.dart';
|
|
8
|
+import '../../../../services/homeAPI.dart';
|
7
|
9
|
import '../../../../widgets/CarsCard.dart';
|
8
|
10
|
import '../../../../widgets/Search.dart';
|
9
|
11
|
import '../../../MoreCars/index.dart';
|
10
|
12
|
|
11
|
|
-
|
12
|
13
|
class HomePage extends StatefulWidget {
|
13
|
14
|
const HomePage({Key? key}) : super(key: key);
|
14
|
15
|
|
|
@@ -18,14 +19,19 @@ class HomePage extends StatefulWidget {
|
18
|
19
|
|
19
|
20
|
class _HomePageState extends State<HomePage> {
|
20
|
21
|
final CarouselController _controller = CarouselController();
|
21
|
|
- final List<String> imgList = [
|
22
|
|
- 'https://images.unsplash.com/photo-1520342868574-5fa3804e551c?ixlib=rb-0.3.5&ixid=eyJhcHBfaWQiOjEyMDd9&s=6ff92caffcdd63681a35134a6770ed3b&auto=format&fit=crop&w=1951&q=80',
|
23
|
|
- 'https://images.unsplash.com/photo-1522205408450-add114ad53fe?ixlib=rb-0.3.5&ixid=eyJhcHBfaWQiOjEyMDd9&s=368f45b0888aeb0b7b08e3a1084d3ede&auto=format&fit=crop&w=1950&q=80',
|
24
|
|
- 'https://images.unsplash.com/photo-1519125323398-675f0ddb6308?ixlib=rb-0.3.5&ixid=eyJhcHBfaWQiOjEyMDd9&s=94a1e718d89ca60a6337a6008341ca50&auto=format&fit=crop&w=1950&q=80',
|
25
|
|
- 'https://images.unsplash.com/photo-1523205771623-e0faa4d2813d?ixlib=rb-0.3.5&ixid=eyJhcHBfaWQiOjEyMDd9&s=89719a0d55dd05e2deae4120227e6efc&auto=format&fit=crop&w=1953&q=80',
|
26
|
|
- 'https://images.unsplash.com/photo-1508704019882-f9cf40e475b4?ixlib=rb-0.3.5&ixid=eyJhcHBfaWQiOjEyMDd9&s=8c6e5e3aba713b17aa1fe71ab4f0ae5b&auto=format&fit=crop&w=1352&q=80',
|
27
|
|
- 'https://images.unsplash.com/photo-1519985176271-adb1088fa94c?ixlib=rb-0.3.5&ixid=eyJhcHBfaWQiOjEyMDd9&s=a0c8d632e977f94e5d312d9893258f59&auto=format&fit=crop&w=1355&q=80'
|
28
|
|
- ];
|
|
22
|
+ List<banner> BannerList = [];
|
|
23
|
+
|
|
24
|
+ @override
|
|
25
|
+ void initState() {
|
|
26
|
+ super.initState();
|
|
27
|
+ getHomeBanner('banner').then((value) {
|
|
28
|
+ setState(() {
|
|
29
|
+ value.forEach((item) {
|
|
30
|
+ BannerList.add(banner.fromJson(item));
|
|
31
|
+ });
|
|
32
|
+ });
|
|
33
|
+ });
|
|
34
|
+ }
|
29
|
35
|
|
30
|
36
|
@override
|
31
|
37
|
Widget build(BuildContext context) {
|
|
@@ -34,83 +40,79 @@ class _HomePageState extends State<HomePage> {
|
34
|
40
|
padding: EdgeInsets.fromLTRB(15.w, 0, 15.w, 0),
|
35
|
41
|
child: ListView(
|
36
|
42
|
children: [
|
37
|
|
-
|
38
|
43
|
Container(
|
39
|
|
- width:20.w ,
|
40
|
|
- child: TypeHeader(type: true,),
|
|
44
|
+ width: 20.w,
|
|
45
|
+ child: TypeHeader(
|
|
46
|
+ type: true,
|
|
47
|
+ ),
|
41
|
48
|
),
|
42
|
|
-
|
43
|
|
-
|
44
|
49
|
Container(
|
45
|
50
|
margin: EdgeInsets.fromLTRB(0, 15, 0, 0),
|
46
|
|
- child: CarouselSlider(
|
47
|
|
- //API https://pub.dev/documentation/carousel_slider/latest/carousel_options/CarouselOptions-class.html
|
48
|
|
- items:imgList
|
49
|
|
- .map((item) => Container(
|
50
|
|
- child: Center(
|
51
|
|
- child:
|
52
|
|
- Image.network(item, fit: BoxFit.cover, width: 350.w)),
|
53
|
|
- ))
|
54
|
|
- .toList(),
|
|
51
|
+ child:
|
|
52
|
+ // Text('asdasdas')
|
|
53
|
+ CarouselSlider(
|
|
54
|
+ items: BannerList.map((item) => Container(
|
|
55
|
+ child: Center(
|
|
56
|
+ child: Image.network(item.thumb.toString(),
|
|
57
|
+ fit: BoxFit.cover, width: 350.w)),
|
|
58
|
+ )).toList(),
|
55
|
59
|
options: CarouselOptions(
|
56
|
60
|
autoPlay: true,
|
57
|
|
- enlargeCenterPage: false,//图片中心放大
|
58
|
|
- viewportFraction: 1,//每个页面应占据的视口部分。默认为 0.8,这意味着每个页面填充 80% 的轮播。
|
|
61
|
+ enlargeCenterPage: false, //图片中心放大
|
|
62
|
+ viewportFraction: 1, //每个页面应占据的视口部分。默认为 0.8,这意味着每个页面填充 80% 的轮播。
|
59
|
63
|
// aspectRatio: 1.6,//纵横比
|
60
|
64
|
height: 214.w,
|
61
|
|
- initialPage: 1,//初始页
|
|
65
|
+ initialPage: 1, //初始页
|
62
|
66
|
),
|
63
|
67
|
),
|
64
|
68
|
),
|
65
|
|
-
|
66
|
|
-
|
67
|
69
|
Container(
|
68
|
|
- margin: EdgeInsets.fromLTRB(0, 20, 0, 20),
|
69
|
|
- child: Column(
|
70
|
|
- children: [
|
71
|
|
- Row(
|
72
|
|
- mainAxisAlignment: MainAxisAlignment.spaceBetween,
|
73
|
|
- children: [
|
74
|
|
- Container(
|
75
|
|
- child: Row(
|
76
|
|
- children: [
|
77
|
|
- Padding(padding: EdgeInsets.fromLTRB(0, 0, 8, 0),
|
78
|
|
- child:Image(image: AssetImage('images/icons/carsListImga.png'),fit: BoxFit.cover,width: 20.w,),
|
79
|
|
- ),
|
80
|
|
- Text('农机列表',
|
81
|
|
- style: TextStyle(
|
82
|
|
- color: Color(0xff222222),
|
83
|
|
- fontSize: 20.sp,
|
84
|
|
- fontWeight: FontWeight.bold
|
|
70
|
+ margin: EdgeInsets.fromLTRB(0, 20, 0, 20),
|
|
71
|
+ child: Column(
|
|
72
|
+ children: [
|
|
73
|
+ Row(
|
|
74
|
+ mainAxisAlignment: MainAxisAlignment.spaceBetween,
|
|
75
|
+ children: [
|
|
76
|
+ Container(
|
|
77
|
+ child: Row(
|
|
78
|
+ children: [
|
|
79
|
+ Padding(
|
|
80
|
+ padding: EdgeInsets.fromLTRB(0, 0, 8, 0),
|
|
81
|
+ child: Image(
|
|
82
|
+ image:
|
|
83
|
+ AssetImage('images/icons/carsListImga.png'),
|
|
84
|
+ fit: BoxFit.cover,
|
|
85
|
+ width: 20.w,
|
|
86
|
+ ),
|
85
|
87
|
),
|
86
|
|
- )
|
87
|
|
- ],
|
88
|
|
- ),
|
89
|
|
- ),
|
90
|
|
- Container(
|
91
|
|
- child:GestureDetector(
|
92
|
|
- child: Text('更多 >>'),
|
93
|
|
- onTap: (){
|
94
|
|
- print('点我进入农机搜索/更多页');
|
95
|
|
- Get.to(MoreCars());
|
96
|
|
- },
|
|
88
|
+ Text(
|
|
89
|
+ '农机列表',
|
|
90
|
+ style: TextStyle(
|
|
91
|
+ color: Color(0xff222222),
|
|
92
|
+ fontSize: 20.sp,
|
|
93
|
+ fontWeight: FontWeight.bold),
|
|
94
|
+ )
|
|
95
|
+ ],
|
|
96
|
+ ),
|
97
|
97
|
),
|
98
|
|
- )
|
99
|
|
-
|
100
|
|
- ],
|
101
|
|
- ),
|
102
|
|
- CarsCard(),
|
103
|
|
- CarsCard(),
|
104
|
|
- CarsCard(),
|
105
|
|
- ],
|
106
|
|
- )
|
107
|
|
-
|
108
|
|
- ),
|
109
|
|
-
|
|
98
|
+ Container(
|
|
99
|
+ child: GestureDetector(
|
|
100
|
+ child: Text('更多 >>'),
|
|
101
|
+ onTap: () {
|
|
102
|
+ print('点我进入农机搜索/更多页');
|
|
103
|
+ Get.to(MoreCars());
|
|
104
|
+ },
|
|
105
|
+ ),
|
|
106
|
+ )
|
|
107
|
+ ],
|
|
108
|
+ ),
|
|
109
|
+ CarsCard(),
|
|
110
|
+ CarsCard(),
|
|
111
|
+ CarsCard(),
|
|
112
|
+ ],
|
|
113
|
+ )),
|
110
|
114
|
],
|
111
|
115
|
),
|
112
|
|
-
|
113
|
|
-
|
114
|
116
|
);
|
115
|
117
|
}
|
116
|
118
|
}
|