【Flutter】Flutter 應用主題 ( ThemeData | 動態修改主題 )

      網友投稿 966 2025-03-31

      文章目錄


      一、flutter 應用主題

      二、完整代碼示例

      三、相關資源

      一、flutter 應用主題

      Flutter 應用主題都封裝在 ThemeData 類中 , 在 MaterialApp 的 theme 字段 , 可以設置 ThemeData 主題 , 可設置的選項如下 , 下面的 ThemeData 工廠構造函數中的可選參數就是可以設置的各種主題選項 ;

      class ThemeData extends Diagnosticable { factory ThemeData({ Brightness brightness, MaterialColor primarySwatch, Color primaryColor, Brightness primaryColorBrightness, Color primaryColorLight, Color primaryColorDark, Color accentColor, Brightness accentColorBrightness, Color canvasColor, Color scaffoldBackgroundColor, Color bottomAppBarColor, Color cardColor, Color dividerColor, Color focusColor, Color hoverColor, Color highlightColor, Color splashColor, InteractiveInkFeatureFactory splashFactory, Color selectedRowColor, Color unselectedWidgetColor, Color disabledColor, Color buttonColor, ButtonThemeData buttonTheme, ToggleButtonsThemeData toggleButtonsTheme, Color secondaryHeaderColor, Color textSelectionColor, Color cursorColor, Color textSelectionHandleColor, Color backgroundColor, Color dialogBackgroundColor, Color indicatorColor, Color hintColor, Color errorColor, Color toggleableActiveColor, String fontFamily, TextTheme textTheme, TextTheme primaryTextTheme, TextTheme accentTextTheme, InputDecorationTheme inputDecorationTheme, IconThemeData iconTheme, IconThemeData primaryIconTheme, IconThemeData accentIconTheme, SliderThemeData sliderTheme, TabBarTheme tabBarTheme, TooltipThemeData tooltipTheme, CardTheme cardTheme, ChipThemeData chipTheme, TargetPlatform platform, MaterialTapTargetSize materialTapTargetSize, bool applyElevationOverlayColor, PageTransitionsTheme pageTransitionsTheme, AppBarTheme appBarTheme, BottomAppBarTheme bottomAppBarTheme, ColorScheme colorScheme, DialogTheme dialogTheme, FloatingActionButtonThemeData floatingActionButtonTheme, Typography typography, CupertinoThemeData cupertinoOverrideTheme, SnackBarThemeData snackBarTheme, BottomSheetThemeData bottomSheetTheme, PopupMenuThemeData popupMenuTheme, MaterialBannerThemeData bannerTheme, DividerThemeData dividerTheme, ButtonBarThemeData buttonBarTheme, }) }

      1

      2

      3

      4

      5

      6

      7

      8

      9

      10

      11

      12

      13

      14

      15

      16

      17

      18

      19

      20

      21

      22

      23

      24

      25

      26

      27

      28

      29

      30

      31

      32

      33

      34

      35

      36

      37

      38

      39

      40

      41

      42

      43

      44

      45

      46

      47

      48

      49

      50

      【Flutter】Flutter 應用主題 ( ThemeData | 動態修改主題 )

      51

      52

      53

      54

      55

      56

      57

      58

      59

      60

      61

      62

      63

      64

      65

      66

      67

      68

      如下代碼中就設置了 MaterialApp 的主題 ThemeData , brightness 字段設置的是主題模式 , 這里設置的是 Brightness.light 日間模式 ;

      primarySwatch 字段設置的是主題的主要顏色 , 這里設置的是藍色 ;

      import 'package:flutter/material.dart'; class ThemePage extends StatefulWidget { @override _ThemePageState createState() => _ThemePageState(); } class _ThemePageState extends State { @override Widget build(BuildContext context) { return MaterialApp( title: "Theme 主題修改", theme: ThemeData( brightness: Brightness.light, primarySwatch: Colors.blue, ), home: , ); } }

      1

      2

      3

      4

      5

      6

      7

      8

      9

      10

      11

      12

      13

      14

      15

      16

      17

      18

      19

      20

      21

      22

      23

      24

      25

      二、完整代碼示例

      完整代碼示例 :

      import 'package:flutter/material.dart'; class ThemePage extends StatefulWidget { @override _ThemePageState createState() => _ThemePageState(); } class _ThemePageState extends State { /// 主題模式 Brightness brightness = Brightness.light; @override Widget build(BuildContext context) { return MaterialApp( title: "Theme 主題修改", theme: ThemeData( brightness: brightness, primarySwatch: Colors.blue, ), home: Scaffold( appBar: AppBar( title: Text("Theme 主題修改"), ), body: Column( children: [ RaisedButton( onPressed: (){ setState(() { brightness = Brightness.light; }); }, child: Text("切換到日間主題"), ), RaisedButton( onPressed: (){ setState(() { brightness = Brightness.dark; }); }, child: Text("切換到夜間主題"), ), ], ), ), ); } }

      1

      2

      3

      4

      5

      6

      7

      8

      9

      10

      11

      12

      13

      14

      15

      16

      17

      18

      19

      20

      21

      22

      23

      24

      25

      26

      27

      28

      29

      30

      31

      32

      33

      34

      35

      36

      37

      38

      39

      40

      41

      42

      43

      44

      45

      46

      47

      48

      49

      50

      51

      52

      53

      54

      運行效果 :

      三、相關資源

      參考資料 :

      Flutter 官網 : https://flutter.dev/

      Flutter 插件- : https://pub.dev/packages

      Flutter 開發文檔 : https://flutter.cn/docs ( 強烈推薦 )

      官方 GitHub 地址 : https://github.com/flutter

      Flutter 中文社區 : https://flutter.cn/

      Flutter 實用教程 : https://flutter.cn/docs/cookbook

      Flutter CodeLab : https://codelabs.flutter-io.cn/

      Dart 中文文檔 : https://dart.cn/

      Dart 開發者官網 : https://api.dart.dev/

      Flutter 中文網 ( 非官方 , 翻譯的很好 ) : https://flutterchina.club/ , http://flutter.axuer.com/docs/

      Flutter 相關問題 : https://flutterchina.club/faq/ ( 入門階段推薦看一遍 )

      博客源碼下載 :

      GitHub 地址 : https://github.com/han1202012/flutter_cmd ( 隨博客進度一直更新 , 有可能沒有本博客的源碼 )

      博客源碼快照 : https://download.csdn.net/download/han1202012/15547438 ( 本篇博客的源碼快照 , 可以找到本博客的源碼 )

      Flutter Git

      版權聲明:本文內容由網絡用戶投稿,版權歸原作者所有,本站不擁有其著作權,亦不承擔相應法律責任。如果您發現本站中有涉嫌抄襲或描述失實的內容,請聯系我們jiasou666@gmail.com 處理,核實后本網站將在24小時內刪除侵權內容。

      版權聲明:本文內容由網絡用戶投稿,版權歸原作者所有,本站不擁有其著作權,亦不承擔相應法律責任。如果您發現本站中有涉嫌抄襲或描述失實的內容,請聯系我們jiasou666@gmail.com 處理,核實后本網站將在24小時內刪除侵權內容。

      上一篇:excel2019怎么輸入刪除線?excel2019刪除線輸入方法
      下一篇:OKR軟件哪個好用(OKR好處)
      相關文章
      亚洲色精品VR一区区三区| 亚洲乱码无人区卡1卡2卡3| 91亚洲国产在人线播放午夜| 精品久久亚洲一级α| 亚洲人成电影网站久久| 亚洲一区精品视频在线| 亚洲国产精品日韩在线观看| 亚洲精品在线观看视频| 国产亚洲精品xxx| 亚洲热妇无码AV在线播放| 国产亚洲AV手机在线观看| 奇米影视亚洲春色| 激情97综合亚洲色婷婷五| 国产亚洲老熟女视频| 国产亚洲一区二区三区在线不卡 | 亚洲酒色1314狠狠做| 99久久亚洲综合精品成人网| 亚洲国产精品久久久久网站 | 亚洲AV性色在线观看| 久久精品国产亚洲AV| 亚洲国产精品成人综合色在线| 亚洲精品成a人在线观看夫| 亚洲av中文无码乱人伦在线观看| 亚洲狠狠色丁香婷婷综合| 亚洲高清一区二区三区电影| 亚洲av日韩精品久久久久久a | 亚洲综合精品一二三区在线| 777亚洲精品乱码久久久久久| 亚洲精品午夜久久久伊人| 亚洲国产美女福利直播秀一区二区| 亚洲无线一二三四区| 国产精品亚洲一区二区麻豆| 亚洲女女女同性video| 国产成人亚洲精品播放器下载 | 99久久亚洲精品无码毛片| wwwxxx亚洲| 18禁亚洲深夜福利人口| 亚洲国产综合久久天堂| 国产亚洲A∨片在线观看| 亚洲综合一区二区国产精品| 亚洲伊人久久大香线蕉啊|