我在一个小部件中使用了SliverAppBar,其代码如下所示;
import 'package:flutter/material.dart';
class MyWidget extends StatelessWidget {
const MyWidget({super.key});
@override
Widget build(BuildContext context) {
return Scaffold(
body: CustomScrollView(
physics: const BouncingScrollPhysics(),
slivers: [
SliverAppBar(
pinned: true,
floating: false,
snap: false,
backgroundColor: Theme.of(context).appBarTheme.backgroundColor,
elevation: 1,
expandedHeight: 100.0,
flexibleSpace: FlexibleSpaceBar(
background: Image.asset(
'assets/images/content/Update.png',
fit: BoxFit.cover,
),
),
),
SliverList(
delegate: SliverChildBuilderDelegate(
(context, index) => ListTile(title: Text('Item #$index')),
childCount: 1000,
),
)
],
),
);
}
}
我的主题数据已配置为如下所示;
final theme = ThemeData(
useMaterial3: true,
colorScheme: ColorScheme.fromSeed(
seedColor: const Color.fromARGB(255, 41, 41, 41),
primary: const Color.fromARGB(255, 41, 41, 41),
primaryContainer: const Color.fromARGB(20, 41, 41, 41),
secondary: const Color.fromARGB(255, 80, 80, 80),
background: const Color.fromARGB(255, 255, 255, 255),
),
textTheme: GoogleFonts.poppinsTextTheme(),
appBarTheme: const AppBarTheme(
backgroundColor: Color.fromARGB(255, 255, 255, 255),
),
splashFactory: NoSplash.splashFactory,
);
当我滚动时,SliverAppBar有一种奇怪的蓝色色彩,我不知道为什么会这样,也不知道为什么会这样.我希望应用程序栏有背景的 colored颜色 或只是"透明",以便它看起来像是作为一个单一的单位整个页面的一部分.目前,与整个页面相比,它看起来是另一回事.
另一个解决办法是创建一个定制的appbar,当检测到滚动时,它将"固定"到顶部,但我想使用appbar方法.