我刚开始使用flutter并使用默认配置创建了一个空白应用,当我打开开发人员选项的显示布局边界时,它没有像其他任何应用一样显示任何边界。
这是怎么回事?
答案 0 :(得分:1)
要显示Flutter应用程序开发人员选项中的布局边界,我们必须这样做
将此包导入main.dart类。
import'package:flutter / rendering.dart';
在build()或main()中,您必须将此“ debugPaintSizeEnabled”变量设置为true。
debugPaintSizeEnabled = true;
示例:这是我的完整课程
import 'package:flutter/material.dart';
import 'package:flutter/rendering.dart';
void main()
{
runApp(MyApp());
}
class MyApp extends StatelessWidget {
// This widget is the root of your application.
@override
Widget build(BuildContext context) {
debugPaintSizeEnabled = true;
return MaterialApp(
title: 'Flutter Demo',
theme: ThemeData(
primarySwatch: Colors.blue,
),
home: MyHomePage(title: 'Flutter Demo Home Page'),
);
}
}
class MyHomePage extends StatefulWidget {
MyHomePage({Key key, this.title}) : super(key: key);
final String title;
@override
_MyHomePageState createState() => _MyHomePageState();
}
class _MyHomePageState extends State<MyHomePage> {
int _counter = 0;
void _incrementCounter() {
setState(() {
_counter++;
});
}
@override
Widget build(BuildContext context) {
return Scaffold(
appBar: AppBar(
title: Text(widget.title),
),
body: Center(
child: Column(
mainAxisAlignment: MainAxisAlignment.center,
children: <Widget>[
Text(
'You have pushed the button this many times:',
),
Text(
'$_counter',
style: Theme.of(context).textTheme.display1,
),
],
),
),
floatingActionButton: FloatingActionButton(
onPressed: _incrementCounter,
tooltip: 'Increment',
child: Icon(Icons.add),
),
);
}
}