簡體   English   中英

從 Flutter 中的 Scaffold AppBar 中刪除投影?

[英]Removing the drop shadow from a Scaffold AppBar in Flutter?

在 Flutter 中使用 Scaffold 小部件時,有沒有辦法刪除應用欄(AppBar 類)下的投影?

查看AppBar構造函數,有一個elevation屬性可用於設置應用欄的高度,從而設置陰影投射量。 將此設置為零會刪除陰影:

  @override
  Widget build(BuildContext context) {
    return Scaffold(
      appBar: AppBar(
        title: const Text('My App Title'),
        elevation: 0,
      ),
      body: const Center(
        child: Text('Hello World'),
      ),
    );
  }

在此處輸入圖像描述

我試過一些可能對你有幫助的東西

AppBar(
backgroundColor: Colors.transparent,
bottomOpacity: 0.0,
elevation: 0.0,
),

看一下這個

如果您想在不重復代碼的情況下刪除所有應用欄的陰影,只需在您的應用程序主題( ThemeData )中添加一個帶有elevation: 0AppBarTheme屬性,在您的MaterialApp小部件內:

// This code should be located inside your "MyApp" class, or equivalent (in main.dart by default)
return MaterialApp(
  // App Theme:
  theme: ThemeData(
    // ••• ADD THIS: App Bar Theme: •••
    appBarTheme: AppBarTheme(
      elevation: 0, // This removes the shadow from all App Bars.
    )
  ),
);

在Flutter中使用Scaffold小部件時,是否可以刪除應用欄(AppBar類)下的陰影?

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM