【发布时间】:2022-01-01 02:33:37
【问题描述】:
我正在尝试将扩展小部件用于示例项目。我在列小部件中嵌入了一行作为 chldren 。在行内,我使用了带有 flex 属性的扩展小部件。但是在删除 Expanded 后,我无法在屏幕上看到任何内容。 我尝试将 Expanded 放在列之前,它也显示相同的错误。 这是我的代码:-
import 'package:flutter/material.dart';
void main() => runApp(
const MaterialApp(home: MyApp())
);
class MyApp extends StatefulWidget {
const MyApp({Key? key}) : super(key: key);
@override
_MyAppState createState() => _MyAppState();
}
class _MyAppState extends State<MyApp> {
@override
Widget build(BuildContext context) {
return Scaffold(
appBar: AppBar(
title: const Text('Expanded Column Sample'),
),
body: Container(
child: Column(
mainAxisAlignment: MainAxisAlignment.center,
children:[
Row(
mainAxisAlignment: MainAxisAlignment.center,
children: <Widget>[
Expanded(
flex:6,
child: Container(
color: Colors.green,
),
),
Expanded(
flex:6,
child: Container(
color: Colors.deepOrange,
),
),
Expanded(
flex:6,
child: Container(
color: Colors.white,
),
),
Expanded(
flex:6,
child: Container(
color: Colors.lightGreenAccent,
),
),
Expanded(
flex:6,
child: Container(
color: Colors.blue,
),
),
Expanded(
flex:6,
child: Container(
color: Colors.red,
),
),
],
),
]
),
),
);
}
}
【问题讨论】: