-
Notifications
You must be signed in to change notification settings - Fork 64
/
Copy path50.flutter_modern_item_section.dart
131 lines (122 loc) · 4.19 KB
/
50.flutter_modern_item_section.dart
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
import 'package:flutter/material.dart';
import 'package:ig_posts/season_2/63.transperant_design_pattern.dart';
import 'package:ig_posts/utils/colors.dart';
import 'package:provider/provider.dart';
class BrowseSectionNotifier extends ChangeNotifier {
bool expandMore = false;
void toggleExpansion() {
expandMore = !expandMore;
notifyListeners();
}
}
class ModernBrowseSectionView extends StatelessWidget {
const ModernBrowseSectionView({super.key});
@override
Widget build(BuildContext context) {
BrowseSectionNotifier browseSectionNotifier({required bool renderUI}) =>
Provider.of<BrowseSectionNotifier>(context, listen: renderUI);
renderSmallItems() {
smallItemBlock() {
return Padding(
padding: const EdgeInsets.all(8.0),
child: Container(
child: Column(
mainAxisAlignment: MainAxisAlignment.center,
children: [
SizedBox(
width: 120,
height: 100,
child: Image.asset("assets/drink_2.png")),
SizedBox(height: 10),
Text("Data", style: KConstantTextstyles.light(fontSize: 12))
],
),
decoration: BoxDecoration(
color: KConstantColors.bgColorFaint,
borderRadius: BorderRadius.circular(12)),
),
);
}
return SizedBox(
width: 500,
height: 180,
child: ListView.builder(
scrollDirection: Axis.horizontal,
itemCount: 5,
itemBuilder: (BuildContext context, int index) {
return smallItemBlock();
},
),
);
}
renderLargeItems() {
largeItemBlock() {
return Padding(
padding: const EdgeInsets.all(8.0),
child: Container(
child: Row(mainAxisAlignment: MainAxisAlignment.start, children: [
Padding(
padding: const EdgeInsets.all(8.0),
child: SizedBox(
width: 120,
height: 80,
child: Image.asset("assets/drink_2.png")),
),
SizedBox(height: 10),
Column(
mainAxisAlignment: MainAxisAlignment.start,
crossAxisAlignment: CrossAxisAlignment.start,
children: [
Text("Data", style: KConstantTextstyles.bold(fontSize: 12)),
Text("Some more data",
style: KConstantTextstyles.light(fontSize: 12))
],
)
]),
decoration: BoxDecoration(
color: KConstantColors.bgColorFaint,
borderRadius: BorderRadius.circular(12))),
);
}
return ListView.builder(
itemCount: 5,
shrinkWrap: true,
itemBuilder: (BuildContext context, int index) {
return largeItemBlock();
},
);
}
return Scaffold(
backgroundColor: KConstantColors.bgColor,
appBar: CustomAppBar(title: "Modern Browse Section"),
body: Column(
children: [
ListTile(
title:
Text("Products", style: KConstantTextstyles.bold(fontSize: 28)),
subtitle: Text("Checkout items from our store",
style: KConstantTextstyles.light(fontSize: 16)),
trailing: TextButton(
child: Text(
!browseSectionNotifier(renderUI: true).expandMore
? "Show less"
: "Browse more",
style: KConstantTextstyles.light(fontSize: 12)),
onPressed: () {
browseSectionNotifier(renderUI: false).toggleExpansion();
},
),
),
SizedBox(height: 10),
AnimatedCrossFade(
firstChild: renderSmallItems(),
secondChild: renderLargeItems(),
crossFadeState: browseSectionNotifier(renderUI: true).expandMore
? CrossFadeState.showFirst
: CrossFadeState.showSecond,
duration: Duration(seconds: 1))
],
),
);
}
}