Flutter UI设计插件tlt_design的功能使用

简介

Tlt Design 是一个全面的 Flutter 包,将 Tandemloop 设计系统 带入您的 Flutter 应用程序。它包括字体样式、图标、颜色以及超过 15 个自定义小部件,以提升您的应用程序开发体验。

Tlt Design Flutter Package


目录


安装Tlt Design

要将 Tlt Design 添加到您的 Flutter 项目中,请在 pubspec.yaml 文件中添加以下依赖项:

dependencies:
  tlt_design: ^latest

然后运行以下命令以获取依赖项:

$ flutter pub get

使用

首先导入 Tlt Design 包:

import 'package:tlt_design/tlt_design.dart';

创建一个简单的按钮示例:

TltButton(
  text: 'Click me',
  onTap: () {},
),

功能

颜色

Tlt Design 提供了一个预定义的颜色调色板,以保持一致的外观和感觉。可以通过 TltColors 类访问这些颜色:

Container(
  color: TltColors.blue,
  child: Text('Blue Color'),
),
字体

Tlt Design 提供了一组预定义的文本样式,以确保应用程序的一致性。通过 TltTypography 类使用它们:

Text(
  'Hello, Tlt Design!',
  style: TltStyles.heading1,
),
图标

Tlt Design 提供了两套图标:TltIconsTltIcons2TltIcons 包含来自 Tandemloop 的基本图标,而 TltIcons2 基于 Iconsax 集合。

使用示例:

Icon(TltIcons.home), // 使用 TltIcons
Icon(TltIcons2.user), // 使用 TltIcons2

小部件

按钮

Tlt Design 提供多种样式的按钮,支持不同的尺寸和状态。

TltButton(
    text: 'Button',
    padding: const EdgeInsets.symmetric(horizontal: 16, vertical: 10),
    buttonSize: TltSize.lg,
    suffix: const Icon(
        TltIcons.chevron_down,
        color: TltColors.white,
    ),
    onTap: () {},
),

示例

完整的示例演示如何使用 Tlt Design 包,请参考 GitHub 仓库 中的示例目录。


贡献

该包由位于班加罗尔的动态初创公司 Tandemloop 开发和维护。Tlt Design 的旅程由一支充满激情的开发团队领导,他们致力于提升 Flutter 开发体验。

团队成员:

  • Gopi - 架构和标准的幕后推手。
  • Ajay - 小部件和设计的魔法师。
  • Alfahad - 稳定性和性能的大师。

我们欢迎社区贡献!无论是修复 Bug、增强现有功能还是提出全新的组件,您的输入对使 Tlt Design 更加出色至关重要。

有关如何贡献的更多信息,请访问我们的 贡献指南 文档。


许可证

Tlt Design 在 MIT 许可证下发布,具有附加限制。更多详细信息请参阅 LICENSE 文件。


完整示例代码

以下是一个完整的示例代码,展示如何使用 Tlt Design 创建一个简单的用户界面:

import 'package:flutter/material.dart';
import 'package:tlt_design/tlt_design.dart';

void main() {
  runApp(const MyApp());
}

class MyApp extends StatelessWidget {
  const MyApp({super.key});

  [@override](/user/override)
  Widget build(BuildContext context) {
    return MaterialApp(
      title: 'Tlt Design Example',
      theme: ThemeData(
        colorScheme: ColorScheme.fromSeed(seedColor: Colors.deepPurple),
        useMaterial3: true,
      ),
      home: const TandemloopDesignSystem(),
    );
  }
}

class TandemloopDesignSystem extends StatelessWidget {
  const TandemloopDesignSystem({super.key});

