简体   繁体   中英

How can i resize image.network in appbar

I want image at center in appbar and resize to bigger. I tried use width and height but it's death code.

class HomeScreen extends StatelessWidget {
  @override
  Widget build(BuildContext context) {
    //ใช้ context
    return MaterialApp(
      //ใช้ MaterialApp
      home: Scaffold(
        //ใช้ Scaffold
        appBar: BuildAppBar(),
        //สร้าง AppBar
        body: Center(child: Text('Hi')), //ใช้ Text แสดงข้อความตรงกลางจอ
      ),
    );
  }

  AppBar BuildAppBar() {
    return AppBar(
      leading: Container(
        padding: const EdgeInsets.all(0),
        child: Image.network(
            'http://www.sr...i can't open this url to pubic'),
        width: 100,
        height: 100,
      ),
    );
  }
}

This's result in debug mode right now.

If you want to add a image to center of appBar, you can use this code;

appBar: AppBar(
        title: Row(
          mainAxisAlignment: MainAxisAlignment.center,
          children: [
            Image.network(
              'https://picsum.photos/250?image=9',
              fit: BoxFit.contain,
              height: 60,
              errorBuilder: (context, error, stackTrace) =>
                  const Icon(Icons.error_outline_outlined),
            ),
            Container()
          ],
        ),
      ),

Try this:

 return AppBar(
  centerTitle: true,
  toolbarHeight: 100,
  title: Image.network(
    imageUrl,
    width: 100,
    height: 100,
  ),
);

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM