Flutter AppBar设置渐变色背景

主要是通过AppBar的属性:弹性空间flexibleSpace

class GradientPage extends StatelessWidget {
  @override
  Widget build(BuildContext context) {
    return Scaffold(
      appBar: AppBar(
        title: const Text('Gradient AppBar', style: Styles.pageTitle),
        centerTitle: true,
        flexibleSpace: Container(
          decoration: BoxDecoration(
            gradient: LinearGradient(colors: [
              Color(0xFF0018EB),
              Color(0xFF01C1D9),
            ], begin: Alignment.bottomCenter, end: Alignment.topCenter),
          ),
        ),
      ),
      body: Center(
        child: Text('内容'),
      ),
    );
  }
}

Flutter AppBar设置渐变色背景_第1张图片

你可能感兴趣的:(Flutter)