Skip to content

Commit e5d49e9

Browse files
author
yangshangzhi
committed
Merge branch 'ysz' into test
2 parents ce4f840 + b357a06 commit e5d49e9

File tree

11 files changed

+253
-41
lines changed

11 files changed

+253
-41
lines changed
Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
## **Scrollbar**
2+
> 显示滚动条的位置的组件
3+
4+
### 构造函数
5+
```
6+
Scrollbar({
7+
Key key,
8+
@required Widget child
9+
})
10+
```
11+
12+
### 属性介绍
13+
> child: 子组件必填,返回可滾动列表组件
14+
- ListView/PageView/GridView/CustomScrollView...
Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
## **ScrollController**
2+
> 控制滚动组件滚动位置,监听与设置滚动位置。一般使用在滚动组件中的controller属性
3+
- 如ListView/PageView/GridView...
4+
5+
### 构造函数
6+
```
7+
ScrollController({
8+
double initialScrollOffset = 0.0,
9+
this.keepScrollOffset = true,
10+
this.debugLabel,
11+
})
12+
```
13+
14+
### 属性介绍
15+
- initialScrollOffset double 初始化滚动位置
16+
- debugLabel: String, 滚动时返回打印的内容, 当存在多滚动条组件时可进行区别.
17+
- keepScrollOffset, bool, 默认true时存储滚动位置,初始为0. 当为false时,则不存储滚动位置

