0
点赞
收藏
分享

微信扫一扫

如何在 Flutter 中创建渐变背景 AppBar# yyds干货盘点 #

如何在 Flutter 中创建渐变背景 AppBar

渐变可帮助您显示两种或多种颜色之间的平滑过渡。下面的示例将向您展示如何在 Flutter 中创建具有渐变背景的应用栏。我们可以在不使用任何第三方插件的情况下实现目标。


如何在 Flutter 中创建渐变背景 AppBar# yyds干货盘点 #_flutter

import 'package:flutter/material.dart';

void main() {
runApp(const MyApp());
}

class MyApp extends StatelessWidget {
const MyApp({Key? key}) : super(key: key);
@override
Widget build(BuildContext context) {
return const MaterialApp(
// Remove the debug banner
debugShowCheckedModeBanner: false,
title: '大前端之旅',
home: HomePage());
}
}

class HomePage extends StatelessWidget {
const HomePage({Key? key}) : super(key: key);
@override
Widget build(BuildContext context) {
return Scaffold(
// implement the app bar
appBar: AppBar(
title: const Text('大前端之旅'),
flexibleSpace: Container(
decoration: const BoxDecoration(
gradient: LinearGradient(
begin: Alignment.centerLeft,
end: Alignment.centerRight,
colors: [Colors.red, Colors.orange, Colors.indigo]),
),
),
),
);
}
}

我们的 AppBar 具有渐变背景颜色。

举报

相关推荐

0 条评论