Flutter轻量级UI组件插件mini_ui的使用

Flutter轻量级UI组件插件mini_ui的使用

Mini UI 是一个用于 Flutter 的包。它是一个 Flutter UI 设计系统的示例。

步骤 1:

pubspec.yaml 文件中添加以下依赖:

dependencies:
  mini_ui: ^1.0.0

步骤 2:

导入 mini_ui 包:

import 'package:mini_ui/mini_ui.dart';

步骤 3:

现在,你可以开始使用 Mini UI 组件了。

按钮 (Buttons)

按钮示例

文本组件 (Text Widgets)

文本组件示例

输入字段 (Input Fields)

输入字段示例

示例代码

以下是一个完整的示例代码,展示了如何使用 Mini UI 中的各种组件。

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

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

/// Mini UI的演示和展示。
///
/// 包含各种类型的按钮:
///  * 普通按钮
///  * 加载按钮
///  * 禁用按钮
///  * 轮廓按钮
///  * 加载轮廓按钮
///  * 禁用轮廓按钮
///  * 带有后缀图标的按钮
///  * 带有前缀图标的按钮
///
/// 各种类型的文本组件:
///  * 标题1
///  * 标题2
///  * 小标题
///  * 正文1
///  * 正文2
///  * 标签
///
/// 文本输入框:
///  * 普通示例
///  * 隐藏示例
///
class MyApp extends StatelessWidget {
  MyApp({Key? key}) : super(key: key);
  
  // 控制密码是否可见
  bool isPasswordVisible = false;

  [@override](/user/override)
  Widget build(BuildContext context) {
    return MaterialApp(
      debugShowCheckedModeBanner: false,
      home: Scaffold(
        body: ListView(
          padding: const EdgeInsets.symmetric(horizontal: 16, vertical: 24),
          children: [
            // 显示标题
            const MiniText.heading1(
              "Mini UI",
              align: TextAlign.center,
              underline: true,
            ),
            
            // 文本组件列表
            ...textWidgets,
            vlSpaceXL,
            
            // 按钮列表
            ...buttons,
            vlSpaceL,
            
            // 输入字段列表
            ...inputFields,
          ],
        ),
      ),
    );
  }

  /// 获取按钮列表
  List<Widget> get buttons => [
        MiniButton(
          title: "Hello",
          onTap: () {},
        ),
        vlSpaceL,
        MiniButton(
          title: "Loading",
          onTap: () {},
          busy: true,
        ),
        vlSpaceL,
        MiniButton(
          title: "Disabled",
          onTap: () {},
          disabled: true,
        ),
        vlSpaceL,
        MiniButton.outline(
          title: "Outline",
          onTap: () {},
        ),
        vlSpaceL,
        MiniButton.outline(
          title: "Outline",
          busy: true,
          onTap: () {},
        ),
        vlSpaceL,
        MiniButton.outline(
          title: "Disabled",
          disabled: true,
          onTap: () {},
        ),
        vlSpaceL,
        MiniButton(
          title: "Send",
          onTap: () {},
          suffix: const Icon(
            Icons.send,
            color: miniBackgroundColor,
            size: 20,
          ),
        ),
        vlSpaceL,
        MiniButton(
          title: "Download",
          onTap: () {},
          prefix: const Icon(
            Icons.download,
            color: miniBackgroundColor,
            size: 20,
          ),
        ),
        vlSpaceL,
      ];

  /// 获取文本组件列表
  List<Widget> get textWidgets => [
        const MiniText.heading1("Heading 1"),
        vlSpaceXS,
        const MiniText.heading2("Heading 2"),
        vlSpaceXS,
        const MiniText.subHeading("Subheading"),
        vlSpaceXS,
        const MiniText.body1("Body 1"),
        vlSpaceXS,
        const MiniText.body2("Body 2"),
        vlSpaceXS,
        const MiniText.label("Label"),
      ];

  /// 获取输入字段列表
  List<Widget> get inputFields => [
        MiniInputField(
          controller: TextEditingController(),
          placeholder: "Email",
          prefix: const Icon(
            Icons.email,
            color: miniPrimaryDark,
          ),
          suffix: IconButton(
            splashRadius: 18,
            iconSize: 20,
            onPressed: () {},
            icon: const Icon(
              Icons.clear,
              color: miniPrimaryDark,
            ),
          ),
        ),
        vlSpaceS,
        MiniInputField(
          controller: TextEditingController(),
          placeholder: "Password",
          prefix: const Icon(
            Icons.lock,
            color: miniPrimaryDark,
          ),
          suffix: IconButton(
            splashRadius: 18,
            iconSize: 20,
            onPressed: () {
              isPasswordVisible = !isPasswordVisible;
            },
            icon: Icon(
              isPasswordVisible ? Icons.remove_red_eye : Icons.visibility_off,
              color: miniPrimaryDark,
            ),
          ),
          password: isPasswordVisible,
        )
      ];
}

