簡體   English   中英

Flutter 中的對齊元素不起作用

[英]Aligning elements in Flutter isn't working

我寫了一個代碼,它使用flutter_mobile_visionmorse通過手機攝像頭掃描文本,並將這些掃描的文本轉換成莫爾斯電碼。
這是我的代碼:

import 'dart:async';
import 'package:flutter/cupertino.dart';
import 'package:flutter/material.dart';
import 'package:flutter_mobile_vision/flutter_mobile_vision.dart';
import 'package:google_fonts/google_fonts.dart';
import 'package:lottie/lottie.dart';
import 'package:morse/morse.dart';

class OCRPage extends StatefulWidget {
  @override
  _OCRPageState createState() => _OCRPageState();
}

class _OCRPageState extends State<OCRPage> {

  int _ocrCamera = FlutterMobileVision.CAMERA_BACK;
  String _text = "TEXT";

  Future<Null> _read() async {
    List<OcrText> texts = [];
    try {
      texts = await FlutterMobileVision.read(
        camera: _ocrCamera,
        waitTap: true,
      );

      setState(() {
        _text = texts[0].value;
      });
    } on Exception {
      texts.add( OcrText('Failed to recognize text'));
    }
  }

  @override
  Widget build(BuildContext context) {
    // TODO: implement build
    return SingleChildScrollView(
      child: Center(
        mainAxisAlignment: MainAxisAlignment.center,
        children: <Widget>[
          Lottie.asset('assets/scan-some-words.json', repeat: false),
          SizedBox(height: 20),
          Text(_text, style: GoogleFonts.orbitron(textStyle: TextStyle(color: Colors.white, fontSize: 20, fontWeight: FontWeight.w500)), textAlign: TextAlign.center,),
          SizedBox(height: 10),
          Text(Morse(_text).encode(), style: GoogleFonts.orbitron(textStyle: TextStyle(color: Colors.white, fontSize: 20, fontWeight: FontWeight.w500)),textAlign: TextAlign.center,),
          SizedBox(height: 30),
          ElevatedButton(
            onPressed: _read,
            child: new Text('Start Scanning'),
            // color: Color(0xFFFF16CD),
            // splashColor: Colors.orangeAccent,
          ),
          SizedBox(height: 10),
          Text('Tap on the text to convert into Morse Code', style: TextStyle(color: Color(0xffE6BBFC)),)
        ]

      )
    );


    throw UnimplementedError();
  }
}    

我指的是對齊小部件的鏈接:https://flutter.dev/docs/development/ui/layout#aligning-widgets
我正在嘗試將子元素對齊為子元素children: <Widget>[] 但我得到錯誤

未定義命名參數“mainAxisAlignment”。 (文檔)嘗試將名稱更正為現有命名參數的名稱,或使用名稱“mainAxisAlignment”定義命名參數。
未定義命名參數“children”。 (文檔)嘗試將名稱更正為現有命名參數的名稱,或使用名稱“children”定義命名參數。

我在這里錯過了什么?

mainAxisAlignment屬性是在 flex 布局中應如何沿主軸放置子項。 Center小部件沒有mainAxisAlignment屬性,因為它不是 flex 布局。

在這里您可以使用Column小部件。

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM