A gesture-unlocking control for Flutter that supports a high degree of customization.
1)A simple and common demo.
Code:
GesturePasswordWidget(
lineColor: const Color(0xff0C6BFE),
errorLineColor: const Color(0xffFB2E4E),
singleLineCount: 3,
identifySize: 80.0,
minLength: 4,
errorItem: Image.asset(
'images/error.png',
color: const Color(0xffFB2E4E),
),
normalItem: Image.asset('images/normal.png'),
selectedItem: Image.asset(
'images/selected.png',
color: const Color(0xff0C6BFE),
),
answer: [0, 1, 2, 4, 7],
color: backgroundColor,
onComplete: (data) {
setState(() {
result = data.join(', ');
});
},
)
2)A complex demo. A line has four dots and supports the effect of the selection by set [hitItem].
Code:
GesturePasswordWidget(
lineColor: Colors.white,
errorLineColor: Colors.redAccent,
singleLineCount: 4,
identifySize: 80.0,
minLength: 4,
hitShowMilliseconds: 40,
errorItem: Container(
width: 10.0,
height: 10.0,
decoration: BoxDecoration(
color: Colors.redAccent,
borderRadius: BorderRadius.circular(50.0),
),
),
normalItem: Container(
width: 10.0,
height: 10.0,
decoration: BoxDecoration(
color: Colors.white,
borderRadius: BorderRadius.circular(50.0),
),
),
selectedItem: Container(
width: 10.0,
height: 10.0,
decoration: BoxDecoration(
color: Colors.white,
borderRadius: BorderRadius.circular(50.0),
),
),
hitItem: Container(
width: 15.0,
height: 15.0,
decoration: BoxDecoration(
color: Colors.white,
borderRadius: BorderRadius.circular(50.0),
),
),
answer: [0, 1, 2, 3, 6, 10, 14],
color: backgroundColor,
onComplete: (data) {
setState(() {
result = data.join(', ');
});
},
)
Property | Description |
---|---|
size | The width and height of GesturePasswordWidget. |
identifySize | The size of the area used to determine whether a point is selected, the larger the value of the more accurate identification. |
normalItem | Normal display of widget. |
selectedItem | The widget to display in the selected case. |
errorItem | The widget displayed in the error case will only work if minLength or answer is set. |
(1) When minLength is not null, if the number of selected points is less than minLength, display errorItem, for example, minLength = 4 is set, but the result set of selected points is [0,1,3], a total of 3 points are selected, less than 4. |
Author: LuodiJackShen
Source Code: https://github.com/LuodiJackShen/GesturePasswordWidget
#flutter #dart #mobile-apps