  [@override](/user/override)
  Widget build(BuildContext context) {
    return Scaffold(
      appBar: AppBar(
        centerTitle: true,
        title: Text(
          'Tandemloop Design System',
          style: TltStyles.heading4.copyWith(
            color: TltColors.black,
            fontWeight: FontWeight.w700,
          ),
        ),
      ),
      backgroundColor: TltColors.white,
      body: SingleChildScrollView(
        padding: const EdgeInsets.all(16),
        child: Column(
          crossAxisAlignment: CrossAxisAlignment.start,
          children: [
            Text(
              'Typography',
              style: TltStyles.heading5.copyWith(
                color: TltColors.black,
                fontWeight: FontWeight.w700,
              ),
            ),
            const TltYSpace(8),
            Text(
              'heading1',
              style: TltStyles.heading1.copyWith(
                color: TltColors.black,
              ),
            ),
            Text(
              'heading2',
              style: TltStyles.heading2.copyWith(
                color: TltColors.black,
              ),
            ),
            const TltYSpace(18),
            Text(
              'Colors',
              style: TltStyles.heading5.copyWith(
                color: TltColors.black,
                fontWeight: FontWeight.w700,
              ),
            ),
            const TltYSpace(8),
            Wrap(
              spacing: 22,
              runSpacing: 30,
              children: [
                Container(
                  padding: const EdgeInsets.all(10),
                  decoration: BoxDecoration(
                    color: TltColors.blue[900],
                    borderRadius: BorderRadius.circular(100),
                  ),
                  height: 50,
                  width: 50,
                  child: Center(
                    child: Text(
                      '900',
                      style: TltStyles.labelM.copyWith(
                        color: TltColors.white,
                        fontWeight: FontWeight.w700,
                      ),
                    ),
                  ),
                ),
                Container(
                  padding: const EdgeInsets.all(10),
                  decoration: BoxDecoration(
                    color: TltColors.blue[800],
                    borderRadius: BorderRadius.circular(100),
                  ),
                  height: 50,
                  width: 50,
                  child: Center(
                    child: Text(
                      '800',
                      style: TltStyles.labelM.copyWith(
                        color: TltColors.white,
                        fontWeight: FontWeight.w700,
                      ),
                    ),
                  ),
                ),
                // 其他颜色块...
              ],
            ),
            const TltYSpace(40),
            Text(
              'Buttons',
              style: TltStyles.heading5.copyWith(
                color: TltColors.black,
                fontWeight: FontWeight.w700,
              ),
            ),
            const TltYSpace(18),
            Row(
              children: [
                TltButton(
                  text: 'Button',
                  padding: const EdgeInsets.symmetric(vertical: 4, horizontal: 16),
                  buttonSize: TltSize.xs,
                  onTap: () {},
                ),
                // 其他按钮...
              ],
            ),
          ],
        ),
      ),
    );
  }
}

更多关于Flutter UI设计插件tlt_design的功能使用的实战教程也可以访问 https://www.itying.com/category-92-b0.html

1 回复

更多关于Flutter UI设计插件tlt_design的功能使用的实战系列教程也可以访问 https://www.itying.com/category-92-b0.html


tlt_design 是一个用于 Flutter 的 UI 设计插件,旨在帮助开发者快速构建符合设计规范的 Flutter 应用界面。它通常提供了一系列预定义的组件、样式和工具,以便开发者能够更高效地实现设计稿中的 UI 元素。

以下是 tlt_design 插件的一些常见功能和使用方法:

1. 安装插件

首先,你需要在 pubspec.yaml 文件中添加 tlt_design 插件的依赖:

dependencies:
  flutter:
    sdk: flutter
  tlt_design: ^版本号

然后运行 flutter pub get 来安装插件。

2. 主题配置

tlt_design 通常提供了一套默认的主题配置,你可以直接在 MaterialApp 中使用它:

import 'package:flutter/material.dart';
import 'package:tlt_design/tlt_design.dart';

void main() {
  runApp(MyApp());
}

class MyApp extends StatelessWidget {
  [@override](/user/override)
  Widget build(BuildContext context) {
    return MaterialApp(
      title: 'Flutter Demo',
      theme: TltTheme.light(), // 使用 tlt_design 提供的 light 主题
      darkTheme: TltTheme.dark(), // 使用 tlt_design 提供的 dark 主题
      home: MyHomePage(),
    );
  }
}

