flutter theme 主题样式生成工具

[外链图片转存失败,源站可能有防盗链机制,建议将图片保存下来直接上传(img-VS1JzLth-1634087831804)(https://ducafecat.tech/2021/10/13/translation/using-flutter-theming-tools-generated-dart-material-theme-in-your-application/2021-10-13-09-08-14.png)]

原文

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

参考

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

正文

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

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

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

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

打开您现有的 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


© 猫哥

  • https://ducafecat.tech/

  • https://github.com/ducafecat

  • 微信群 ducafecat

  • b 站 https://space.bilibili.com/404904528

往期

开源

GetX Quick Start

https://github.com/ducafecat/getx_quick_start

新闻客户端

https://github.com/ducafecat/flutter_learn_news

strapi 手册译文

https://getstrapi.cn

微信讨论群 ducafecat

系列集合

译文

https://ducafecat.tech/categories/%E8%AF%91%E6%96%87/

开源项目

https://ducafecat.tech/categories/%E5%BC%80%E6%BA%90/

Dart 编程语言基础

https://space.bilibili.com/404904528/channel/detail?cid=111585

Flutter 零基础入门

https://space.bilibili.com/404904528/channel/detail?cid=123470

Flutter 实战从零开始 新闻客户端

https://space.bilibili.com/404904528/channel/detail?cid=106755

Flutter 组件开发

https://space.bilibili.com/404904528/channel/detail?cid=144262

Flutter Bloc

https://space.bilibili.com/404904528/channel/detail?cid=177519

Flutter Getx4

https://space.bilibili.com/404904528/channel/detail?cid=177514

Docker Yapi

https://space.bilibili.com/404904528/channel/detail?cid=130578

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值