[英]Aligning elements in Flutter isn't working
I wrote a code which uses flutter_mobile_vision
and morse
to scan texts via mobile camera and covert those scanned texts into Morse code.我写了一个代码,它使用
flutter_mobile_vision
和morse
通过手机摄像头扫描文本,并将这些扫描的文本转换成莫尔斯电码。
Here is my code:这是我的代码:
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();
}
}
I'm referring this link for aligning widgets:https://flutter.dev/docs/development/ui/layout#aligning-widgets我指的是对齐小部件的链接:https://flutter.dev/docs/development/ui/layout#aligning-widgets
I'm trying to align the child elements as children: <Widget>[]
.我正在尝试将子元素对齐为子元素
children: <Widget>[]
。 But I get error as但我得到错误
The named parameter 'mainAxisAlignment' isn't defined.
未定义命名参数“mainAxisAlignment”。 (Documentation) Try correcting the name to an existing named parameter's name, or defining a named parameter with the name 'mainAxisAlignment'.
(文档)尝试将名称更正为现有命名参数的名称,或使用名称“mainAxisAlignment”定义命名参数。
The named parameter 'children' isn't defined.未定义命名参数“children”。 (Documentation) Try correcting the name to an existing named parameter's name, or defining a named parameter with the name 'children'.
(文档)尝试将名称更正为现有命名参数的名称,或使用名称“children”定义命名参数。
What did I miss here?我在这里错过了什么?
mainAxisAlignment
property is How the children should be placed along the main axis in a flex layout. mainAxisAlignment
属性是在 flex 布局中应如何沿主轴放置子项。 A Center
widget doesn't have mainAxisAlignment
property since it is not flex layout. Center
小部件没有mainAxisAlignment
属性,因为它不是 flex 布局。
Here you can can use Column
widget.在这里您可以使用
Column
小部件。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.