如何调整主要属性内的图像大小?

Mus*_*ola 6 image flutter

我试图在应用程序栏中的标题之前添加一个徽标,但图像似乎只采用前导属性的宽度和高度。

import 'package:flutter/material.dart';

class Home extends StatelessWidget {
  Widget build(context){
      return Scaffold(
        appBar: AppBar(
          title:Text('Hi, Andi Loshi'),
          backgroundColor: Color.fromRGBO(230, 1, 1,1),
          leading:  new Image.asset("assets/images/logo.png",
          fit:BoxFit.cover,
          height:20.00,
          width:20.00
          ),
        ),
        body: Text('Body will reside here')
      );
  }
}
Run Code Online (Sandbox Code Playgroud)

小智 5

虽然您无法修改行距的大小,但您可以在应用栏中的标题之前添加图像,如下所示,标题请检查下面的代码。

import 'package:flutter/material.dart';

void main() => runApp(Home());

class Home extends StatelessWidget {
  Widget build(context) {
    return MaterialApp(
      home: Scaffold(
        appBar: AppBar(
          title: Container(
            child: Row(
              children: [
                Image.asset(
                  "assets/images/logo.png",
                  fit: BoxFit.cover,
                ),
                SizedBox(
                  width: 10,
                ),
                Text('Hi, Andi Loshi')
              ],
            ),
          ),
          backgroundColor: Color.fromRGBO(230, 1, 1, 1),
        ),
        body: Text('Body will reside here'),
      ),
    );
  }
}
Run Code Online (Sandbox Code Playgroud)


ozi*_*iem 5

@Mussa Kalokola,您可以用填充将图像包裹起来,使其变小。

我认为这是最简单的解决方案。

例如。

appBar: AppBar(
    title: Text(_getScreenTitle(context, _selected)),
    leading: const Padding(
      padding: EdgeInsets.all(16.0),
      child: ClipOval(
        child: Image(
          image: AssetImage('images/test.png'),
        ),
      ),
    ),
  ),
Run Code Online (Sandbox Code Playgroud)