在屏幕底部的背景图象在振翼app

宝剑锋从磨砺出,梅花香自苦寒来。这篇文章主要讲述在屏幕底部的背景图象在振翼app相关的知识,希望能为你提供帮助。
在我的颤动应用程序中,我正在尝试将背景图像放在屏幕的底部。我已经使用堆栈将背景与我的应用内容分开,并使用扩展容器的列将我的图像推到底部。
不幸的是,这种组合导致我的应用程序崩溃。如果我从背景中删除列,它可以正常工作。所以关于计算布局的事情就失败了。

import 'package:flutter/material.dart'; void main() => runApp(new MyApp()); class MyApp extends StatelessWidget { @override Widget build(BuildContext context) { return new MaterialApp( title: 'Flutter Demo', theme: new ThemeData( primarySwatch: Colors.grey, ), home: Scaffold( body: Background(), ), ); } }class Background extends StatelessWidget { @override Widget build(BuildContext context) { return Stack( children: < Widget> [ Column( children: < Widget> [ Expanded( child: Container(), ), Container( decoration: BoxDecoration( image: DecorationImage( image: AssetImage("assets/background.png"), fit: BoxFit.fitWidth, ), ), ), ], ), Center( child: Text("App content would be here"), ), ], ); } }

堆栈跟踪:
flutter: ══╡ EXCEPTION CAUGHT BY SERVICES ╞══════════════════════════════════════════════════════════════════ flutter: The following assertion was thrown resolving an image codec: flutter: Unable to load asset: assets/background.png flutter: flutter: When the exception was thrown, this was the stack: flutter: #0PlatformAssetBundle.load (package:flutter/src/services/asset_bundle.dart:221:7) flutter: < asynchronous suspension> flutter: #1AssetBundleImageProvider._loadAsync (package:flutter/src/painting/image_provider.dart:427:44) flutter: < asynchronous suspension> flutter: #2AssetBundleImageProvider.load (package:flutter/src/painting/image_provider.dart:412:14) flutter: #3ImageProvider.resolve.< anonymous closure> .< anonymous closure> (package:flutter/src/painting/image_provider.dart:266:86) flutter: #4ImageCache.putIfAbsent (package:flutter/src/painting/image_cache.dart:143:20) flutter: #5ImageProvider.resolve.< anonymous closure> (package:flutter/src/painting/image_provider.dart:266:63) flutter: #6SynchronousFuture.then (package:flutter/src/foundation/synchronous_future.dart:38:29) flutter: #7ImageProvider.resolve (package:flutter/src/painting/image_provider.dart:264:30) flutter: #8DecorationImagePainter.paint (package:flutter/src/painting/decoration_image.dart:239:55) flutter: #9_BoxDecorationPainter._paintBackgroundImage (package:flutter/src/painting/box_decoration.dart:395:19) flutter: #10_BoxDecorationPainter.paint (package:flutter/src/painting/box_decoration.dart:413:5) flutter: #11RenderDecoratedBox.paint (package:flutter/src/rendering/proxy_box.dart:1876:16) flutter: #12RenderObject._paintWithContext (package:flutter/src/rendering/object.dart:2024:7) flutter: #13PaintingContext.paintChild (package:flutter/src/rendering/object.dart:131:13) flutter: #14_RenderFlex& RenderBox& ContainerRenderObjectMixin& RenderBoxContainerDefaultsMixin.defaultPaint (package:flutter/src/rendering/box.dart:2222:15) flutter: #15RenderFlex.paint (package:flutter/src/rendering/flex.dart:931:7) flutter: #16RenderObject._paintWithContext (package:flutter/src/rendering/object.dart:2024:7) flutter: #17PaintingContext.paintChild (package:flutter/src/rendering/object.dart:131:13) flutter: #18_RenderStack& RenderBox& ContainerRenderObjectMixin& RenderBoxContainerDefaultsMixin.defaultPaint (package:flutter/src/rendering/box.dart:2222:15) flutter: #19RenderStack.paintStack (package:flutter/src/rendering/stack.dart:604:5) flutter: #20RenderStack.paint (package:flutter/src/rendering/stack.dart:612:7) flutter: #21RenderObject._paintWithContext (package:flutter/src/rendering/object.dart:2024:7) flutter: #22PaintingContext.paintChild (package:flutter/src/rendering/object.dart:131:13) flutter: #23_RenderCustomMultiChildLayoutBox& RenderBox& ContainerRenderObjectMixin& RenderBoxContainerDefaultsMixin.defaultPaint (package:flutter/src/rendering/box.dart:2222:15) flutter: #24RenderCustomMultiChildLayoutBox.paint (package:flutter/src/rendering/custom_layout.dart:360:5) flutter: #25RenderObject._paintWithContext (package:flutter/src/rendering/object.dart:2024:7) flutter: #26PaintingContext.paintChild (package:flutter/src/rendering/object.dart:131:13) flutter: #27_RenderProxyBox& RenderBox& RenderObjectWithChildMixin& RenderProxyBoxMixin.paint (package:flutter/src/rendering/proxy_box.dart:127:15) flutter: #28_RenderInkFeatures.paint (package:flutter/src/material/material.dart:456:11) flutter: #29RenderObject._paintWithContext (package:flutter/src/rendering/object.dart:2024:7) flutter: #30PaintingContext.paintChild (package:flutter/src/rendering/object.dart:131:13) flutter: #31_RenderProxyBox& RenderBox& RenderObjectWithChildMixin& RenderProxyBoxMixin.paint (package:flutter/src/rendering/proxy_box.dart:127:15) flutter: #32RenderPhysicalModel.paint (package:flutter/src/rendering/proxy_box.dart:1644:15) flutter: #33RenderObject._paintWithContext (package:flutter/src/rendering/object.dart:2024:7) flutter: #34PaintingContext.paintChild (package:flutter/src/rendering/object.dart:131:13) flutter: #35_RenderProxyBox& RenderBox& RenderObjectWithChildMixin& RenderProxyBoxMixin.paint (package:flutter/src/rendering/proxy_box.dart:127:15) flutter: #36RenderObject._paintWithContext (package:flutter/src/rendering/object.dart:2024:7) flutter: #37PaintingContext.paintChild (package:flutter/src/rendering/object.dart:131:13) flutter: #38_RenderProxyBox& RenderBox& RenderObjectWithChildMixin& RenderProxyBoxMixin.paint (package:flutter/src/rendering/proxy_box.dart:127:15) flutter: #39RenderObject._paintWithContext (package:flutter/src/rendering/object.dart:2024:7) flutter: #40PaintingContext.repaintCompositedChild (package:flutter/src/rendering/object.dart:111:11) flutter: #41PipelineOwner.flushPaint (package:flutter/src/rendering/object.dart:791:29) flutter: #42_WidgetsFlutterBinding& BindingBase& GestureBinding& ServicesBinding& SchedulerBinding& PaintingBinding& RendererBinding.drawFrame (package:flutter/src/rendering/binding.dart:272:19) flutter: #43_WidgetsFlutterBinding& BindingBase& GestureBinding& ServicesBinding& SchedulerBinding& PaintingBinding& RendererBinding& WidgetsBinding.drawFrame (package:flutter/src/widgets/binding.dart:627:13) flutter: #44_WidgetsFlutterBinding& BindingBase& GestureBinding& ServicesBinding& SchedulerBinding& PaintingBinding& RendererBinding._handlePersistentFrameCallback (package:flutter/src/rendering/binding.dart:208:5) flutter: #45_WidgetsFlutterBinding& BindingBase& GestureBinding& ServicesBinding& SchedulerBinding._invokeFrameCallback (package:flutter/src/scheduler/binding.dart:990:15) flutter: #46_WidgetsFlutterBinding& BindingBase& GestureBinding& ServicesBinding& SchedulerBinding.handleDrawFrame (package:flutter/src/scheduler/binding.dart:930:9) flutter: #47_WidgetsFlutterBinding& BindingBase& GestureBinding& ServicesBinding& SchedulerBinding._handleDrawFrame (package:flutter/src/scheduler/binding.dart:842:5) flutter: #48_invoke (dart:ui/hooks.dart:120:13) flutter: #49_drawFrame (dart:ui/hooks.dart:109:3) flutter: flutter: Image provider: AssetImage(bundle: null, name: "assets/background.png") flutter: Image key: AssetBundleImageKey(bundle: PlatformAssetBundle#3853b(), name: "assets/background.png", flutter: scale: 1.0) flutter: ════════════════════════════════════════════════════════════════════════════════════════════════════ Error -32000 received from application: Server error

有什么建议?这对Flutter来说是不可能的布局请求吗?
答案【在屏幕底部的背景图象在振翼app】你可以直接使用Image.assetalignment: Alignment.bottomCenter
Stack( children: < Widget> [ Positioned.fill( child: Image.asset( "assets/background.jpg", fit: BoxFit.fitWidth, alignment: Alignment.bottomLeft, ), ), Center( child: Text("App content would be here"), ) ], );


    推荐阅读