gpt4 book ai didi

android - 布局边界未在 Flutter 应用程序中显示,但它显示在其他应用程序中

转载 作者:IT王子 更新时间:2023-10-29 06:36:24 25 4
gpt4 key购买 nike

我刚开始使用 Flutter 并使用默认配置创建了一个空白应用程序,当我从开发人员选项中打开显示布局边界时,它没有像任何其他应用程序那样显示任何边界。

这是怎么回事?

最佳答案

要在 Flutter 应用的开发者选项中显示布局边界,我们必须这样做

  1. main.dart 类中导入这个包。

    import 'package:flutter/rendering.dart';
  2. build()main() 中,您必须将此 debugPaintSizeEnabled 变量设置为 true.

    debugPaintSizeEnabled = true;

示例:这是我的完整类(class)

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),
),
);
}
}

关于android - 布局边界未在 Flutter 应用程序中显示,但它显示在其他应用程序中,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/54821625/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com