Flutter商店调度管理插件rashail_store_schedular的使用

发布于 1周前 作者 ionicwang 来自 Flutter

Flutter商店调度管理插件rashail_store_schedular的使用

rashail_store_schedular 是一个用于 Flutter 的一周调度包,允许你为每一天选择预定时间。你可以根据需求完全自定义其用户界面。


截图

以下是一些示例截图:


示例图像 1


示例图像 2


示例图像 3


预览

以下是 rashail_store_schedular 的用法示例代码:

StoreScheduler(
  borderRadius: 4, // 设置圆角大小
  borderWidth: 0, // 设置边框宽度
  showBorder: false, // 是否显示边框
  borderColor: Colors.black, // 边框颜色
  buttonColor: Colors.black, // 按钮颜色
  pickerColor: Colors.black.withOpacity(0.05), // 选择器背景颜色
  dayStyle: const TextStyle(
    fontWeight: FontWeight.w600,
    fontFamily: "Times New Roman", // 字体样式
  ),
  buttonTextStyle: const TextStyle(
    color: Colors.white,
    fontWeight: FontWeight.bold,
    fontFamily: "Times New Roman", // 按钮文字样式
  ),
  fontFamily: "Times New Roman", // 全局字体
  fontColor: Colors.black.withOpacity(0.8), // 文字颜色
  pickerFontSize: 18, // 选择器字体大小
  pickerFontWeight: FontWeight.w500, // 选择器字体粗细
  submitButtonText: "Save Store Settings", // 提交按钮文字
  onChangeValue: (value) { // 监听值变化
    print(value); // 打印选中的值
  },
)

功能特性

  • 允许为每周的每一天设置开始时间和结束时间。
  • 支持部分天数关闭店铺的功能。
  • 输出结果以 JSON 格式生成。

开始使用

在你的项目中添加以下依赖到 pubspec.yaml 文件中:

dependencies:
  rashail_store_schedular: ^0.0.1

然后运行以下命令安装依赖:

flutter pub get

示例代码

以下是一个完整的示例代码,展示如何在 Flutter 应用中使用 rashail_store_schedular

import 'package:flutter/foundation.dart';
import 'package:flutter/material.dart';
import 'package:rashail_store_schedular/rashail_store_schedular.dart';

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

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

  [@override](/user/override)
  Widget build(BuildContext context) {
    return MaterialApp(
      title: 'App Example',
      theme: ThemeData.light(useMaterial3: true),
      home: const MyHomePage(title: 'Example App'),
    );
  }
}