3. 使用预定义组件

tlt_design 提供了许多预定义的组件,例如按钮、文本框、卡片等。你可以直接使用这些组件来构建 UI:

import 'package:flutter/material.dart';
import 'package:tlt_design/tlt_design.dart';

class MyHomePage extends StatelessWidget {
  [@override](/user/override)
  Widget build(BuildContext context) {
    return Scaffold(
      appBar: AppBar(
        title: Text('TLT Design Demo'),
      ),
      body: Center(
        child: Column(
          mainAxisAlignment: MainAxisAlignment.center,
          children: <Widget>[
            TltButton(
              onPressed: () {
                // 按钮点击事件
              },
              text: 'Click Me',
            ),
            SizedBox(height: 16),
            TltTextField(
              hintText: 'Enter your name',
            ),
          ],
        ),
      ),
    );
  }
}

4. 自定义样式

虽然 tlt_design 提供了默认的样式,但你也可以根据需要自定义这些样式。例如,你可以通过 TltThemeData 来覆盖默认的主题配置:

final customTheme = TltThemeData(
  primaryColor: Colors.blue,
  accentColor: Colors.orange,
  // 其他自定义配置
);

void main() {
  runApp(MyApp());
}

class MyApp extends StatelessWidget {
  [@override](/user/override)
  Widget build(BuildContext context) {
    return MaterialApp(
      title: 'Flutter Demo',
      theme: customTheme, // 使用自定义主题
      home: MyHomePage(),
    );
  }
}

5. 响应式布局

tlt_design 可能还提供了一些响应式布局的工具,帮助你在不同屏幕尺寸上更好地展示 UI。例如,你可以使用 TltResponsive 来根据屏幕宽度调整布局:

import 'package:flutter/material.dart';
import 'package:tlt_design/tlt_design.dart';

class MyHomePage extends StatelessWidget {
  [@override](/user/override)
  Widget build(BuildContext context) {
    return Scaffold(
      appBar: AppBar(
        title: Text('TLT Design Demo'),
      ),
      body: TltResponsive(
        mobile: MobileLayout(),
        tablet: TabletLayout(),
        desktop: DesktopLayout(),
      ),
    );
  }
}

class MobileLayout extends StatelessWidget {
  [@override](/user/override)
  Widget build(BuildContext context) {
    return Center(
      child: Text('Mobile Layout'),
    );
  }
}

class TabletLayout extends StatelessWidget {
  [@override](/user/override)
  Widget build(BuildContext context) {
    return Center(
      child: Text('Tablet Layout'),
    );
  }
}

class DesktopLayout extends StatelessWidget {
  [@override](/user/override)
  Widget build(BuildContext context) {
    return Center(
      child: Text('Desktop Layout'),
    );
  }
}

6. 其他工具

tlt_design 可能还提供了一些其他工具,例如颜色工具、间距工具、字体工具等,帮助你在开发过程中保持 UI 的一致性。

import 'package:flutter/material.dart';
import 'package:tlt_design/tlt_design.dart';

class MyHomePage extends StatelessWidget {
  [@override](/user/override)
  Widget build(BuildContext context) {
    return Scaffold(
      appBar: AppBar(
        title: Text('TLT Design Demo'),
      ),
      body: Center(
        child: Column(
          mainAxisAlignment: MainAxisAlignment.center,
          children: <Widget>[
            Text(
              'Hello, World!',
              style: TltTextStyles.headline1, // 使用预定义的文本样式
            ),
            SizedBox(height: TltSpacing.large), // 使用预定义的间距
            Container(
              width: 100,
              height: 100,
              color: TltColors.primary, // 使用预定义的颜色
            ),
          ],
        ),
      ),
    );
  }
}
回到顶部