在Flutter中使用BottomNavigationBar,如何设置背景图像,而不仅仅是使用颜色?

时间:2020-03-23 19:06:04

标签: flutter

我想为BottomNavigationBar的背景使用图像,但是我什么都没找到。有什么建议吗?建议的唯一属性是backgroundColor,它只需要一个Color即可。

1 个答案:

答案 0 :(得分:3)

import 'package:flutter/material.dart';

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

class MyApp extends StatelessWidget {
  @override
  Widget build(BuildContext context) {
    return MaterialApp(
      home: Scaffold(
        bottomNavigationBar: Container(
          decoration: BoxDecoration(
            image: DecorationImage(image: AssetImage('images/img.png'), fit: BoxFit.fill),
          ),
          child: BottomNavigationBar(
            backgroundColor: Colors.transparent,
            elevation: 0,
            items: [
              BottomNavigationBarItem(icon: Icon(Icons.add), title: Text('title')),
              BottomNavigationBarItem(icon: Icon(Icons.remove), title: Text('title')),
            ],
          ),
        ),
      ),
    );
  }
}

enter image description here