go_captcha_flutter 0.0.1
go_captcha_flutter: ^0.0.1 copied to clipboard
GoCaptcha Flutter library - A behavior captcha library for Flutter with Click, Slide, SlideRegion, and Rotate modes.
English | 中文
⭐️ If it helps you, please give a star.
| Flutter Version | Go Captcha Version |
|---|---|
| flutter >= 2.5.0 | go-captcha-flutter@^0 |
Install #
flutter pub add go_captcha_flutter
Or add it manually to pubspec.yaml:
dependencies:
go_captcha_flutter: ^0.0.1
Then run:
flutter pub get
Use Go Captcha #
import 'package:go_captcha_flutter/go_captcha_flutter.dart';
Click Mode #
final GlobalKey<State<StatefulWidget>> captchaKey = GlobalKey();
ClickCaptcha(
key: captchaKey,
config: const ClickConfig(),
image: '',
thumb: '',
onClick: (x, y) {
debugPrint('click: $x, $y');
},
onConfirm: (dots, reset) {
reset();
},
onRefresh: () {},
onClose: () {},
)
// call methods
(captchaKey.currentState as dynamic?)?.clear();
(captchaKey.currentState as dynamic?)?.refresh();
// config
class ClickConfig {
final double width;
final double height;
final double thumbWidth;
final double thumbHeight;
final double verticalPadding;
final double horizontalPadding;
final bool showTheme;
final String title;
final String buttonText;
final double iconSize;
final double titleFontSize;
final double buttonFontSize;
final double dotSize;
}
// widget
class ClickCaptcha extends StatefulWidget {
final ClickConfig config;
final String image;
final String thumb;
final Function(double x, double y)? onClick;
final ValueChanged<List<ClickDot>>? onDotChanged;
final Function(List<ClickDot> dots, VoidCallback reset)? onConfirm;
final VoidCallback? onRefresh;
final VoidCallback? onClose;
}
// data model
class ClickDot {
final int key;
final int index;
final double x;
final double y;
}
// exported methods from widget state
reset()
clear()
refresh()
close()
Slide Mode #
final GlobalKey<State<StatefulWidget>> captchaKey = GlobalKey();
SlideCaptcha(
key: captchaKey,
config: const SlideConfig(),
image: '',
thumb: '',
thumbX: 0,
thumbY: 0,
thumbWidth: 0,
thumbHeight: 0,
onMove: (x, y) {
debugPrint('move: $x, $y');
},
onConfirm: (point, reset) {
reset();
},
onRefresh: () {},
onClose: () {},
)
// call methods
(captchaKey.currentState as dynamic?)?.clear();
(captchaKey.currentState as dynamic?)?.refresh();
// config
class SlideConfig {
final double width;
final double height;
final double thumbWidth;
final double thumbHeight;
final double verticalPadding;
final double horizontalPadding;
final bool showTheme;
final String title;
final String helperText;
final double iconSize;
final double titleFontSize;
final double helperFontSize;
final bool scope;
}
// widget
class SlideCaptcha extends StatefulWidget {
final SlideConfig config;
final String image;
final String thumb;
final double thumbX;
final double thumbY;
final double thumbWidth;
final double thumbHeight;
final Function(double x, double y)? onMove;
final Function(Position position, VoidCallback reset)? onConfirm;
final VoidCallback? onRefresh;
final VoidCallback? onClose;
}
// data model
class Position {
final double x;
final double y;
}
// exported methods from widget state
reset()
clear()
refresh()
close()
Drag-Drop Mode #
final GlobalKey<State<StatefulWidget>> captchaKey = GlobalKey();
SlideRegionCaptcha(
key: captchaKey,
config: const SlideRegionConfig(),
image: '',
thumb: '',
thumbX: 0,
thumbY: 0,
thumbWidth: 0,
thumbHeight: 0,
onMove: (x, y) {
debugPrint('move: $x, $y');
},
onConfirm: (point, reset) {
reset();
},
onRefresh: () {},
onClose: () {},
)
// call methods
(captchaKey.currentState as dynamic?)?.clear();
(captchaKey.currentState as dynamic?)?.refresh();
// config
class SlideRegionConfig {
final double width;
final double height;
final double thumbWidth;
final double thumbHeight;
final double verticalPadding;
final double horizontalPadding;
final bool showTheme;
final String title;
final String idleText;
final String draggingText;
final String loadingText;
final double iconSize;
final double titleFontSize;
final double helperFontSize;
final bool scope;
}
// widget
class SlideRegionCaptcha extends StatefulWidget {
final SlideRegionConfig config;
final String image;
final String thumb;
final double thumbX;
final double thumbY;
final double thumbWidth;
final double thumbHeight;
final Function(double x, double y)? onMove;
final Function(Position position, VoidCallback reset)? onConfirm;
final VoidCallback? onRefresh;
final VoidCallback? onClose;
}
// data model
class Position {
final double x;
final double y;
}
// exported methods from widget state
reset()
clear()
refresh()
close()
Rotation Mode #
final GlobalKey<State<StatefulWidget>> captchaKey = GlobalKey();
RotateCaptcha(
key: captchaKey,
config: const RotateConfig(),
image: '',
thumb: '',
angle: 0,
onRotate: (angle) {
debugPrint('rotate: $angle');
},
onConfirm: (angle, reset) {
reset();
},
onRefresh: () {},
onClose: () {},
)
// call methods
(captchaKey.currentState as dynamic?)?.clear();
(captchaKey.currentState as dynamic?)?.refresh();
// config
class RotateConfig {
final double width;
final double height;
final double size;
final double thumbSize;
final double verticalPadding;
final double horizontalPadding;
final bool showTheme;
final String title;
final String helperText;
final double iconSize;
final double titleFontSize;
final double helperFontSize;
final bool scope;
}
// widget
class RotateCaptcha extends StatefulWidget {
final RotateConfig config;
final String image;
final String thumb;
final double angle;
final Function(double angle)? onRotate;
final Function(double angle, VoidCallback reset)? onConfirm;
final VoidCallback? onRefresh;
final VoidCallback? onClose;
}
// exported methods from widget state
reset()
clear()
refresh()
close()
Theme And Helper Types #
import 'package:go_captcha_flutter/go_captcha_flutter.dart';
GoCaptchaTheme
ImageHelper
LoadingWidget
CloseIconButton
RefreshIconButton
ArrowsIcon
ClickDot
Position
Example #
Please check the example/ directory for a complete demo.