一、进入App直接显示拍照页面

import 'package:flutter/material.dart';
import 'package:faceimage/camera.dart';
import 'package:faceimage/renderPicture.dart';

void main() => runApp(MyApp());

class MyApp extends StatelessWidget {
  // This widget is the root of your application.
  @override
  Widget build(BuildContext context) {
    return MaterialApp(
      theme: ThemeData(primarySwatch: Colors.blue,),
      home: MyHomePage(),
      routes: <String, WidgetBuilder>{
        "camera": (context) => camera(),
        "renderPicture": (context) => renderPicture(),
      },
    );
  }
}

class MyHomePage extends StatefulWidget {
  @override
  State<StatefulWidget> createState() {
    // TODO: implement createState
    return page();
  }
}

class page extends State<MyHomePage> {
  @override
  Widget build(BuildContext context) {
    // TODO: implement build
    return camera();
  }
}

二、在拍照页面,显示相机

import 'dart:io';
import 'package:path_provider/path_provider.dart';
import 'package:flutter/material.dart';
import 'package:faceimage/renderPicture.dart';
import 'package:camera/camera.dart';
import 'dart:async';

class camera extends StatefulWidget {
  @override
  State<StatefulWidget> createState() {
    // TODO: implement createState
    return page();
  }
}

class page extends State<camera> {
  CameraController controller;
  @override
  void initState() {
    super.initState();
    // 初始化相机对象
//    creatController();
  }

  @override
  void dispose() {
    super.dispose();
    controller?.dispose();
  }

  @override
  Widget build(BuildContext context) {
//    if (controller == null || !controller.value.isInitialized) {
//      return Container();
//    }
    return Scaffold(
//      body: AspectRatio(
//          aspectRatio: controller.value.aspectRatio,
//          child: CameraPreview(controller)
//      ),
      floatingActionButton: FloatingActionButton(
        child: Icon(Icons.camera_alt),
        onPressed: () async {
          final path = "";
//          final path = (await getTemporaryDirectory()).path + '${DateTime.now()}.png';
//          await controller.takePicture(path);
          Navigator.push(context, MaterialPageRoute(
            builder: (context) => renderPicture(picture: path),
          ));
        },
      ),
    );
  }

  Future creatController() async {
    List<CameraDescription> cameras = await availableCameras();
    controller = CameraController(cameras[1], ResolutionPreset.high);
    controller.initialize().then((_){
      if (!mounted) {
        return;
      }
      setState(() {});
    });
  }

//  @override
//  Widget build(BuildContext context) {
//    // TODO: implement build
//    return new Scaffold(
//      backgroundColor: Colors.yellow,
//      body: Container(
//        margin: EdgeInsets.only(top: 60, left: 30),
//        child: Column(
//          children: <Widget>[
//            FlatButton(
//              child: Text("测试"),
//              onPressed: _clickButton,
//            )
//          ],
//        ),
//      )
//    );
//  }
//
//  _clickButton() {
//    Navigator.of(context).push(
//        PageRouteBuilder(opaque: false,
//            pageBuilder: (context, animation, secondaryAnimation) {
//            return renderPicture();
//        })
//    );
//  }
}

三、点击拍照,进入下个页面,显示照片

import 'dart:io';
import 'package:dio/dio.dart';
import 'package:flutter/material.dart';

class renderPicture extends StatefulWidget {
  renderPicture({Key key, this.picture}): super(key: key);
  final String picture;
  @override
  State<StatefulWidget> createState() {
    // TODO: implement createState
    return page();
  }
}

class page extends State<renderPicture> {

  @override
  void initState() {
    super.initState();
    // 上传图片
    uploadImage();
//    getFaceMessage();
  }
  @override
  Widget build(BuildContext context) {
    // TODO: implement build
    return new Scaffold(
      backgroundColor: Colors.red,
//      body: Image.file(File(widget.picture)),
    );
  }

  _clickButton() {
    Navigator.of(context).pop(false);
  }
  // 上传图片
  void uploadImage() async {
//    FormData formData = new FormData.fromMap({
//      "file": await MultipartFile.fromFile(widget.picture, filename: "upload.png"),
//    });
    Dio dio = new Dio();
    dio.options.connectTimeout = 3000 * 10;
    Response response = await dio.get("http://www.xx:8080/face/index?name=upload.png");
//    Response response = await dio.post("http://www.xx:8080/face/index", data: formData);
//    print("11111111111111");
    if (response.statusCode == 200) {
    }
  }

  // 获取人脸识别数据
  void getFaceMessage() async {
//    Dio dio11 = new Dio();
//    Response response = await dio11.get("xx:8080/face/index?name=upload.png");
//    if (response.statusCode == 200) {
//      print("3333333333333");
//    }
  }
}

/*
* import 'dart:convert';
import 'dart:ui';
import 'package:flutter/material.dart';

class homePage extends StatefulWidget {
  @override
  State<StatefulWidget> createState() {
    // TODO: implement createState
    return page();
  }
}

class page extends State<StatefulWidget> {
  Map dictionary;
  @override
  Widget build(BuildContext context) {
    // TODO: implement build
    return FutureBuilder(
      future: DefaultAssetBundle.of(context).loadString("jsons/face.json"),
      builder: (context, snapshot){
        if (snapshot.hasData) {
          dictionary = json.decode(snapshot.data.toString());
          // 解析本地Json数据
          List points = retrieveData(dictionary);
          return new Scaffold(
            appBar: AppBar(title: Text("公园"),),
            body: Column(
              crossAxisAlignment: CrossAxisAlignment.center,
              children: <Widget>[
                _buildTopBannerWidget(points),
              ],
            ),
          );
        }
        return CircularProgressIndicator();
      },
    );
  }
// 数据解析
  List retrieveData(point) {
    List faces = point["faces"];
    Map dic = faces.first;
    Map landmark = dic["landmark"];
    List<Offset> listPoint = new List();
    landmark.forEach((key, value) {
      listPoint.add(Offset(value["x"] * 1.0, value["y"] * 1.0));
    });
    return listPoint;
  }

  // 顶部图片
  _buildTopBannerWidget(points) {
    return Container(
      margin: EdgeInsets.only(left: 20, top: 20),
      width: 290,
      height: 356,
      child: Stack(
        alignment: Alignment.topLeft,
        children: <Widget>[
          Image.asset(
            "images/testA.jpg",
            fit: BoxFit.cover,
          ),
          _drawCustomPaint(points),
        ]
      )
    );
  }

  // 绘制点
  _drawCustomPaint(points) {
    return CustomPaint(
      size: Size(290, 356),
      painter: MyPainter(points),
    );
  }

}
class MyPainter extends CustomPainter {
  MyPainter(this.points);
  final List<Offset> points;
  @override
  void paint(Canvas canvas, Size size) {
    var paint = Paint()
      ..style = PaintingStyle.fill
      ..strokeWidth = 3.0
      ..color = Colors.red;
    canvas.drawPoints(PointMode.points, points, paint);
  }
  @override
  bool shouldRepaint(MyPainter oldDelegate) {
    return oldDelegate.points != points;
  }
}
* */