Flutter通用组件插件xcommonwidgets的使用

Flutter通用组件插件xcommonwidgets的使用

Introduction

DON’T USE THIS PLUGIN, BECAUSE IT IS ALWAYS IN DEVELOP.
!!USE THIS PLUGIN AT YOUR OWN RISK!!

Features

  • 自定义按钮
  • 自定义下拉菜单
  • 自定义文本输入框
  • 带有文本的自定义卡片/容器
  • 查看图片或文件的自定义对话框
  • 自定义复选框
  • 自定义树节点
  • 自定义抽屉
  • 自定义应用栏/底部栏
  • 自定义通用基础小部件

完整示例Demo

以下是一个完整的示例代码,展示如何使用xcommonwidgets插件来构建一个简单的Flutter应用。

import 'package:flutter/material.dart';
import 'package:xcommonwidgets/xcommonwidgets.dart'; // 假设插件名为xcommonwidgets

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

class MyApp extends StatelessWidget {
  [@override](/user/override)
  Widget build(BuildContext context) {
    return MaterialApp(
      home: Scaffold(
        appBar: CustomAppBar( // 使用自定义应用栏
          title: "XCommonWidgets Demo",
        ),
        body: Center(
          child: Column(
            mainAxisAlignment: MainAxisAlignment.center,
            children: [
              CustomButton( // 使用自定义按钮
                text: "Click Me",
                onPressed: () {
                  print("Button Pressed");
                },
              ),
              SizedBox(height: 20),
              CustomDropDown( // 使用自定义下拉菜单
                items: ["Option 1", "Option 2", "Option 3"],
                onChanged: (value) {
                  print("Selected: $value");
                },
              ),
              SizedBox(height: 20),
              CustomTextFormField( // 使用自定义文本输入框
                hint: "Enter something",
                onChanged: (text) {
                  print("Input: $text");
                },
              ),
              SizedBox(height: 20),
              CustomCardWithText( // 使用带有文本的自定义卡片
                text: "This is a custom card",
                onTap: () {
                  print("Card Tapped");
                },
              ),
              SizedBox(height: 20),
              ElevatedButton( // 使用默认按钮打开自定义对话框
                onPressed: () {
                  showDialog(
                    context: context,
                    builder: (context) => CustomDialogForImageOrFile(), // 自定义查看图片或文件的对话框
                  );
                },
                child: Text("Open Custom Dialog"),
              ),
              SizedBox(height: 20),
              CustomCheckBox( // 使用自定义复选框
                value: false,
                onChanged: (bool newValue) {
                  print("Checkbox State: $newValue");
                },
              ),
              SizedBox(height: 20),
              CustomTreeNode( // 使用自定义树节点
                nodes: [
                  TreeNodeData(label: "Root"),
                  TreeNodeData(label: "Child 1"),
                  TreeNodeData(label: "Child 2"),
                ],
              ),
              SizedBox(height: 20),
              CustomDrawer( // 使用自定义抽屉
                child: Text("Drawer Content"),
              ),
              SizedBox(height: 20),
              CustomBottomBar( // 使用自定义底部栏
                items: [
                  BottomBarItem(icon: Icons.home, label: "Home"),
                  BottomBarItem(icon: Icons.settings, label: "Settings"),
                ],
              ),
            ],
          ),
        ),
      ),
    );
  }
}

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

1 回复

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


xcommonwidgets 是一个为 Flutter 开发者提供的通用组件插件,旨在简化开发流程,提供常用且高度可定制的 UI 组件。以下是如何使用 xcommonwidgets 插件的详细指南。

1. 安装插件

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

dependencies:
  flutter:
    sdk: flutter
  xcommonwidgets: ^1.0.0  # 请使用最新版本

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

2. 导入插件

在需要使用 xcommonwidgets 的 Dart 文件中导入插件:

import 'package:xcommonwidgets/xcommonwidgets.dart';

3. 使用组件

xcommonwidgets 提供了多种常用组件,以下是一些常见组件的使用示例:

3.1. XButton

XButton 是一个高度可定制的按钮组件。

XButton(
  text: 'Click Me',
  onPressed: () {
    print('Button Pressed!');
  },
  color: Colors.blue,
  textColor: Colors.white,
  borderRadius: 8.0,
);

3.2. XTextField

XTextField 是一个带有标签和验证功能的文本输入框。

XTextField(
  labelText: 'Username',
  hintText: 'Enter your username',
  validator: (value) {
    if (value.isEmpty) {
      return 'Please enter your username';
    }
    return null;
  },
);

3.3. XCard

XCard 是一个带有阴影和圆角的卡片组件。

XCard(
  child: Column(
    children: [
      Text('Card Title'),
      Text('This is a card with shadow and rounded corners.'),
    ],
  ),
  elevation: 4.0,
  borderRadius: 12.0,
);

3.4. XLoadingIndicator

XLoadingIndicator 是一个自定义的加载指示器。

XLoadingIndicator(
  size: 50.0,
  color: Colors.blue,
);

3.5. XSnackbar

XSnackbar 是一个简单的 Snackbar 组件。

XSnackbar.show(
  context: context,
  message: 'This is a snackbar!',
  duration: Duration(seconds: 2),
);

4. 自定义主题

xcommonwidgets 允许你通过自定义主题来统一应用的外观。

XTheme(
  primaryColor: Colors.blue,
  accentColor: Colors.green,
  textTheme: TextTheme(
    headline1: TextStyle(fontSize: 24, fontWeight: FontWeight.bold),
    bodyText1: TextStyle(fontSize: 16, color: Colors.black),
  ),
  child: MaterialApp(
    home: MyHomePage(),
  ),
);

5. 其他功能

xcommonwidgets 还提供了其他一些实用功能,如 XDialogXToastXImagePicker 等,具体使用方法可以参考插件的官方文档或示例代码。

6. 示例项目

你可以在 GitHub 上找到 xcommonwidgets 的示例项目,查看更多的使用示例和最佳实践。

git clone https://github.com/example/xcommonwidgets-example.git
cd xcommonwidgets-example
flutter run

7. 贡献与反馈

如果你在使用过程中遇到问题或有任何建议,欢迎在 GitHub 上提交 issue 或 pull request。

https://github.com/example/xcommonwidgets/issues
回到顶部