Home > Mobile >  How can i resize image.network in appbar
How can i resize image.network in appbar

Time:07-03

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.

CodePudding user response:

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()
          ],
        ),
      ),

CodePudding user response:

Try this:

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