小部件不显示

时间:2019-09-02 20:02:39

标签: flutter dart

我试图创建一个可用的窗口小部件作为自定义窗口小部件,以便每次需要时都可以调用它,我将其命名为CarteCin(),但是当我调用它时并没有显示问题,它删除了所有创建,它给了我一个空白页,我不知道为什么请有人可以帮助我 这是小部件的代码:

class CarteCin extends StatelessWidget{
  Future<File> path1;
  bool isImageLoaded = false;

  List<int> bytes;

  TextEditingController nameController = TextEditingController();
  TextEditingController prenomController = TextEditingController();
  TextEditingController ddnController = TextEditingController();
  TextEditingController adresseController = TextEditingController();
  TextEditingController numeroController = TextEditingController();
  TextEditingController codeB1Controller = TextEditingController();
  TextEditingController codeB2Controller = TextEditingController();
  List<String> tableau = List();
  File pickedImage;
  var currentDate = new DateFormat("dd-MM-yyyy hh:mm:ss").format(now);

  Future writeTextField() async {
    nameController.text = tableau[0];
    prenomController.text = tableau[1];
    numeroController.text = tableau[4];
    ddnController.text = tableau[2];
  }
  Future readText() async {
    final FirebaseVisionImage ourImage = FirebaseVisionImage.fromFile(
        pickedImage);
    TextRecognizer recognizeText = FirebaseVision.instance.textRecognizer();
    VisionText readText = await recognizeText.processImage(ourImage);
    var decodedImage = await decodeImageFromList(pickedImage.readAsBytesSync());
    int width = decodedImage.width;
    int height = decodedImage.height;

    double demiwidth = width / 2;

    double demiheight = height / 2;


    List<TextBlock> readTextLast = List();
    readTextLast.addAll(readText.blocks);
    readTextLast.retainWhere((a) => a.boundingBox.left < demiwidth);
    readTextLast.retainWhere((a) => a.boundingBox.top > demiheight/2);
    readTextLast.sort((a, b) => a.boundingBox.top.toInt() - b.boundingBox.top.toInt());
    TextBlock a = readTextLast[0];
    TextBlock b = readTextLast[1];
    tableau.clear();
    tableau.add(a.lines[0].text);
    tableau.add(b.lines[0].text);


    List<TextBlock> readTextLast1 = List();
    readTextLast1.addAll(readText.blocks);
    readTextLast1.retainWhere((a) => a.boundingBox.left > demiwidth/2);
    readTextLast1.retainWhere((a) => a.boundingBox.right < demiwidth);
    TextBlock c = readTextLast1[0];
    TextBlock d = readTextLast1[1];
    tableau.add(c.lines[0].text);
    tableau.add(d.lines[0].text);

    List<TextBlock> readTextLast2 = List();
    readTextLast2.addAll(readText.blocks);
    readTextLast2.retainWhere((a) => a.boundingBox.left > demiwidth);
    readTextLast2.retainWhere((a) => a.boundingBox.top > demiheight/4);
    readTextLast2.sort((b, a) => a.boundingBox.top.toInt() - b.boundingBox.top.toInt());
    TextBlock e = readTextLast2[0];
    tableau.add(e.lines[0].elements[0].text);
    writeTextField();
  }
  Future<File> writeImage(var image) async {
    final file = await _localFile;
    print(file);
    bytes = await image.readAsBytes();

    // Write the file.
    return file.writeAsBytes(bytes);
  }
  Future<File> get _localFile async {
    final path = await _localPath;
    var now = new DateTime.now();
    String a = new DateFormat("H:m:s").format(now);
    return File('$path/image'+ a +'.png');
  }

  Future<String> get _localPath async {
    final directory = await getApplicationDocumentsDirectory();
    return directory.path;
  }

  Future pickImageCamera() async {
    var tempStore = await ImagePicker.pickImage(source: ImageSource.camera);
    await writeImage(tempStore);
    List<int> a = await readImage();
    print(a);
    path1 = _localFile;

      pickedImage = tempStore;
      isImageLoaded = true;

  }

  Future pickImage() async {
    var tempStore = await ImagePicker.pickImage(source: ImageSource.gallery);
    // bytes = await tempStore.readAsBytes();
    await writeImage(tempStore);
    List<int> a = await readImage();
    print(a);
    path1 = _localFile;

      pickedImage = tempStore;
      isImageLoaded = true;

  }
  Future<List<int>> readImage() async {
    final file = await _localFile;
    // Read the file.
    List<int> contents = await file.readAsBytes();
    return contents;
  }

  @override
  Widget build(BuildContext context) {
    // TODO: implement build
    return Scaffold(
      body: SingleChildScrollView(
      child: Column(
        children: <Widget>[
        Text("Camera en avant"),

          isImageLoaded ? Center(
            child: Container(
              padding: new EdgeInsets.all(20.0),

              height: 300.0,
              width: 500.0,
              decoration: BoxDecoration(
                  image: DecorationImage(
                      image: FileImage(pickedImage),
                      fit: BoxFit.cover)
              ),
            ),
          )
              : Container(),
          SizedBox(height: 10.0),
          RaisedButton(
            child: Text('gallery'),
            onPressed: pickImage,
          ),
          RaisedButton(
            child: Text('camera'),

            onPressed: pickImageCamera,
          ),
          SizedBox(height: 10.0),
          RaisedButton(
            child: Text('Read Text'),
            onPressed: readText,

          ),

       ]
    )

    ));
  }
}

这就是我所说的:

 new Row(
            children: [
              CarteCin(),
            ],
        )

0 个答案:

没有答案