Warning: file_get_contents(/data/phpspider/zhask/data//catemap/5/flutter/9.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/7/user-interface/2.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Flutter 背景图像未设置为白色|为文本添加样式_Flutter - Fatal编程技术网

Flutter 背景图像未设置为白色|为文本添加样式

Flutter 背景图像未设置为白色|为文本添加样式,flutter,Flutter,这里有两个问题。。。在我走的过程中,仍然是一个新的学习者 我的背景色不会变为白色。flatter.dev上的所有资源似乎都不可行。目前,我使用的是建议最多的答案,即backgroundColor:Colors.white。有没有想过为什么这不起作用 类应用程序扩展了无状态小部件{ @override Widget build(BuildContext context) { return MaterialApp( title: 'Onboarding1',

这里有两个问题。。。在我走的过程中,仍然是一个新的学习者

  • 我的背景色不会变为白色。flatter.dev上的所有资源似乎都不可行。目前,我使用的是建议最多的答案,即
    backgroundColor:Colors.white
    。有没有想过为什么这不起作用
  • 类应用程序扩展了无状态小部件{

      @override
      Widget build(BuildContext context) {
        return MaterialApp(
          title: 'Onboarding1',
          theme: ThemeData(
            backgroundColor: Colors.white,
            fontFamily: 'fonts/Avenir-Bold',
            visualDensity: VisualDensity.adaptivePlatformDensity,
          ),
        );
      }
    }```
    
  • 我希望能够设置列中文本的样式,但TextStle抛出了一个错误。在列中调整文本样式的最佳方法是什么?最好使用脚手架吗
  • @凌驾

      Widget build(BuildContext context) {
        return Column(
          children: <Widget>[
            Image.asset(
              "assets/Onboarding1_Photo.png",
              height: MediaQuery.of(context).size.height * 0.7,
              width: MediaQuery.of(context).size.width,
              fit: BoxFit.cover,
            ),
            Column(
              children: <Widget>[
                Text('Some Text'),
                style: TextStyle(
                )
              ],
            )
          ],
        );
      }
    }
    
    小部件构建(构建上下文){
    返回列(
    儿童:[
    影像资产(
    “assets/Onboarding1_Photo.png”,
    高度:MediaQuery.of(上下文).size.height*0.7,
    宽度:MediaQuery.of(context).size.width,
    适合:BoxFit.cover,
    ),
    纵队(
    儿童:[
    文本(“某些文本”),
    样式:TextStyle(
    )
    ],
    )
    ],
    );
    }
    }
    
    根据答案更新。。。我到底做错了什么

    class App extends StatelessWidget {
      @override
      Widget build(BuildContext context) {
        return MaterialApp(
          title: 'Onboarding1',
          theme: ThemeData(
            scaffoldBackgroundColor: Colors.white,
            fontFamily: 'fonts/Avenir-Bold',
            visualDensity: VisualDensity.adaptivePlatformDensity,
          ),
        );
      }
    }
    
    class Onboarding1 extends StatelessWidget {
      @override
      Widget build(BuildContext context) {
        return Scaffold(
          body: Column(
            children: [
              Image.asset(
                "assets/Onboarding1_Photo.png",
                height: MediaQuery.of(context).size.height * 0.7,
                width: MediaQuery.of(context).size.width,
                fit: BoxFit.cover,
              ),
              Column(
                children: <Widget>[
                  Text('Some Text', style: TextStyle(fontSize: 24)),
                ],
              ),
            ],
          ),
        );
      }
    }
    
    类应用程序扩展了无状态小部件{
    @凌驾
    小部件构建(构建上下文){
    返回材料PP(
    标题:'Onboarding1',
    主题:主题数据(
    脚手架背景颜色:颜色。白色,
    fontFamily:'fonts/Avenir Bold',
    视觉密度:视觉密度。自适应平台密度,
    ),
    );
    }
    }
    类Onboarding1扩展了无状态小部件{
    @凌驾
    小部件构建(构建上下文){
    返回脚手架(
    正文:专栏(
    儿童:[
    影像资产(
    “assets/Onboarding1_Photo.png”,
    高度:MediaQuery.of(上下文).size.height*0.7,
    宽度:MediaQuery.of(context).size.width,
    适合:BoxFit.cover,
    ),
    纵队(
    儿童:[
    Text('Some Text',style:TextStyle(fontSize:24)),
    ],
    ),
    ],
    ),
    );
    }
    }
    
    用示例更新了答案:

    class Onboarding1 extends StatelessWidget {
      @override
      Widget build(BuildContext context) {
        return Scaffold(
          body: Column(
            children: [
              Image.asset(
                "assets/Onboarding1_Photo.png",
                height: MediaQuery.of(context).size.height * 0.7,
                width: MediaQuery.of(context).size.width,
                fit: BoxFit.cover,
              ),
              Column(
                children: <Widget>[
                  Text('Some Text', style: TextStyle(fontSize: 24)),
                ],
              ),
            ],
          ),
        );
      }
    }
    
    
    然后用脚手架把你的柱子包起来,它就可以工作了

    至于文本样式,在代码中,
    样式
    在文本小部件的外部,它需要在内部,您需要使用属性定义一个
    文本样式

    Text('Some Text',
     style: TextStyle(
      color: Colors.blue, 
      fontSize: 20),
    ),
    
    诚然,对我的口味来说,在Flutter中设置文本样式有点冗长。出于这个原因,我有自己的自定义文本小部件,它可以在我最常用的文本属性上节省时间

    class MyTextWidget extends StatelessWidget {
      final String text;
      final double fontSize;
      final Color color;
      final double spacing;
    
      const MyTextWidget(
          {Key key, this.text, this.fontSize, this.color, this.spacing})
          : super(key: key);
      @override
      Widget build(BuildContext context) {
        return Text(
          text != null ? text : ' ',
    
    // this is part of the google fonts package it won't work if you don't have it in your project but you get the idea
    
          style: kGoogleFontOpenSansCondensed.copyWith(
              fontSize: fontSize ?? 20,
              color: color ?? Colors.white70,
              letterSpacing: spacing ?? 1.0),
        );
      }
    }
    
    然后,当我需要一个文本小部件时,它看起来是这样的

    MyTextWidget(
       text: 'Some text', 
       fontSize: 25, 
       color: Colors.white54)
    

    你能检查一下对我原来帖子的编辑吗?我还做错了什么?你把脚手架放在柱子里,柱子需要放在脚手架里。一般来说,
    Scaffold
    将是任何基本页面的根窗口小部件。也不确定使用透明背景的容器要实现什么。但是根据我回答的另一篇帖子,我建议从脚手架->专栏->图片开始,就像我在另一个帖子中所做的那样,然后从那里开始。将容器设置为无限高和无限宽也可能会导致问题。只是尝试完成您回答的另一个问题中的设计。我将尝试脚手架、柱、图像方法。谢谢还要注意在列中列出孩子的顺序。根据你的另一篇文章,你想把图片放在屏幕的顶部,这里你有了图片上方的文本小部件。如果仍然希望图像位于顶部,则它必须是列中的第一个子级。
    MyTextWidget(
       text: 'Some text', 
       fontSize: 25, 
       color: Colors.white54)