Flutter UI组件库插件bld_ui_kit的使用

Flutter UI组件库插件bld_ui_kit的使用

使用

初始化

Widget build(BuildContext context) {
  return BLD(
      style: TextStyle(
        color: Colors.deepPurple,
      ),
      builder: () => MaterialApp(
        title: 'Flutter Demo',
        theme: ThemeData(
          primarySwatch: Colors.blue,
        ),
        home: const MyHomePage(title: 'Flutter Demo Home Page'),
      ));
}

文本(Text)

BLDText('text', textColor:Colors.white)

按钮(Button)

BLDButton(
  text: '按钮标题',
  image: Icon(Icons.ac_unit, size: 20),
  padding: EdgeInsets.all(10),
  radius: 10,
  backgroundColor: Colors.deepOrangeAccent,
  isExpand: false,
  layoutStyle: ButtonLayoutStyle.landscapeLeft,
  widgetSpace: 10,
  onPressed: () {})

会话(Dialog)

showBLDCustomDialog(context, customStyle: (style){
  style.titleColor = Colors.blue;
  return style;
});

输入框(TextField)

BLDTextField(
  controller: TextEditingController(),
  hintText: '请输入内容',
  title: '测试标题',
  axis: BLDAxis.horizontal,
  padding: EdgeInsets.symmetric(horizontal: 13.33),
  backgroundColor: Colors.white,
  radius: 6,
  clean: Icon(Icons.close_rounded, color: Colors.red,),
  alwaysClean: true,
  obscureText: true,
  showEye: true,
  maxLength: 4,
),

完整示例Demo

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

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

class MyApp extends StatelessWidget {
  const MyApp({Key? key}) : super(key: key);

  // This widget is the root of your application.
  [@override](/user/override)
  Widget build(BuildContext context) {
    return BLD(
        style: TextStyle(
          color: Colors.deepPurple,
        ),
        builder: () => MaterialApp(
              title: 'Flutter Demo',
              theme: ThemeData(
                primarySwatch: Colors.blue,
              ),
              home: const MyHomePage(title: 'Flutter Demo Home Page'),
            ));
  }
}

class MyHomePage extends StatefulWidget {
  const MyHomePage({Key? key, required this.title}) : super(key: key);

  final String title;

  [@override](/user/override)
  State<MyHomePage> createState() => _MyHomePageState();
}

class _MyHomePageState extends State<MyHomePage> {
  int _counter = 0;

  void _incrementCounter() {
    setState(() {
      _counter++;
    });
  }

  [@override](/user/override)
  Widget build(BuildContext context) {

    var _body = [
      BLDText('hello word'),
      BLDText('textColor', textColor: Colors.red),
      BLDText('backgroundColor', backgroundColor: Colors.red),
      BLDText('wordSpacing test', wordSpacing: 40),
      BLDText('你好wordSpacing test测试', wordSpacing: 40),
      BLDTextField(
        controller: TextEditingController(),
        hintText: '请输入内容',
        title: '测试标题',
        axis: BLDAxis.horizontal,
        padding: EdgeInsets.symmetric(horizontal: 13.33),
        backgroundColor: Colors.white,
        radius: 6,
        clean: Icon(Icons.close_rounded, color: Colors.red,),
        alwaysClean: true,
        obscureText: true,
        showEye: true,
        maxLength: 4,
      ),
      BLDText('letterSpacing', letterSpacing: 10),
      BLDText('字间隔 letterSpacing ', letterSpacing: 10),
      BLDText('字间隔 letterSpacing', letterSpacing: -3),
      Row(
        children: [
          Container(
            color: Colors.pink,
            child: Text(
              '丨丨丨丨丨',
              style: TextStyle(fontSize: 34.67),
            ),
          ),
          Container(
            color: Colors.green,
            child: BLDText(
              '丨丨丨丨丨',
              fontSize: 34.67,
            ),
          ),
        ],
      ),
      Container(
        color: Colors.purpleAccent,
        child: BLDText(
          '文本文本文本文本文本文本文本文本文本文本本',
          textAlign: TextAlign.center,
          onTap: (text) {
            print(text);
          },
        ),
      ),
      Container(
          width: 200,
          height: 50,
          color: Colors.green,
          alignment: Alignment.center,
          child: BLDButton(
              text: 'BLDTextButton',
              padding: EdgeInsets.all(10),
              textColor: Colors.red,
              borderColor: Colors.orange,
              backgroundColor: Colors.yellow,
              radius: 5,
              onPressed: () {
                print('BLDTextButton -> 点击事件');
              })),
      Container(
        width: 300,
        height: 50,
        color: Colors.blueAccent,
        alignment: Alignment.center,
        child: BLDButton(
            text: '按钮标题',
            image: Icon(Icons.ac_unit, size: 20),
            padding: EdgeInsets.all(10),
            radius: 10,
            backgroundColor: Colors.deepOrangeAccent,
            isExpand: false,
            layoutStyle: ButtonLayoutStyle.landscapeLeft,
            widgetSpace: 10,
            onPressed: () {
              showBLDCustomDialog(context, customStyle: (style) {
                style.titleColor = Colors.blue;
                return style;
              });
            }),
      ),
    ];

    return Scaffold(
      appBar: AppBar(
        title: Text(widget.title),
      ),
      backgroundColor: Colors.grey,
      body: Center(
        child: ListView(
          children: _body,
        ),
      ),
      floatingActionButton: FloatingActionButton(
        onPressed: _incrementCounter,
        tooltip: 'Increment',
        child: const Icon(Icons.add),
      ),
    );
  }
}

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

1 回复

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


bld_ui_kit 是一个 Flutter UI 组件库插件,旨在提供一组可复用的 UI 组件,以加速 Flutter 应用程序的开发。要使用 bld_ui_kit,你可以按照以下步骤进行:

1. 安装插件

首先,你需要在 pubspec.yaml 文件中添加 bld_ui_kit 作为依赖项:

dependencies:
  flutter:
    sdk: flutter
  bld_ui_kit: ^1.0.0  # 请替换为最新版本

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

2. 导入插件

在你的 Dart 文件中导入 bld_ui_kit

import 'package:bld_ui_kit/bld_ui_kit.dart';

3. 使用组件

bld_ui_kit 提供了许多预构建的组件,你可以在你的应用程序中使用这些组件。以下是一些常见的使用示例:

按钮组件

BldPrimaryButton(
  onPressed: () {
    // 按钮点击事件
  },
  child: Text('Primary Button'),
)

文本输入框

BldTextField(
  hintText: 'Enter your text',
  onChanged: (value) {
    // 文本变化事件
  },
)

卡片组件

BldCard(
  child: Column(
    children: [
      Text('Card Title'),
      Text('Card Content'),
    ],
  ),
)

加载指示器

BldLoadingIndicator()

4. 自定义主题

bld_ui_kit 可能还提供了一些主题和样式自定义的选项。你可以通过配置主题来使组件更符合你的应用程序设计需求。

MaterialApp(
  theme: ThemeData(
    primaryColor: Colors.blue,
    accentColor: Colors.orange,
    // 其他主题配置
  ),
  home: MyHomePage(),
)
回到顶部