微信二维码
微博二维码
qq号二维码

Flutter主题生成

王伟平 2021.10.14 770人浏览
flutter主题样式生成工具

原文链接:

https://medium.com/@sheikhg1900/using-flutter-theming-tools-generated-dart-material-theme-in-your-application-f190f3919e88


在你的 android 手机上打开 Flutter 主题工具应用程序 。按照指南为你的应用程序准备一个很棒的 Dart 主题。

Flutter主题生成

将生成的 Dart 主题代码复制到剪贴板中。

Flutter主题生成

Flutter主题生成

要在您的计算机上获取主题,请在 IDE 中,(例如 Visual Studio Code)。将其粘贴到您手机上的 slack 聊天中,以便您可以从计算机上的 slack 获取代码。在移动设备 slack 上,输入 ```。将出现一个框。将剪贴板内容粘贴到该框中。


Flutter主题生成

Flutter主题生成

Flutter主题生成

可选:按照相同的步骤为黑暗模式生成另一个 Dart 主题。

Flutter主题生成

打开您现有的 flutter 项目。使用以下内容创建 generated_theme.dart 文件。

import 'package:flutter/material.dart';ThemeData get mylightTheme {// TODO: Copy Generated Light Theme Here.

return theme;

}ThemeData get myDarkTheme {// TODO: Copy Generated Dark Theme Here.

return theme;

}

用生成的代码替换 TODO 注释。

ThemeData get mylightTheme {

// Flutter Theming Tool 1.0.0+10, developed by Tamata Soft

// Initialize ThemeData.

  var theme = ThemeData(

    primarySwatch: Colors.blue,

    brightness: Brightness.light,

  );// Main Setting.

  theme = theme.copyWith(

    colorScheme: theme.colorScheme.copyWith(

      onPrimary: const Color(0xffffffff),

      secondary: Colors.deepOrange,

    ),

  );// ElevatedButton Setting.

  theme = theme.copyWith(

    elevatedButtonTheme: ElevatedButtonThemeData(

      style: ButtonStyle(

        shape: MaterialStateProperty.all(

          const RoundedRectangleBorder(

            borderRadius: BorderRadius.only(

              topLeft: Radius.circular(16.0),

              topRight: Radius.circular(16.0),

            ),

          ),

        ),

      ),

    ),

  );// OutlinedButton Setting.

  theme = theme.copyWith(

    outlinedButtonTheme: OutlinedButtonThemeData(

      style: ButtonStyle(

        shape: MaterialStateProperty.all(

          const RoundedRectangleBorder(

            borderRadius: BorderRadius.only(

              topLeft: Radius.circular(16.0),

              topRight: Radius.circular(16.0),

            ),

          ),

        ),

      ),

    ),

  );// Chip Setting.

  theme = theme.copyWith(

    chipTheme: theme.chipTheme.copyWith(

      shape: const RoundedRectangleBorder(

        borderRadius: BorderRadius.only(

          topLeft: Radius.circular(16.0),

          bottomRight: Radius.circular(16.0),

        ),

      ),

      labelStyle: (theme.chipTheme.labelStyle).copyWith(

        color: Colors.deepOrange,

        shadows: [

          const Shadow(

            blurRadius: 2.0,

            color: Colors.grey,

          )

        ],

      ),

      secondaryLabelStyle: (theme.chipTheme.labelStyle).copyWith(

        shadows: [

          const Shadow(

            blurRadius: 2.0,

          )

        ],

      ),

    ),

  );

  return theme;

}

打开 main.dart 文件。在 MaterialApp 小部件中添加 theme 属性。

MaterialApp(

 title: 'Flutter Demo',

 theme: mylightTheme,

 ----

 ----

)

所需的包-google_fonts

分享到:
天津UI设计培训-CleanPNG免抠素材网站
  • 2020.11.30
  • 天津IT培训后最便宜的程序员都做些什么?拿多少钱?如何破局
  • 2024.04.16