Skip to content

Commit 5ea4fee

Browse files
committed
添加preview组件和实例
1 parent 68322ee commit 5ea4fee

File tree

3 files changed

+205
-0
lines changed

3 files changed

+205
-0
lines changed

example/lib/preview_example.dart

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
import 'package:flutter/material.dart';
2+
import 'package:flutter_weui/flutter_weui.dart';
3+
4+
class PreviewExample extends StatelessWidget {
5+
@override
6+
Widget build(BuildContext context) {
7+
return Scaffold(
8+
appBar: AppBar(
9+
title: Text("Preview"),
10+
),
11+
body: Column(
12+
children: <Widget>[
13+
PreView(
14+
header: PreViewHeader(label: "label",value: "value",),
15+
body: PreViewBody(
16+
children: [
17+
PreViewItem(label: "sdsfsd",value: "sdfsdfasd",),
18+
PreViewItem(label: "sdsfsd",value: "sdfsdfasd",),
19+
PreViewItem(label: "sdsfsd",value: "sdfsdfasd",),
20+
PreViewItem(label: "sdsfsd",value: "sdfsdfasd",),
21+
],
22+
),
23+
footer: PreViewFooter(children: [PreViewButton(text: "sdsfs",),PreViewButton(text: "dsfsf",primary: true,)],),
24+
),
25+
],
26+
),
27+
);
28+
}
29+
}

lib/flutter_weui.dart

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,3 +15,4 @@ export 'media_box.dart';
1515
export 'panel.dart';
1616
export 'footer.dart';
1717
export 'article.dart';
18+
export 'preview.dart';

lib/preview.dart

Lines changed: 175 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,175 @@
1+
import 'package:flutter/material.dart';
2+
import 'constants.dart';
3+
import 'util.dart';
4+
import 'touchable.dart';
5+
6+
/*
7+
class PreView extends StatefulWidget {
8+
PreView({this.header, this.body, this.footer,Key key}):super(key: key);
9+
10+
final PreViewHeader header;
11+
final PreViewBody body;
12+
final PreViewFooter footer;
13+
14+
@override
15+
_PreViewState createState() => _PreViewState();
16+
}
17+
*/
18+
19+
class PreView extends StatelessWidget {
20+
PreView({this.header, this.body, this.footer,Key key}):super(key: key);
21+
22+
final PreViewHeader header;
23+
final PreViewBody body;
24+
final PreViewFooter footer;
25+
getChildren() {
26+
List<Widget> list = [];
27+
if (header != null) list.add(header);
28+
if (body != null) list.add(body);
29+
if (footer != null) list.add(footer);
30+
return list.toList();
31+
}
32+
33+
@override
34+
Widget build(BuildContext context) {
35+
return Container(
36+
decoration:
37+
BoxDecoration(border: Border(bottom: BorderSide(color: Constants.borderColor), top: BorderSide(color: Constants.borderColor)), color: Colors.white),
38+
child: Column(
39+
children: getChildren(),
40+
),
41+
);
42+
}
43+
}
44+
45+
/// PreViewItem组件
46+
class PreViewItem extends StatelessWidget {
47+
PreViewItem({this.label, this.value,Key key}):super(key: key);
48+
49+
final String label;
50+
final String value;
51+
52+
@override
53+
Widget build(BuildContext context) {
54+
return Padding(
55+
padding: const EdgeInsets.symmetric(vertical: 0, horizontal: 0),
56+
child: Row(
57+
mainAxisAlignment: MainAxisAlignment.spaceBetween,
58+
crossAxisAlignment: CrossAxisAlignment.center,
59+
children: <Widget>[
60+
Text(
61+
label,
62+
style: TextStyle(color: Color(0xFF999999), fontSize: emToPx(0.9)),
63+
),
64+
Text(
65+
value,
66+
style: TextStyle(color: Color(0xFF999999), fontSize: emToPx(0.9)),
67+
)
68+
],
69+
),
70+
);
71+
}
72+
}
73+
74+
/// PreViewBody组件
75+
class PreViewBody extends StatelessWidget {
76+
PreViewBody({this.children = const [],Key key}):super(key: key);
77+
78+
final List<PreViewItem> children;
79+
80+
@override
81+
Widget build(BuildContext context) {
82+
return Container(
83+
padding: const EdgeInsets.symmetric(vertical: 10, horizontal: 15),
84+
decoration: BoxDecoration(border: Border(bottom: BorderSide(color: Constants.borderColor))),
85+
child: Column(
86+
children: children.toList(),
87+
),
88+
);
89+
}
90+
}
91+
92+
/// PreViewHeader组件
93+
class PreViewHeader extends StatelessWidget {
94+
PreViewHeader({this.label, this.value,Key key}):super(key: key);
95+
96+
final String label;
97+
final String value;
98+
99+
@override
100+
Widget build(BuildContext context) {
101+
return Padding(
102+
padding: const EdgeInsets.only(left: 15),
103+
child: Container(
104+
padding: const EdgeInsets.only(top: 10, bottom: 10, right: 15),
105+
decoration: BoxDecoration(border: Border(bottom: BorderSide(color: Constants.borderColor,width: 1/MediaQuery.of(context).devicePixelRatio))),
106+
child: Row(
107+
mainAxisAlignment: MainAxisAlignment.spaceBetween,
108+
crossAxisAlignment: CrossAxisAlignment.center,
109+
children: <Widget>[
110+
Text(
111+
label,
112+
style: TextStyle(color: Color(0xFF999999), fontSize: emToPx(0.9)),
113+
),
114+
Text(
115+
value,
116+
style: TextStyle(
117+
fontSize: emToPx(1.2),
118+
),
119+
)
120+
],
121+
),
122+
),
123+
);
124+
}
125+
}
126+
127+
class PreViewButton extends StatelessWidget {
128+
PreViewButton({this.text = "", this.onPressed, this.primary = false,Key key}):super(key: key);
129+
130+
final String text;
131+
final VoidCallback onPressed;
132+
final bool primary;
133+
134+
@override
135+
Widget build(BuildContext context) {
136+
return TouchableOpacity(
137+
child: Container(
138+
height: Constants.btnHeight,
139+
child: Center(
140+
child: Text(
141+
text,
142+
style: TextStyle(fontSize: Constants.btnFontSize, color: primary == true ? Constants.primaryColor : Color(0xFF999999)),
143+
),
144+
),
145+
),
146+
onPressed: onPressed,
147+
);
148+
}
149+
}
150+
151+
class PreViewFooter extends StatelessWidget {
152+
PreViewFooter({this.children = const [],Key key}):super(key: key);
153+
154+
final List<PreViewButton> children;
155+
156+
getChildren() {
157+
List<Widget> list = [];
158+
for (int i = 0; i < children.length; i++) {
159+
list.add(Expanded(child: children.elementAt(i)));
160+
list.add(Container(
161+
width: 1,
162+
height: Constants.btnHeight,
163+
color: Constants.borderColor,
164+
));
165+
}
166+
return list.toList();
167+
}
168+
169+
@override
170+
Widget build(BuildContext context) {
171+
return Row(
172+
children: getChildren(),
173+
);
174+
}
175+
}

0 commit comments

Comments
 (0)