更多关于Flutter轻量级UI组件插件mini_ui的使用的实战教程也可以访问 https://www.itying.com/category-92-b0.html

1 回复

更多关于Flutter轻量级UI组件插件mini_ui的使用的实战系列教程也可以访问 https://www.itying.com/category-92-b0.html


mini_ui 是一个轻量级的 Flutter UI 组件库,旨在为开发者提供简单、易用且高效的 UI 组件,以快速构建美观的应用程序界面。mini_ui 提供了丰富的预定义组件和样式,帮助开发者减少重复代码,提高开发效率。

以下是关于 mini_ui 插件的基本使用指南,包括如何安装、常用组件的使用以及一些示例代码。

1. 安装 mini_ui

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

dependencies:
  flutter:
    sdk: flutter
  mini_ui: ^0.1.0  # 请根据实际情况使用最新版本

然后运行 flutter pub get 来安装依赖。

2. 导入 mini_ui

在你的 Dart 文件中导入 mini_ui

import 'package:mini_ui/mini_ui.dart';

3. 使用 mini_ui 组件

mini_ui 提供了多种常用的 UI 组件,以下是一些常用组件的示例。

3.1 按钮 (MiniButton)

MiniButton 是一个简单的按钮组件,支持多种样式和事件处理。

MiniButton(
  text: 'Click Me',
  onPressed: () {
    print('Button Pressed!');
  },
  backgroundColor: Colors.blue,
  textColor: Colors.white,
)

3.2 输入框 (MiniInput)

MiniInput 是一个简单的输入框组件,支持占位符、边框样式等。

MiniInput(
  hintText: 'Enter your email',
  onChanged: (value) {
    print('Input changed: $value');
  },
  borderColor: Colors.grey,
)

3.3 卡片 (MiniCard)

MiniCard 是一个卡片组件,支持阴影、圆角等样式。

MiniCard(
  child: Text('This is a card'),
  elevation: 2.0,
  borderRadius: 8.0,
)

3.4 加载指示器 (MiniLoader)

MiniLoader 是一个简单的加载指示器,支持自定义颜色和大小。

MiniLoader(
  color: Colors.blue,
  size: 24.0,
)

3.5 对话框 (MiniDialog)

MiniDialog 是一个简单的对话框组件,支持标题、内容和按钮。

MiniDialog(
  title: 'Alert',
  content: 'Are you sure you want to delete this item?',
  actions: [
    MiniButton(
      text: 'Cancel',
      onPressed: () {
        print('Cancelled');
      },
    ),
    MiniButton(
      text: 'Delete',
      onPressed: () {
        print('Deleted');
      },
    ),
  ],
)

4. 自定义主题

mini_ui 支持自定义主题,你可以通过 MiniTheme 来全局设置应用的样式。

MiniTheme(
  data: MiniThemeData(
    primaryColor: Colors.blue,
    secondaryColor: Colors.green,
    textColor: Colors.black,
  ),
  child: MyApp(),
)

5. 完整示例

以下是一个完整的示例,展示了如何使用 mini_ui 组件构建一个简单的界面:

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

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

class MyApp extends StatelessWidget {
  [@override](/user/override)
  Widget build(BuildContext context) {
    return MiniTheme(
      data: MiniThemeData(
        primaryColor: Colors.blue,
        secondaryColor: Colors.green,
        textColor: Colors.black,
      ),
      child: MaterialApp(
        home: Scaffold(
          appBar: AppBar(
            title: Text('Mini UI Example'),
          ),
          body: Center(
            child: Column(
              mainAxisAlignment: MainAxisAlignment.center,
              children: [
                MiniButton(
                  text: 'Click Me',
                  onPressed: () {
                    print('Button Pressed!');
                  },
                ),
                SizedBox(height: 20),
                MiniInput(
                  hintText: 'Enter your email',
                  onChanged: (value) {
                    print('Input changed: $value');
                  },
                ),
                SizedBox(height: 20),
                MiniCard(
                  child: Text('This is a card'),
                ),
                SizedBox(height: 20),
                MiniLoader(
                  color: Colors.blue,
                  size: 24.0,
                ),
              ],
            ),
          ),
        ),
      ),
    );
  }
}
回到顶部