我有一個應用程式。在計算機上的模擬器上,它應該正常顯示,但在真機上顯示不同。
模擬器:

真實電話:

為什么會這樣?我該如何解決?
代碼:
Scaffold(
floatingActionButton: FloatingActionButton(
child: Text("FAB"),
onPressed: () {},
),
body: Padding(
padding: EdgeInsets.only(left: 8, right: 8, bottom: 40),
child: Column(
children: [
SizedBox(height: 15,),
Text("Profile", style: TextStyle(fontSize: 27),),
Divider(thickness: 1, color: Colors.black,),
SizedBox(height: 5),
Row(
crossAxisAlignment: CrossAxisAlignment.start,
children: [
Text("Solved Tests:",style: TextStyle(fontSize: 19)),
],
),
SizedBox(height: 20,),
Container(
width: double.infinity,
height: MediaQuery.of(context).size.height/4,
child: Expanded(
child: FutureBuilder(
future: listUpload(),
builder: (BuildContext context, AsyncSnapshot snapshot) {
late List<String?> items;
if (!snapshot.hasData){
return Text("Bulunamad?");
}
if (snapshot.connectionState == ConnectionState.waiting) {
items = [];
} else if (snapshot.connectionState == ConnectionState.done &&
snapshot.hasData) {
items = snapshot.data as List<String?>;
} else {
items = [];
}
return Scrollbar(
isAlwaysShown: true,
controller: _scrollContreller,
scrollbarOrientation: ScrollbarOrientation.right,
child: ListView.builder(
controller: _scrollContreller,
itemCount: items.length,
itemBuilder: (BuildContext context, int index) {
return Padding(
padding: const EdgeInsets.only(bottom: 20, left: 10, right: 10),
child: Container(
decoration: BoxDecoration(
color: Colors.grey[300],
borderRadius: BorderRadius.circular(10),
),
child: ListTile(
title: Text(
items[index].toString(),
style: TextStyle(fontSize: 20),
),
),
),
);
},
),
);
})),
),
Container(
decoration: BoxDecoration(
color: Colors.red,
borderRadius: BorderRadius.circular(10),
),
),
SizedBox(height: 15,),
Center(
child: Row(
mainAxisAlignment: MainAxisAlignment.center,
children: [
Padding(
padding: const EdgeInsets.only(left: 10),
child: Container(
width: 250,
height: 40,
child: GFButton(
text: "Temizle", textStyle: TextStyle(fontSize: 20, color: Colors.red),
color: Colors.red,
type: GFButtonType.outline2x,
onPressed: () {
AlertDialog eminlik = AlertDialog(
title: Text("Onay"),
content: Text("??zdü?ünüz testlerin kay?tlar? silinecektir. Emin misiniz?"),
actions: [
FlatButton(
child: Text("Evet"),
onPressed: () {
Navigator.pop(context);
setState(() {
eminlikSil();
});
},
),
FlatButton(
child: Text("Hay?r"),
onPressed: () {
Navigator.pop(context);
},
)
],
);
showDialog(context: context, builder: (context) => eminlik);
},
),
),
),
],
),
),
],
),
),
),
我不明白為什么會這樣,但很可能存在尺寸問題。在此先感謝您的幫助。
PS:我在幾部手機上都試過了,所有手機都是這樣。
當我運行它時,我會收到這樣的警告:
════════ Exception caught by widgets library ═══════════════════════════════════
The following assertion was thrown while applying parent data.:
Incorrect use of ParentDataWidget.
The ParentDataWidget Expanded(flex: 1) wants to apply ParentData of type FlexParentData to a RenderObject, which has been set up to accept ParentData of incompatible type ParentData.
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 ConstrainedBox widget.
The ownership chain for the RenderObject that received the incompatible parent data was:
RichText ← Text ← FutureBuilder<dynamic> ← Expanded ← ConstrainedBox ← Container ← Column ← Padding ← _BodyBuilder ← MediaQuery ← ?
When the exception was thrown, this was the stack
#0 RenderObjectElement._updateParentData.<anonymous closure>
#1 RenderObjectElement._updateParentData
#2 RenderObjectElement.attachRenderObject
#3 RenderObjectElement.mount
#4 MultiChildRenderObjectElement.mount
... Normal element mounting (30 frames)
#34 Element.inflateWidget
#35 MultiChildRenderObjectElement.inflateWidget
#36 MultiChildRenderObjectElement.mount
... Normal element mounting (22 frames)
#58 Element.inflateWidget
#59 MultiChildRenderObjectElement.inflateWidget
#60 MultiChildRenderObjectElement.mount
... Normal element mounting (117 frames)
#177 Element.inflateWidget
#178 Element.updateChild
#179 SliverMultiBoxAdaptorElement.updateChild
#180 SliverMultiBoxAdaptorElement.createChild.<anonymous closure>
#181 BuildOwner.buildScope
#182 SliverMultiBoxAdaptorElement.createChild
#183 RenderSliverMultiBoxAdaptor._createOrObtainChild.<anonymous closure>
#184 RenderObject.invokeLayoutCallback.<anonymous closure>
#185 PipelineOwner._enableMutationsToDirtySubtrees
#186 RenderObject.invokeLayoutCallback
#187 RenderSliverMultiBoxAdaptor._createOrObtainChild
#188 RenderSliverMultiBoxAdaptor.insertAndLayoutChild
#189 RenderSliverFixedExtentBoxAdaptor.performLayout
#190 RenderObject.layout
#191 RenderSliverEdgeInsetsPadding.performLayout
#192 _RenderSliverFractionalPadding.performLayout
#193 RenderObject.layout
#194 RenderViewportBase.layoutChildSequence
#195 RenderViewport._attemptLayout
#196 RenderViewport.performLayout
#197 RenderObject._layoutWithoutResize
#198 PipelineOwner.flushLayout
#199 RendererBinding.drawFrame
#200 WidgetsBinding.drawFrame
#201 RendererBinding._handlePersistentFrameCallback
#202 SchedulerBinding._invokeFrameCallback
#203 SchedulerBinding.handleDrawFrame
#204 SchedulerBinding._handleDrawFrame
#208 _invoke (dart:ui/hooks.dart:150:10)
#209 PlatformDispatcher._drawFrame (dart:ui/platform_dispatcher.dart:270:5)
#210 _drawFrame (dart:ui/hooks.dart:114:31)
(elided 3 frames from dart:async)
════════════════════════════════════════════════════════════════════════════════
════════ Exception caught by widgets library ═══════════════════════════════════
Incorrect use of ParentDataWidget.
════════════════════════════════════════════════════════════════════════════════
uj5u.com熱心網友回復:
Expanded
不應該在容器中。它必須在行/列中。
轉載請註明出處,本文鏈接:https://www.uj5u.com/net/442453.html
