main.dart 1.3 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455
  1. import 'package:fltbdface_example/face_service.dart';
  2. import 'package:flutter/material.dart';
  3. import 'dart:async';
  4. import 'package:flutter/services.dart';
  5. import 'package:fltbdface/fltbdface.dart';
  6. import 'dart:convert';
  7. void main() => runApp(MyApp());
  8. class MyApp extends StatefulWidget {
  9. @override
  10. _MyAppState createState() => _MyAppState();
  11. }
  12. class _MyAppState extends State<MyApp> {
  13. FaceService faceService = FaceService();
  14. var imageBytes;
  15. @override
  16. void initState() {
  17. super.initState();
  18. }
  19. @override
  20. Widget build(BuildContext context) {
  21. return MaterialApp(
  22. home: Scaffold(
  23. appBar: AppBar(
  24. title: const Text('Plugin example app'),
  25. ),
  26. body: Center(
  27. child: Column(
  28. children: [
  29. TextButton(
  30. onPressed: () {
  31. faceService.startFaceLiveness(data: (data) {
  32. setState(() {
  33. imageBytes = Base64Decoder().convert(data);
  34. });
  35. }, onFailed: (error) {
  36. print(error);
  37. });
  38. },
  39. child: Text("点击采集人脸"),
  40. ),
  41. imageBytes != null ? Image.memory(imageBytes) : Container()
  42. ],
  43. ),
  44. ),
  45. ),
  46. );
  47. }
  48. }