class MyHomePage extends StatefulWidget {
  const MyHomePage({super.key, required this.title});
  final String title;

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

class _MyHomePageState extends State<MyHomePage> {
  [@override](/user/override)
  Widget build(BuildContext context) {
    return Scaffold(
      appBar: AppBar(
        centerTitle: true,
        title: const Text(
          'Schedule Time',
          style: TextStyle(
            fontSize: 30,
            fontWeight: FontWeight.bold,
            fontFamily: "Times New Roman",
          ),
        ),
      ),
      body: Row(
        crossAxisAlignment: CrossAxisAlignment.start,
        mainAxisAlignment: MainAxisAlignment.center,
        children: [
          SizedBox(
            width: MediaQuery.of(context).size.width / 3,
            child: StoreScheduler(
              borderRadius: 4, // 圆角
              borderWidth: 0, // 边框宽度
              showBorder: false, // 是否显示边框
              borderColor: Colors.black, // 边框颜色
              buttonColor: Colors.black, // 按钮颜色
              pickerColor: Colors.black.withOpacity(0.05), // 选择器背景色
              dayStyle: const TextStyle(
                fontWeight: FontWeight.w600,
                fontFamily: "Times New Roman", // 星期样式
              ),
              buttonTextStyle: const TextStyle(
                color: Colors.white,
                fontWeight: FontWeight.bold,
                fontFamily: "Times New Roman", // 按钮文字样式
              ),
              fontFamily: "Times New Roman", // 全局字体
              fontColor: Colors.black.withOpacity(0.8), // 文字颜色
              pickerFontSize: 18, // 选择器字体大小
              pickerFontWeight: FontWeight.w500, // 选择器字体粗细
              submitButtonText: "Save Store Settings", // 提交按钮文字
              onChangeValue: (value) { // 值变化回调
                if (kDebugMode) {
                  print(value); // 打印选中的值
                }
              },
            ),
          ),
        ],
      ),
    );
  }
}

更多关于Flutter商店调度管理插件rashail_store_schedular的使用的实战系列教程也可以访问 https://www.itying.com/category-92-b0.html

1 回复

更多关于Flutter商店调度管理插件rashail_store_schedular的使用的实战系列教程也可以访问 https://www.itying.com/category-92-b0.html


rashail_store_scheduler 是一个用于 Flutter 的商店调度管理插件,它可以帮助你管理和调度商店的营业时间、员工排班等。以下是如何使用这个插件的基本步骤:

1. 添加依赖

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

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

然后运行 flutter pub get 来获取依赖。

2. 导入插件

在你的 Dart 文件中导入插件:

import 'package:rashail_store_scheduler/rashail_store_scheduler.dart';

3. 初始化插件

在使用插件之前,你需要初始化它。通常你可以在 main.dart 文件中进行初始化:

void main() {
  WidgetsFlutterBinding.ensureInitialized();
  RashailStoreScheduler.initialize();
  runApp(MyApp());
}

4. 设置商店营业时间

你可以使用插件来设置商店的营业时间。例如:

RashailStoreScheduler.setStoreHours(
  openingTime: TimeOfDay(hour: 9, minute: 0),
  closingTime: TimeOfDay(hour: 21, minute: 0),
);

5. 添加员工排班

你可以为员工添加排班。例如:

RashailStoreScheduler.addEmployeeShift(
  employeeId: 'emp001',
  shiftStart: DateTime(2023, 10, 1, 9, 0),
  shiftEnd: DateTime(2023, 10, 1, 17, 0),
);

6. 获取商店营业时间

你可以获取商店的营业时间:

TimeOfDay? openingTime = RashailStoreScheduler.getOpeningTime();
TimeOfDay? closingTime = RashailStoreScheduler.getClosingTime();

7. 获取员工排班

你可以获取某个员工的排班:

List<Shift> shifts = RashailStoreScheduler.getEmployeeShifts('emp001');

8. 检查商店是否营业

你可以检查商店当前是否营业:

bool isOpen = RashailStoreScheduler.isStoreOpen();

9. 处理事件

你可以监听商店状态的变化,例如商店开门或关门:

RashailStoreScheduler.onStoreOpen(() {
  print('Store is now open!');
});

RashailStoreScheduler.onStoreClose(() {
  print('Store is now closed!');
});

10. 示例代码

以下是一个完整的示例代码,展示了如何使用 rashail_store_scheduler 插件:

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

void main() {
  WidgetsFlutterBinding.ensureInitialized();
  RashailStoreScheduler.initialize();
  runApp(MyApp());
}

class MyApp extends StatelessWidget {
  [@override](/user/override)
  Widget build(BuildContext context) {
    return MaterialApp(
      home: Scaffold(
        appBar: AppBar(
          title: Text('Store Scheduler Example'),
        ),
        body: Center(
          child: Column(
            mainAxisAlignment: MainAxisAlignment.center,
            children: [
              ElevatedButton(
                onPressed: () {
                  RashailStoreScheduler.setStoreHours(
                    openingTime: TimeOfDay(hour: 9, minute: 0),
                    closingTime: TimeOfDay(hour: 21, minute: 0),
                  );
                },
                child: Text('Set Store Hours'),
              ),
              ElevatedButton(
                onPressed: () {
                  RashailStoreScheduler.addEmployeeShift(
                    employeeId: 'emp001',
                    shiftStart: DateTime(2023, 10, 1, 9, 0),
                    shiftEnd: DateTime(2023, 10, 1, 17, 0),
                  );
                },
                child: Text('Add Employee Shift'),
              ),
              ElevatedButton(
                onPressed: () {
                  bool isOpen = RashailStoreScheduler.isStoreOpen();
                  print('Is store open? $isOpen');
                },
                child: Text('Check Store Status'),
              ),
            ],
          ),
        ),
      ),
    );
  }
}
回到顶部
AI 助手
你好,我是IT营的 AI 助手
您可以尝试点击下方的快捷入口开启体验!