微信交流群

老孟公众号

# 聊天气泡(.9图实现)

Container(
  width: 200,
  padding: EdgeInsets.only(left: 8,top: 8,right: 20,bottom: 8),
  decoration: BoxDecoration(
      image: DecorationImage(
          centerSlice: Rect.fromLTWH(20, 20, 1, 1),
          image: AssetImage(
            'assets/images/chat.png',
          ),
          fit: BoxFit.fill)),
  child: Text('老孟,专注分享Flutter技术和应用实战。'
      '老孟,专注分享Flutter技术和应用实战。'
      '老孟,专注分享Flutter技术和应用实战。',),
)
1
2
3
4
5
6
7
8
9
10
11
12
13
14

背景图片大小是57x80:

右侧三角已经不在中间了,如果想让其一直保持居中,修改拉伸区域:

centerSlice: Rect.fromLTWH(20, 10, 1, 60),
1

# 圆形带边框的头像

Container(
  width: 100,
  height: 100,
  padding: EdgeInsets.all(3),
  decoration: BoxDecoration(shape: BoxShape.circle, color: Colors.blue),
  child: Container(
    decoration: BoxDecoration(
        shape: BoxShape.circle,
        image: DecorationImage(
            image: AssetImage('assets/images/aa.jpg'), fit: BoxFit.cover)),
  ),
)
1
2
3
4
5
6
7
8
9
10
11
12

# 图片占位符:

Image.network(
  'https://flutter.github.io/assets-for-api-docs/assets/widgets/puffin.jpg',
  height: 150,
  width: 150,
  fit: BoxFit.cover,
  frameBuilder: (
    BuildContext context,
    Widget child,
    int frame,
    bool wasSynchronouslyLoaded,
  ) {
    if (frame == null) {
      return Image.asset(
        'assets/images/place.png',
        height: 150,
        width: 150,
        fit: BoxFit.cover,
      );
    }
    return child;
  },
)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22