Skip to content

Commit 51bbe8b

Browse files
committed
add the AbsorbPointer widget.
1 parent 1a196e7 commit 51bbe8b

File tree

6 files changed

+106
-0
lines changed

6 files changed

+106
-0
lines changed

lib/const/page_item_const.dart

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -267,4 +267,10 @@ const PAGE_ITEMS = [
267267
"img": PageImage.FLUTTER_OPEN,
268268
"click": PageName.INTER_DISMISSIBLE,
269269
},
270+
{
271+
"title": PageName.INTER_POINTER,
272+
"img": PageImage.FLUTTER_OPEN,
273+
"click": PageName.INTER_POINTER,
274+
},
275+
270276
];

lib/const/page_name_const.dart

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -58,4 +58,6 @@ class PageName {
5858
static const INTER_DRAG = "Draggable";
5959
static const INTER_GESTURE = "Gesture";
6060
static const INTER_DISMISSIBLE = "Dismissible";
61+
static const INTER_POINTER = "AbsorbPointer";
62+
static const INTER_SCROLLABLE = "Scrollable";
6163
}

lib/main.dart

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -72,6 +72,7 @@ class FlutterOpenApp extends StatelessWidget {
7272
PageName.INTER_DRAG: (context) => DraggablePage(),
7373
PageName.INTER_GESTURE: (context) => GesturePage(),
7474
PageName.INTER_DISMISSIBLE: (context) => DismissiblePage(),
75+
PageName.INTER_POINTER: (context) => PointerPage(),
7576
},
7677
);
7778
}
Lines changed: 58 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,58 @@
1+
///
2+
/// Created by NieBin on 2019/6/13
3+
/// Github: https://github.com/nb312
4+
/// Email: niebin312@gmail.com
5+
///
6+
import "package:flutter/material.dart";
7+
import 'package:flutter_widgets/const/_const.dart';
8+
9+
class PointerPage extends StatefulWidget {
10+
@override
11+
_PointerState createState() => _PointerState();
12+
}
13+
14+
class _PointerState extends State<PointerPage> {
15+
Widget _absorb() => Container(
16+
constraints: BoxConstraints.expand(height: 100),
17+
child: AbsorbPointer(
18+
child: GestureDetector(
19+
onTap: () {
20+
print("You have touch me.");
21+
},
22+
child: Text(
23+
"It can absorb the pointer touching when you click it. but you should set the parameter of the absorbing to the 'true'"),
24+
),
25+
absorbing: true,
26+
),
27+
color: RED_LIGHT,
28+
);
29+
30+
Widget _ignore() => Container(
31+
color: BLUE_LIGHT,
32+
child: IgnorePointer(
33+
child: GestureDetector(
34+
onTap: () {
35+
print("Hello world");
36+
},
37+
child: Text(
38+
"IgnorePointer,you can change the paramter of the ignoring to see the effect."),
39+
),
40+
ignoring: true,
41+
),
42+
);
43+
44+
@override
45+
Widget build(BuildContext context) {
46+
return Scaffold(
47+
appBar: AppBar(
48+
title: Text(PageName.INTER_POINTER),
49+
),
50+
body: Column(
51+
children: <Widget>[
52+
_absorb(),
53+
_ignore(),
54+
],
55+
),
56+
);
57+
}
58+
}
Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,37 @@
1+
///
2+
/// Created by NieBin on 2019/6/13
3+
/// Github: https://github.com/nb312
4+
/// Email: niebin312@gmail.com
5+
///
6+
import "package:flutter/material.dart";
7+
import 'package:flutter_widgets/const/_const.dart';
8+
9+
class ScrollablePage extends StatefulWidget {
10+
@override
11+
_ScrollableState createState() => _ScrollableState();
12+
}
13+
14+
class _ScrollableState extends State<ScrollablePage> {
15+
Widget _scrollBuilder(BuildContext context, position) => Container(
16+
child: Column(
17+
children: _list(),
18+
),
19+
);
20+
21+
List<Widget> _list() {
22+
List<Widget> list = List();
23+
for (int i = 0; i < 20; i++) {
24+
list.add(Container(
25+
constraints: BoxConstraints.expand(height: 100),
26+
color: i % 2 == 0 ? RED_LIGHT : BLUE_LIGHT,
27+
));
28+
}
29+
return list;
30+
}
31+
32+
@override
33+
Widget build(BuildContext context) {
34+
//it scrollable failed, so if you want to scroll a view, you can consider to use the CustomScrollView
35+
return Scrollable(viewportBuilder: _scrollBuilder);
36+
}
37+
}

lib/page/interation/_interaction.dart

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,3 +6,5 @@
66
export "DraggablePage.dart";
77
export "GesturePage.dart";
88
export "DismissiblePage.dart";
9+
export "PointerPage.dart";
10+
export "ScrollablePage.dart";

0 commit comments

Comments
 (0)