我编写了以下简单的flutter应用程序。我试图在没有MaterialApp的情况下编写此代码。 早期的方向性错误即将来临,我可以使用Directionality Widget来解决。即使不使用主题,它也会显示黑屏且无输出。请纠正错误
import 'package:flutter/cupertino.dart';
import 'package:flutter/material.dart';
void main()
{
runApp(MyApp());
}
class MyApp extends StatefulWidget
{
@override
State<StatefulWidget> createState() {
// TODO: implement createState
return _MyAppState();
}
}
class _MyAppState extends State<MyApp> {
double maxbid = 0.0;
void changeBid() {
setState(() {
maxbid += 10.0;
});
}
@override
Widget build(BuildContext context) {
// TODO: implement build
return
Theme(
data: Theme.of(context).copyWith(canvasColor: Colors.white,buttonColor: Colors.blue),
child:
Column(
children: <Widget>[
new Directionality(textDirection: TextDirection.ltr, child: Text("your Current bid is $maxbid",)),
new Directionality(textDirection: TextDirection.ltr, child: FlatButton.icon(
onPressed: changeBid,
label: Text("Click to increase Bid",),
icon: Icon(Icons.add_circle)
)),
],
)
);
}
}
答案 0 :(得分:0)
任何窗口小部件都需要Material来构建窗口小部件,因此您可以通过仅将主题窗口小部件包装为Material窗口小部件来纠正它。
@override
Widget build(BuildContext context) {
return Material( //added widget
child: Theme(
data: Theme.of(context)