time_slot 1.0.0 copy "time_slot: ^1.0.0" to clipboard
time_slot: ^1.0.0 copied to clipboard

A new Flutter package which helps in creating time slots with given time interval or list of date times and get day part name of time.

example/lib/main.dart

import 'package:flutter/material.dart';
import 'package:intl/date_symbol_data_local.dart';
import 'package:intl/intl.dart';
import 'package:time_slot/time_slot.dart';

void main() {
  WidgetsFlutterBinding.ensureInitialized();

  initializeDateFormatting('ar', '').then((value) => null);
  initializeDateFormatting('en', '').then((value) => null);

  runApp(const MyApp());
}

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

  // This widget is the root of your application.
  @override
  Widget build(BuildContext context) {
    return MaterialApp(
      title: 'Flutter Demo',
      theme: ThemeData(
        primarySwatch: Colors.blue,
      ),
      home: const MyHomePage(title: 'Time Slot Package'),
    );
  }
}

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

  final String title;

  @override
  State<MyHomePage> createState() => _MyHomePageState();
}

class _MyHomePageState extends State<MyHomePage> {
  DateTime selectTime = DateTime.now();

  DayPartController dayPartController = DayPartController();

  @override
  Widget build(BuildContext context) {
    return Scaffold(
      appBar: AppBar(
        title: Text(widget.title),
      ),
      body: SingleChildScrollView(
        padding: const EdgeInsets.all(20),
        child: Center(
          child: Column(
            mainAxisAlignment: MainAxisAlignment.center,
            children: <Widget>[
              ListTile(
                title: const Text("DayPart of Time"),
                subtitle: Text(
                  DateFormat.jm().format(
                    DateTime(2023, 1, 1, 10, 30),
                  ),
                ),
                trailing: Text(dayPartController.getDayPartName(
                  dayPart: dayPartController.getDayPartOfTime(
                    time: DateTime(2023, 1, 1, 10, 30),
                  )!,
                )),
              ),
              ListTile(
                title: const Text("DayPart of Time"),
                subtitle: Text(
                  DateFormat.jm().format(
                    DateTime(2023, 1, 1, 13, 30),
                  ),
                ),
                trailing: Text(
                  dayPartController.getDayPartName(
                    dayPart: dayPartController.getDayPartOfTime(
                      time: DateTime(2023, 1, 1, 13, 30),
                    )!,
                  ),
                ),
              ),
              ListTile(
                title: const Text("DayPart of Time"),
                subtitle: Text(
                  DateFormat.jm().format(
                    DateTime(2023, 1, 1, 18, 30),
                  ),
                ),
                trailing: Text(
                  dayPartController.getDayPartName(
                    dayPart: dayPartController.getDayPartOfTime(
                      time: DateTime(2023, 1, 1, 18, 30),
                    )!,
                  ),
                ),
              ),
              ListTile(
                title: const Text("DayPart of Time"),
                subtitle: Text(
                  DateFormat.jm().format(
                    DateTime(2023, 1, 1, 23, 30),
                  ),
                ),
                trailing: Text(
                  dayPartController.getDayPartName(
                    dayPart: dayPartController.getDayPartOfTime(
                      time: DateTime(2023, 1, 1, 23, 30),
                    )!,
                  ),
                ),
              ),
              const Divider(),
              const Text(
                  "times slot from interval (10:00 AM to 10:00 PM) every hour"),
              const Divider(),
              const Text("-------------- EN --------------"),
              TimesSlotGridViewFromInterval(
                locale: "en",
                initTime: selectTime,
                crossAxisCount: 4,
                timeSlotInterval: const TimeSlotInterval(
                  start: TimeOfDay(hour: 10, minute: 00),
                  end: TimeOfDay(hour: 22, minute: 0),
                  interval: Duration(hours: 1, minutes: 0),
                ),
                onChange: (value) {
                  setState(() {
                    selectTime = value;
                  });
                },
              ),
              const Text("-------------- AR --------------"),
              TimesSlotGridViewFromInterval(
                locale: "ar",
                initTime: selectTime,
                crossAxisCount: 4,
                timeSlotInterval: const TimeSlotInterval(
                  start: TimeOfDay(hour: 10, minute: 00),
                  end: TimeOfDay(hour: 22, minute: 0),
                  interval: Duration(hours: 1, minutes: 0),
                ),
                onChange: (value) {
                  setState(() {
                    selectTime = value;
                  });
                },
              ),
              const Divider(),
              const Text("times slot from list"),
              const Divider(),
              const Text("-------------- EN --------------"),
              TimesSlotGridViewFromList(
                locale: "en",
                initTime: selectTime,
                crossAxisCount: 4,
                listDates: [
                  DateTime(2023, 1, 1, 10, 30),
                  DateTime(2023, 1, 1, 11, 30),
                  DateTime(2023, 1, 1, 12, 30),
                  DateTime(2023, 1, 1, 13, 30),
                  DateTime(2023, 1, 1, 14, 30),
                  DateTime(2023, 1, 1, 15, 30)
                ],
                onChange: (value) {
                  setState(() {
                    selectTime = value;
                  });
                },
              ),
              const Text("-------------- AR --------------"),
              TimesSlotGridViewFromList(
                locale: "ar",
                initTime: selectTime,
                crossAxisCount: 4,
                listDates: [
                  DateTime(2023, 1, 1, 10, 30),
                  DateTime(2023, 1, 1, 11, 30),
                  DateTime(2023, 1, 1, 12, 30),
                  DateTime(2023, 1, 1, 13, 30),
                  DateTime(2023, 1, 1, 14, 30),
                  DateTime(2023, 1, 1, 15, 30)
                ],
                onChange: (value) {
                  setState(() {
                    selectTime = value;
                  });
                },
              )
            ],
          ),
        ),
      ),
    );
  }
}
28
likes
140
pub points
84%
popularity

Publisher

verified publishermohamed-abdo.com

A new Flutter package which helps in creating time slots with given time interval or list of date times and get day part name of time.

Repository (GitHub)
View/report issues

Documentation

API reference

License

MIT (LICENSE)

Dependencies

flutter, intl

More

Packages that depend on time_slot