首页 > 解决方案 > 在颤动中使用堆栈时内容重叠

问题描述

import 'package:flutter/material.dart';
import 'package:flutter/painting.dart';

void main() => runApp(MaterialApp(
  home: Home(),
));`class Home extends StatelessWidget {
  @override
  Widget build(BuildContext context) {
    return Scaffold(

      appBar: AppBar(
        title: Text('GigoClean',
          style: TextStyle(
            fontFamily: 'Roboto',
          ),
        ),
        centerTitle: true,
        backgroundColor: Colors.cyanAccent[400],
      ),`body:  Center(
        child: Stack(
        children: <Widget>[
           Container(
            decoration: new BoxDecoration(
              image: new DecorationImage(image: new AssetImage("assets/bg.png"), fit: BoxFit.cover,),
            ),
          ),
          Container(
            padding: EdgeInsets.fromLTRB(0, 90.0, 0, 0),
            child: Image.asset('assets/intro.jpg'),
          ),
          Container(
              padding: EdgeInsets.fromLTRB(15, 40, 15, 0),
              child: Text('Get ready to make your life easy with single click of app, which makes your cleaning easy.' ,
              textAlign: TextAlign.center,),

我只想要一个背景图像,这就是我使用堆栈但它也与其他内容重叠的原因。请帮忙!!

标签: flutterdart

解决方案


您应该将其他两个 Container 放在 Column 或 Row 内以避免重叠。举个例子供大家理解:

Widget build(BuildContext context) {
return Scaffold(

  appBar: AppBar(
    title: Text('GigoClean',
      style: TextStyle(
        fontFamily: 'Roboto',
      ),
    ),
    centerTitle: true,
    backgroundColor: Colors.cyanAccent[400],
  ),`body:  Center(
    child: Stack(
    children: <Widget>[
       Container(
        decoration: new BoxDecoration(
          image: new DecorationImage(image: new AssetImage("assets/bg.png"), fit: BoxFit.cover,),
        ),
      ),
      Column(
        children: [
          Container(
            padding: EdgeInsets.fromLTRB(0, 90.0, 0, 0),
            child: Image.asset('assets/intro.jpg'),
          ),
          Container(
            padding: EdgeInsets.fromLTRB(15, 40, 15, 0),
            child: Text('Get ready to make your life easy with single click of app, which makes your cleaning easy.' ,
            textAlign: TextAlign.center,),

推荐阅读