【发布时间】:2021-04-06 10:24:52
【问题描述】:
大家好,我正在尝试将 Column 转换为可滚动我尝试在 SingleChildScrollView 中扭曲 Column(删除所有展开的小部件)但我收到错误我将列转换为 ListView(删除所有展开的小部件)但我得到一个错误。
有没有办法保留展开的小部件?
那么有人可以帮助我吗?请
这是我的代码
@override
Widget build(BuildContext context) {
return Scaffold(
resizeToAvoidBottomInset: false,
floatingActionButton: buttonTheme,
drawer: SideMenu(),
appBar: AppBar(
actions: [
Padding(
padding: EdgeInsets.all(8.0),
child: DropdownButton(
underline: SizedBox(),
icon: Icon(
Icons.language,
color: Colors.white,
),
items: AppLanguage.languageList()
.map<DropdownMenuItem<AppLanguage>>(
(lang) => DropdownMenuItem(
value: lang,
child: Row(
mainAxisAlignment: MainAxisAlignment.spaceAround,
children: [Text(lang.flag), Text(lang.name)],
),
),
)
.toList(),
onChanged: (AppLanguage language) {
_changeLanguage(language);
},
),
)
],
centerTitle: true,
//automaticallyImplyLeading: false,
title: Text(
getTranslation(context, 'main_app_bar'),
style: TextStyle(
fontSize: 20,
),
),
),
body: Center(
child: SafeArea(
child: Column(
children: <Widget>[
Expanded(
flex: 1,
child: WeatherWidget(
deglaPalmsWeatherData: widget.deglaPalmsWeather,
),
),
Expanded(
flex: 1,
child: Column(
children: [
Expanded(
flex: 2,
child: Row(
children: [
SizedBox(
width: 20,
),
Expanded(
flex: 1,
child: MapWidget(),
),
SizedBox(
width: 10,
),
Expanded(
flex: 1,
child: ServicesWidget(),
),
SizedBox(
width: 20,
)
],
),
),
Expanded(
flex: 2,
child: Row(
children: [
SizedBox(
width: 20,
),
Expanded(
flex: 1,
child: InfoWidget(),
),
SizedBox(
width: 10,
),
Expanded(
flex: 1,
child: BusWidget(),
),
SizedBox(
width: 20,
),
],
),
),
Expanded(
flex: 1,
child: SoonWidget(),
),
],
),
),
DCCopyRights(),
],
),
),
),
bottomNavigationBar: Container(
height: bannerHeight,
),
);
}
【问题讨论】:
-
尝试用
Expanded包裹你的专栏 -
@FahmiSawalha 使用哪个小部件 SingleChildScrollView 或 ListView ?
-
我认为你应该使用 singleChildScrollView
-
@FahmiSawalha 不工作我收到此错误
Usually, this means that the Expanded widget has the wrong ancestor RenderObjectWidget. Typically, Expanded widgets are placed directly inside Flex widgets. The offending Expanded is currently placed inside a _SingleChildViewport widget.