main.dart 1.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475
  1. import 'package:flutter/material.dart';
  2. import 'dart:async';
  3. import 'package:flutter/services.dart';
  4. import 'package:flutter_ali_camera/flutter_ali_camera.dart';
  5. void main() async {
  6. WidgetsFlutterBinding.ensureInitialized();
  7. await FlutterAliCameraController.initializeSdk();
  8. runApp(MyApp());
  9. }
  10. class MyApp extends StatefulWidget {
  11. @override
  12. _MyAppState createState() => _MyAppState();
  13. }
  14. class _MyAppState extends State<MyApp> {
  15. FlutterAliCameraController _controller = FlutterAliCameraController();
  16. double value = 0;
  17. @override
  18. void initState() {
  19. super.initState();
  20. initPlatform();
  21. }
  22. Future<void> initPlatform() async {
  23. await _controller.create();
  24. setState(() {});
  25. }
  26. void _onPlatformViewCreated() {
  27. }
  28. @override
  29. Widget build(BuildContext context) {
  30. return MaterialApp(
  31. home: Scaffold(
  32. backgroundColor: Colors.white,
  33. appBar: AppBar(
  34. title: const Text('Plugin example app'),
  35. ),
  36. body: Column(
  37. children: <Widget>[
  38. SizedBox(
  39. width: double.maxFinite,
  40. height: 200,
  41. child: _controller.buildView(_onPlatformViewCreated),
  42. ),
  43. Row(
  44. mainAxisAlignment: MainAxisAlignment.spaceEvenly,
  45. children: <Widget>[
  46. IconButton(icon: Icon(Icons.play_arrow, size: 26,), onPressed: () {
  47. _controller.startPreview();
  48. }),
  49. IconButton(icon: Icon(Icons.pause, size: 26,), onPressed: () {
  50. _controller.stopPreview();
  51. }),
  52. ],
  53. ),
  54. SizedBox(height: 5,),
  55. Slider(value: value, max: 100, onChanged: (value) {
  56. _controller.setBeauty(value.toInt());
  57. setState(() {
  58. this.value = value;
  59. });
  60. }),
  61. ],
  62. ),
  63. ),
  64. );
  65. }
  66. }