lib/components/widgetComp.dart

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -83,8 +83,13 @@ class IndexState extends State<Index> {
8383
this.model = model;
8484
return Scaffold(
8585
appBar: AppBar(
86-
title: Header.Index(this.title),
87-
actions: this.getActions(context, model),
86+
title: Header.Index(
87+
this.title,
88+
),
89+
actions: this.getActions(
90+
context,
91+
model,
92+
),
8893
),
8994
body: this.loading ? this.renderLoading() : this.renderWidget(),
9095
);
@@ -131,7 +136,7 @@ class IndexState extends State<Index> {
131136
IconButton(
132137
icon: Icon(Icons.share),
133138
onPressed: () {
134-
final String msg =
139+
final String msg =
135140
model.config.state.env.GithubAssetOrigin + this.mdUrl;
136141
AppShare.shareText(msg);
137142
},

lib/page/component/index.dart

Lines changed: 38 additions & 36 deletions
Original file line numberDiff line numberDiff line change
@@ -45,47 +45,49 @@ class _IndexState extends State<Index> {
4545
);
4646
},
4747
body: Container(
48-
decoration: BoxDecoration(
49-
color: Color(AppTheme.thirdColor),
50-
),
51-
// padding: EdgeInsets.all(10),
5248
child: GridView.count(
49+
childAspectRatio: 1.3,
50+
padding: EdgeInsets.fromLTRB(4, 0, 4, 0),
5351
shrinkWrap: true,
5452
physics: ScrollPhysics(),
5553
crossAxisCount: 3,
56-
// crossAxisSpacing: 10,
57-
// mainAxisSpacing: 10,
58-
children: List.generate(_tmpWidgetList.length, (index) {
59-
return FlatButton(
60-
color: Color(AppTheme.secondColor),
61-
splashColor: Color(AppTheme.mainColor),
62-
child: Column(
63-
crossAxisAlignment: CrossAxisAlignment.center,
64-
mainAxisAlignment: MainAxisAlignment.spaceEvenly,
65-
children: [
66-
Icon(
67-
IconData(
68-
_tmpWidgetList[index].code,
69-
fontFamily: 'MaterialIcons',
70-
matchTextDirection: true,
54+
children: List.generate(
55+
_tmpWidgetList.length,
56+
(index) {
57+
return FlatButton(
58+
color: Color(AppTheme.secondColor),
59+
splashColor: Color(AppTheme.mainColor),
60+
child: Column(
61+
crossAxisAlignment: CrossAxisAlignment.center,
62+
mainAxisAlignment: MainAxisAlignment.spaceEvenly,
63+
children: [
64+
Icon(
65+
IconData(
66+
_tmpWidgetList[index].code,
67+
fontFamily: 'MaterialIcons',
68+
matchTextDirection: true,
69+
),
70+
color: Color(AppTheme.mainColor),
71+
size: 32,
7172
),
72-
color: Color(AppTheme.mainColor),
73-
size: 48,
74-
),
75-
Text(
76-
'${_tmpWidgetList[index].title}',
77-
overflow: TextOverflow.ellipsis,
78-
)
79-
],
80-
),
81-
onPressed: () {
82-
FluroRouter.router.navigateTo(
83-
context,
84-
nameSpaces + _tmpWidgetList[index].title,
85-
);
86-
},
87-
);
88-
}),
73+
Text(
74+
'${_tmpWidgetList[index].title}',
75+
overflow: TextOverflow.ellipsis,
76+
style: TextStyle(
77+
fontSize: 16,
78+
),
79+
)
80+
],
81+
),
82+
onPressed: () {
83+
FluroRouter.router.navigateTo(
84+
context,
85+
nameSpaces + _tmpWidgetList[index].title,
86+
);
87+
},
88+
);
89+
},
90+
),
8991
),
9092
),
9193
isExpanded: _isExpandedIndex == index,

lib/page/home.dart

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -88,7 +88,7 @@ class _IndexState extends State<Index> {
8888
builder: (context, child, model) {
8989
return Scaffold(
9090
appBar: AppBar(
91-
title: Header.Index(lang.t('title')),
91+
title: Header.Index(lang.t('title'),),
9292
actions: appBarActions(model),
9393
),
9494
bottomNavigationBar: _bottomNavigationBar(model),

lib/widget/scrollview/index.dart

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,8 @@ import 'listview/index.dart' as listview;
44
import 'scrollable/index.dart' as scrollable;
55
import 'customscrollview/index.dart' as customscrollview;
66
import 'singlechildscrollview/index.dart' as singlechildscrollview;
7+
import 'scrollbar/index.dart' as scrollbar;
8+
import 'scrollcontroller/index.dart' as scrollcontroller;
79

810
const nameSpaces = '/scrollview_';
911

@@ -32,7 +34,17 @@ List widgets = [
3234
widget: singlechildscrollview.Index(),
3335
code: 57909, // format_align_justify
3436
title: singlechildscrollview.Index.title,
35-
)
37+
),
38+
ItemInfo(
39+
widget: scrollbar.Index(),
40+
code: 59614, // toc
41+
title: scrollbar.Index.title,
42+
),
43+
ItemInfo(
44+
widget: scrollcontroller.Index(),
45+
code: 57945, // vertical_align_center
46+
title: scrollcontroller.Index.title,
47+
),
3648
];
3749

3850
List widgetMap = [
Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
1+
import 'package:flutter/material.dart';
2+
3+
class Index extends StatefulWidget {
4+
@override
5+
State<StatefulWidget> createState() => _IndexState();
6+
}
7+
8+
class _IndexState extends State<Index> {
9+
@override
10+
void initState() {
11+
super.initState();
12+
}
13+
14+
@override
15+
Widget build(BuildContext context) {
16+
return Scaffold(
17+
appBar: AppBar(
18+
title: Text('Scrollbar'),
19+
),
20+
body: Scrollbar(
21+
child: ListView.builder(
22+
// gridDelegate: SliverGridDelegateWithMaxCrossAxisExtent(
23+
// maxCrossAxisExtent: 100,
24+
// ),
25+
itemCount: 20,
26+
itemExtent: 50, // 行高
27+
itemBuilder: (context, index) {
28+
return ListTile(
29+
title: Text(' $index 滚动时显示滚动条'),
30+
);
31+
},
32+
),
33+
),
34+
);
35+
}
36+
}
Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
import 'package:flutter/material.dart';
2+
import 'package:efox_flutter/components/widgetComp.dart' as WidgetComp;
3+
import 'demo.dart' as Demo;
4+
5+
class Index extends StatefulWidget {
6+
static String title = 'Scrollbar';
7+
static String mdUrl = 'docs/widget/scrollview/scrollbar/index.md';
8+
static String originCodeUrl = 'https://docs.flutter.io/flutter/widgets/Scrollbar-class.html';
9+
10+
@override
11+
_IndexState createState() => new _IndexState();
12+
}
13+
14+
class _IndexState extends State<Index> {
15+
@override
16+
Widget build(BuildContext context) {
17+
return WidgetComp.Index(
18+
title: Index.title,
19+
originCodeUrl: Index.originCodeUrl,
20+
mdUrl: Index.mdUrl,
21+
demoChild: [
22+
Demo.Index(),
23+
]
24+
);
25+
}
26+
}
Lines changed: 72 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,72 @@
1+
import 'package:flutter/material.dart';
2+
import 'package:efox_flutter/config/theme.dart' show AppTheme;
3+
4+
class Index extends StatefulWidget {
5+
@override
6+
State<StatefulWidget> createState() => _IndexState();
7+
}
8+
9+
class _IndexState extends State<Index> {
10+
ScrollController _controller = new ScrollController(
11+
initialScrollOffset: 99,
12+
keepScrollOffset: true,
13+
);
14+
bool toTopBtn = false;
15+
int count = 50;
16+
double height = 50;
17+
18+
@override
19+
void initState() {
20+
super.initState();
21+
_controller.addListener(this.scrollEvent);
22+
}
23+
24+
void scrollEvent() {
25+
print(_controller);
26+
var _status = false;
27+
if (_controller.offset > 100) {
28+
_status = true;
29+
} else {
30+
_status = false;
31+
}
32+
setState(() {
33+
this.toTopBtn = _status;
34+
});
35+
}
36+
37+
@override
38+
Widget build(BuildContext context) {
39+
return Scaffold(
40+
appBar: AppBar(
41+
title: Text('ScrollController'),
42+
),
43+
body: Scrollbar(
44+
child: ListView.builder(
45+
// gridDelegate: SliverGridDelegateWithMaxCrossAxisExtent(
46+
// maxCrossAxisExtent: 100,
47+
// ),
48+
controller: _controller,
49+
itemCount: this.count,
50+
itemExtent: this.height, // 行高
51+
itemBuilder: (context, index) {
52+
return ListTile(
53+
title: Text(' $index 向上滚动,会显示回到顶部图标'),
54+
);
55+
},
56+
),
57+
),
58+
floatingActionButton: !this.toTopBtn
59+
? null
60+
: FloatingActionButton(
61+
backgroundColor: Color(AppTheme.mainColor),
62+
child: Icon(
63+
Icons.arrow_upward,
64+
color: Color(AppTheme.secondColor),
65+
),
66+
onPressed: () {
67+
_controller.jumpTo(-50);
68+
},
69+
),
70+
);
71+
}
72+
}
Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
import 'package:flutter/material.dart';
2+
import 'package:efox_flutter/components/widgetComp.dart' as WidgetComp;
3+
import 'demo.dart' as Demo;
4+
5+
class Index extends StatefulWidget {
6+
static String title = 'ScrollController';
7+
static String mdUrl = 'docs/widget/scrollview/scrollcontroller/index.md';
8+
static String originCodeUrl = 'https://docs.flutter.io/flutter/widgets/ScrollController-class.html';
9+
10+
@override
11+
_IndexState createState() => new _IndexState();
12+
}
13+
14+
class _IndexState extends State<Index> {
15+
@override
16+
Widget build(BuildContext context) {
17+
return WidgetComp.Index(
18+
title: Index.title,
19+
originCodeUrl: Index.originCodeUrl,
20+
mdUrl: Index.mdUrl,
21+
demoChild: [
22+
Demo.Index(),
23+
]
24+
);
25+
}
26+
}

0 commit comments

Comments
 (0)