Skip to content

Commit d7d09c8

Browse files
author
张瑞宇
committed
add example
1 parent 7242f2f commit d7d09c8

File tree

7 files changed

+114
-42
lines changed

7 files changed

+114
-42
lines changed

README.md

Lines changed: 103 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,13 +9,115 @@ For help getting started with Flutter, view our online [documentation](https://f
99
For help on editing package code, view the [documentation](https://flutter.io/developing-packages/).
1010
![image](https://github.com/zhangruiyu/flutter_gesture_password/blob/master/wow.gif)
1111

12-
#属性
12+
##How to use ?
13+
14+
1. Depend on it
15+
16+
```yaml
17+
dependencies:
18+
gesture_password: "^0.0.2"
19+
```
20+
21+
2. Install it
22+
23+
```sh
24+
$ flutter packages get
25+
```
26+
27+
3. Import it
28+
29+
```dart
30+
import 'package:gesture_password/gesture_password.dart';
31+
import 'package:gesture_password/mini_gesture_password.dart';
32+
```
33+
34+
##属性
1335
* selectedColor 选中的颜色
1436
* normalColor: 没选中的颜色
1537
* lineStrokeWidth: 线宽
1638
* circleStrokeWidth: 选中外圈圆宽
1739
* smallCircleR: 小圆半径
1840
* bigCircleR: 大圆半径
1941
* focusDistance: 选中差值 越大越容易选中
42+
* successCallback 选择4个以上松手回调,返回值为选中的index相加的字符串
43+
* failCallback 选择4下以上松手回调
44+
* selectedCallback 经过任意一个后回调,返回值为选中的index相加的字符串
45+
46+
##Example
47+
```
48+
import 'package:flutter/material.dart';
49+
import 'package:gesture_password/gesture_password.dart';
50+
import 'package:gesture_password/mini_gesture_password.dart';
51+
52+
void main() => runApp(new MyApp());
53+
54+
class MyApp extends StatelessWidget {
55+
@override
56+
Widget build(BuildContext context) {
57+
return new MaterialApp(
58+
title: 'Flutter Demo',
59+
theme: new ThemeData(
60+
primarySwatch: Colors.blue,
61+
),
62+
home: new MyHomePage(title: 'Flutter Demo Home Page'),
63+
);
64+
}
65+
}
66+
67+
class MyHomePage extends StatefulWidget {
68+
MyHomePage({Key key, this.title}) : super(key: key);
69+
70+
final String title;
71+
72+
@override
73+
_MyHomePageState createState() => new _MyHomePageState();
74+
}
75+
76+
class _MyHomePageState extends State<MyHomePage> {
77+
GlobalKey<MiniGesturePasswordState> miniGesturePassword =
78+
new GlobalKey<MiniGesturePasswordState>();
79+
80+
GlobalKey<ScaffoldState> scaffoldState = new GlobalKey<ScaffoldState>();
81+
82+
@override
83+
Widget build(BuildContext context) {
84+
return new MaterialApp(
85+
home: new Scaffold(
86+
key: scaffoldState,
87+
appBar: new AppBar(
88+
title: new Text('Plugin example app'),
89+
),
90+
body: new Column(
91+
children: <Widget>[
92+
new Center(
93+
child: new MiniGesturePassword(key: miniGesturePassword)),
94+
new Container(
95+
color: Colors.red,
96+
margin: const EdgeInsets.only(top: 100.0),
97+
child: new GesturePassword(
98+
successCallback: (s) {
99+
print("successCallback$s");
100+
scaffoldState.currentState?.showSnackBar(
101+
new SnackBar(content: new Text('successCallback:$s')));
102+
miniGesturePassword.currentState?.setSelected('');
103+
},
104+
failCallback: () {
105+
print('failCallback');
106+
scaffoldState.currentState?.showSnackBar(
107+
new SnackBar(content: new Text('failCallback')));
108+
miniGesturePassword.currentState?.setSelected('');
109+
},
110+
selectedCallback: (str) {
111+
miniGesturePassword.currentState?.setSelected(str);
112+
},
113+
),
114+
),
115+
],
116+
),
117+
),
118+
);
119+
}
120+
}
121+
```
20122

21123
##### 有需求的话,后期再加入其他的吧

example/lib/main.dart

Lines changed: 3 additions & 35 deletions
Original file line numberDiff line numberDiff line change
@@ -5,20 +5,11 @@ import 'package:gesture_password/mini_gesture_password.dart';
55
void main() => runApp(new MyApp());
66

77
class MyApp extends StatelessWidget {
8-
// This widget is the root of your application.
98
@override
109
Widget build(BuildContext context) {
1110
return new MaterialApp(
1211
title: 'Flutter Demo',
1312
theme: new ThemeData(
14-
// This is the theme of your application.
15-
//
16-
// Try running your application with "flutter run". You'll see the
17-
// application has a blue toolbar. Then, without quitting the app, try
18-
// changing the primarySwatch below to Colors.green and then invoke
19-
// "hot reload" (press "r" in the console where you ran "flutter run",
20-
// or press Run > Flutter Hot Reload in IntelliJ). Notice that the
21-
// counter didn't reset back to zero; the application is not restarted.
2213
primarySwatch: Colors.blue,
2314
),
2415
home: new MyHomePage(title: 'Flutter Demo Home Page'),
@@ -29,38 +20,15 @@ class MyApp extends StatelessWidget {
2920
class MyHomePage extends StatefulWidget {
3021
MyHomePage({Key key, this.title}) : super(key: key);
3122

32-
// This widget is the home page of your application. It is stateful, meaning
33-
// that it has a State object (defined below) that contains fields that affect
34-
// how it looks.
35-
36-
// This class is the configuration for the state. It holds the values (in this
37-
// case the title) provided by the parent (in this case the App widget) and
38-
// used by the build method of the State. Fields in a Widget subclass are
39-
// always marked "final".
40-
4123
final String title;
4224

4325
@override
4426
_MyHomePageState createState() => new _MyHomePageState();
4527
}
4628

4729
class _MyHomePageState extends State<MyHomePage> {
48-
int _counter = 0;
49-
50-
void _incrementCounter() {
51-
setState(() {
52-
// This call to setState tells the Flutter framework that something has
53-
// changed in this State, which causes it to rerun the build method below
54-
// so that the display can reflect the updated values. If we changed
55-
// _counter without calling setState(), then the build method would not be
56-
// called again, and so nothing would appear to happen.
57-
_counter++;
58-
});
59-
}
60-
61-
6230
GlobalKey<MiniGesturePasswordState> miniGesturePassword =
63-
new GlobalKey<MiniGesturePasswordState>();
31+
new GlobalKey<MiniGesturePasswordState>();
6432

6533
GlobalKey<ScaffoldState> scaffoldState = new GlobalKey<ScaffoldState>();
6634

@@ -81,13 +49,13 @@ class _MyHomePageState extends State<MyHomePage> {
8149
margin: const EdgeInsets.only(top: 100.0),
8250
child: new GesturePassword(
8351
successCallback: (s) {
84-
print("密码为$s");
52+
print("successCallback$s");
8553
scaffoldState.currentState?.showSnackBar(
8654
new SnackBar(content: new Text('successCallback:$s')));
8755
miniGesturePassword.currentState?.setSelected('');
8856
},
8957
failCallback: () {
90-
print('失败了');
58+
print('failCallback');
9159
scaffoldState.currentState?.showSnackBar(
9260
new SnackBar(content: new Text('failCallback')));
9361
miniGesturePassword.currentState?.setSelected('');

example/test/widget_test.dart

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,8 +4,9 @@
44
// find child widgets in the widget tree, read text, and verify that the values of widget properties
55
// are correct.
66

7-
import 'package:flutter/material.dart';
8-
import 'package:flutter_test/flutter_test.dart';
7+
//import 'package:flutter/material.dart';
8+
//import 'package:flutter_test/flutter_test.dart';
9+
/*
910
1011
import 'package:example/main.dart';
1112
@@ -27,3 +28,4 @@ void main() {
2728
expect(find.text('1'), findsOneWidget);
2829
});
2930
}
31+
*/

lib/gesture_password.dart

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,9 @@
11
import 'dart:ui' as ui;
22

3+
import 'package:flutter/foundation.dart';
34
import 'package:flutter/material.dart';
45
import 'package:flutter/widgets.dart';
56
import 'package:gesture_password/circle_item_painter.dart';
6-
import 'package:meta/meta.dart';
77

88
class GesturePassword extends StatefulWidget {
99
final ValueChanged<String> successCallback;
@@ -50,7 +50,7 @@ class _GesturePasswordState extends State<GesturePassword> {
5050
setState(() {
5151
RenderBox box = context.findRenderObject();
5252
touchPoint = box.globalToLocal(details.globalPosition);
53-
//会绘画越界
53+
//防止绘画越界
5454
if (touchPoint.dy < 0) {
5555
touchPoint = new Offset(touchPoint.dx, 0.0);
5656
}

lib/mini_gesture_password.dart

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
import 'package:flutter/material.dart';
22
import 'package:flutter/widgets.dart';
3-
import 'package:gesture_password/MiniCircleView.dart';
3+
import 'package:gesture_password/mini_circle_view.dart';
44

55
class MiniGesturePassword extends StatefulWidget {
66
final MiniItemAttribute attribute;

pubspec.yaml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
name: gesture_password
22
description: A new flutter GesturePassword
3-
version: 0.0.1
3+
version: 0.0.2
44
author: zhangruiyu <157418979@qq.com>
55
homepage: https://github.com/zhangruiyu/flutter_gesture_password
66

0 commit comments

Comments
 (0)