time_range_picker 1.0.2

  • Readme
  • Changelog
  • Example
  • Installing
  • 84

time_range_picker #

A time range picker for flutter.

Getting Started #

Installation #

Add


time_range_picker : any

to your pubspec.yaml, and run

flutter packages get

in your project's root directory.

Basic Usage #

import 'package:flutter/material.dart';

import 'package:time_range_picker/time_range_picker.dart';

void main() => runApp(MyApp());

class MyApp extends StatelessWidget {
  @override
  Widget build(BuildContext context) {
    return MaterialApp(
      theme: ThemeData(
        primarySwatch: Colors.blue,
      ),
      home: MyHomePage(),
    );
  }
}

class MyHomePage extends StatelessWidget {
  @override
  Widget build(BuildContext context) {
    return Scaffold(
        backgroundColor: Colors.blueGrey,
        body: Center(
          child: RaisedButton(
            onPressed: () async {
              TimeRange result = await showTimeRangePicker(
                context: context,
              );
              print("result " + result.toString());
            },
            child: Text("Pure"),
          ),
        ));
  }
}

Examples #

Simple

Simple

Interval

Interval

Filled Style

Filled Style

Disabled Timeframe

Disabled Timeframe

Background Widget

Background Widget

Parameters #

typeparamdefaultdescription
TimeOfDaystartTimeOfDay.now()preselected start time
TimeOfDayendnow + 3hpreselected end time
TimeRangedisabledTimedisabled time range (this time cannot be selected)
ColordisabledColorColors.red.withOpacity(0.5)the color for the disabled section
PaintingStylepaintingStylePaintingStyle.strokeStyle of the arc (filled or stroke)
Function(TimeOfDay)onStartChange
Function(TimeOfDay)onEndChange
DurationintervalDuration(minutes: 5)Minimum time steps that can be selected
StringfromText"From"label for start time
StringtoText"To"label for end time
booluse24HourFormattrueuse 24 hours or am / pm
doublepadding26the padding of the ring
doublestrokeWidth12the thickness of the ring
ColorstrokeColorprimaryColorthe color of the active arc from start time to end time
doublehandlerRadius12the radius of the handler to drag the arc
ColorhandlerColorprimaryColorthe color of a handler
ColorselectedColorprimaryColorLightthe color of a selected handler
ColorbackgroundColorColors.grey[200]the color of the circle outline
WidgetbackgroundWidgeta widget displayed in the background, use e.g. an image
intticksnumber of ticks displayed
doubleticksOffset0the offset for ticks
doubleticksLengthstrokeWidthticks length
doubleticksWidth1ticks thickness
ColorticksColorColors.whiteColor of ticks
boolsnapfalseSnap time bar to interval
ListlabelsShow labels around the circle (start at 0 hours)
doublelabelOffset20Offset of the labels
boolrotateLabelstruerotate labels
boolautoAdjustLabelstrueflip labels if the angle woulb be upside down (only if rotate labels is active)
TextStylelabelStyleStyle of the labels
TextStyletimeTextStyleTextStyle of the time texts
TextStyleactiveTimeTextStyleTextStyle of the currently moving time text
boolhideTimesfalsehide the time texts

[1.0.0] - TODO: Add release date. #

  • Initial release

[1.0.1] - TODO: Add release date. #

  • Updated docs

[1.0.2] - TODO: Add release date. #

  • Fixed a bug when start-time was beyond 21pm

example/lib/main.dart

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

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

class MyApp extends StatelessWidget {
  // This widget is the root of your application.
  @override
  Widget build(BuildContext context) {
    return MaterialApp(
      title: 'Time Range Picker',
      theme: ThemeData(
        // This is the theme of your application.
        //
        // Try running your application with "flutter run". You'll see the
        // application has a blue toolbar. Then, without quitting the app, try
        // changing the primarySwatch below to Colors.green and then invoke
        // "hot reload" (press "r" in the console where you ran "flutter run",
        // or simply save your changes to "hot reload" in a Flutter IDE).
        // Notice that the counter didn't reset back to zero; the application
        // is not restarted.
        primarySwatch: Colors.blue,
        // This makes the visual density adapt to the platform that you run
        // the app on. For desktop platforms, the controls will be smaller and
        // closer together (more dense) than on mobile platforms.
        visualDensity: VisualDensity.adaptivePlatformDensity,
      ),
      home: MyHomePage(title: 'Flutter Time Range Picker'),
    );
  }
}

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

  // This widget is the home page of your application. It is stateful, meaning
  // that it has a State object (defined below) that contains fields that affect
  // how it looks.

  // This class is the configuration for the state. It holds the values (in this
  // case the title) provided by the parent (in this case the App widget) and
  // used by the build method of the State. Fields in a Widget subclass are
  // always marked "final".

  final String title;

  @override
  _MyHomePageState createState() => _MyHomePageState();
}

class _MyHomePageState extends State<MyHomePage> {
  @override
  Widget build(BuildContext context) {
    return Scaffold(
      appBar: AppBar(
        title: Text(widget.title),
      ),
      body: Center(
        child: Column(children: [
          RaisedButton(
            onPressed: () async {
              TimeRange result = await showTimeRangePicker(
                context: context,
              );
              print("result " + result.toString());
            },
            child: Text("Pure"),
          ),
          RaisedButton(
            onPressed: () {
              showTimeRangePicker(
                context: context,
                start: TimeOfDay(hour: 22,minute: 9),
                onStartChange: (start) {
                  print("start time " + start.toString());
                },
                onEndChange: (end) {
                  print("end time " + end.toString());
                },
                interval: Duration(minutes: 30),
                use24HourFormat: true,
                padding: 30,
                strokeWidth: 20,
                handlerRadius: 14,
                strokeColor: Colors.orange,
                handlerColor: Colors.orange[700],
                selectedColor: Colors.amber,
                backgroundColor: Colors.black.withOpacity(0.3),
                ticks: 12,
                ticksColor: Colors.white,
                snap: true,
                labels: [
                  "12 pm",
                  "3 am",
                  "6 am",
                  "9 am",
                  "12 am",
                  "3 pm",
                  "6 pm",
                  "9 pm"
                ].asMap().entries.map((e) {
                  return ClockLabel.fromIndex(
                      idx: e.key, length: 8, text: e.value);
                }).toList(),
                labelOffset: -30,
                labelStyle: TextStyle(
                    fontSize: 22,
                    color: Colors.grey,
                    fontWeight: FontWeight.bold),
                timeTextStyle: TextStyle(
                    color: Colors.orange[700],
                    fontSize: 32,
                    fontStyle: FontStyle.italic,
                    fontWeight: FontWeight.bold),
                activeTimeTextStyle: TextStyle(
                    color: Colors.orange,
                    fontSize: 32,
                    fontStyle: FontStyle.italic,
                    fontWeight: FontWeight.bold),
              );
            },
            child: Text("Interval"),
          ),
          RaisedButton(
            onPressed: () async {
              TimeRange result = await showTimeRangePicker(
                  context: context,
                  start: TimeOfDay(hour: 9, minute: 0),
                  end: TimeOfDay(hour: 12, minute: 0),
                  disabledTime: TimeRange(
                      startTime: TimeOfDay(hour: 22, minute: 0),
                      endTime: TimeOfDay(hour: 5, minute: 0)),
                  disabledColor: Colors.red.withOpacity(0.5),
                  strokeWidth: 4,
                  ticks: 24,
                  ticksOffset: -7,
                  ticksLength: 15,
                  ticksColor: Colors.grey,
                  labels: [
                    "12 pm",
                    "3 am",
                    "6 am",
                    "9 am",
                    "12 am",
                    "3 pm",
                    "6 pm",
                    "9 pm"
                  ].asMap().entries.map((e) {
                    return ClockLabel.fromIndex(
                        idx: e.key, length: 8, text: e.value);
                  }).toList(),
                  labelOffset: 35,
                  rotateLabels: false,
                  padding: 60);

              print("result " + result.toString());
            },
            child: Text("Disabled Times"),
          ),
          RaisedButton(
            onPressed: () async {
              TimeRange result = await showTimeRangePicker(
                context: context,
                paintingStyle: PaintingStyle.fill,
                backgroundColor: Colors.grey.withOpacity(0.2),
                labels: [
                  ClockLabel.fromTime(
                      time: TimeOfDay(hour: 7, minute: 0), text: "Start Work"),
                  ClockLabel.fromTime(
                      time: TimeOfDay(hour: 18, minute: 0), text: "Go Home")
                ],
                start: TimeOfDay(hour: 10, minute: 0),
                end: TimeOfDay(hour: 13, minute: 0),
                ticks: 8,
                strokeColor: Theme.of(context).primaryColor.withOpacity(0.5),
                ticksColor: Theme.of(context).primaryColor,
                labelOffset: 15,
                padding: 60,
                disabledTime: TimeRange(
                    startTime: TimeOfDay(hour: 18, minute: 0),
                    endTime: TimeOfDay(hour: 7, minute: 0)),
                disabledColor: Colors.red.withOpacity(0.5),
              );

              print("result " + result.toString());
            },
            child: Text("Filled Style"),
          ),
          RaisedButton(
            onPressed: () async {
              TimeRange result = await showTimeRangePicker(
                context: context,
                strokeColor: Colors.teal,
                handlerColor: Colors.teal[200],
                selectedColor: Colors.tealAccent,
                strokeWidth: 16,
                handlerRadius: 18,
                backgroundWidget: Image.asset(
                  "assets/images/day-night.png",
                  height: 200,
                  width: 200,
                ),
                labels: [
                  ClockLabel.fromTime(
                      time: TimeOfDay(hour: 6, minute: 0), text: "Get up"),
                  ClockLabel.fromTime(
                      time: TimeOfDay(hour: 9, minute: 0), text: "Coffee time"),
                  ClockLabel.fromTime(
                      time: TimeOfDay(hour: 15, minute: 0), text: "Afternoon"),
                  ClockLabel.fromTime(
                      time: TimeOfDay(hour: 18, minute: 0),
                      text: "Time for a beer"),
                  ClockLabel.fromTime(
                      time: TimeOfDay(hour: 22, minute: 0),
                      text: "Go to Sleep"),
                  ClockLabel.fromTime(
                      time: TimeOfDay(hour: 2, minute: 0),
                      text: "Go for a pee"),
                  ClockLabel.fromTime(
                      time: TimeOfDay(hour: 12, minute: 0), text: "Lunchtime!")
                ],
                ticksColor: Colors.black,
                labelOffset: 40,
                padding: 55,
                labelStyle: TextStyle(fontSize: 18, color: Colors.black),
              );

              print("result " + result.toString());
            },
            child: Text("Background Widget"),
          ),
        ]),
      ),
    );
  }
}

Use this package as a library

1. Depend on it

Add this to your package's pubspec.yaml file:


dependencies:
  time_range_picker: ^1.0.2

2. Install it

You can install packages from the command line:

with Flutter:


$ flutter pub get

Alternatively, your editor might support flutter pub get. Check the docs for your editor to learn more.

3. Import it

Now in your Dart code, you can use:


import 'package:time_range_picker/time_range_picker.dart';
  
Popularity:
Describes how popular the package is relative to other packages. [more]
67
Health:
Code health derived from static analysis. [more]
100
Maintenance:
Reflects how tidy and up-to-date the package is. [more]
100
Overall:
Weighted score of the above. [more]
84
Learn more about scoring.

We analyzed this package on Jul 11, 2020, and provided a score, details, and suggestions below. Analysis was completed with status completed using:

  • Dart: 2.8.4
  • pana: 0.13.15
  • Flutter: 1.17.5

Analysis suggestions

Package not compatible with SDK dart

Because:

  • time_range_picker that is a package requiring null.

Health suggestions

Format lib/src/time-range-dialog.dart.

Run flutter format to format lib/src/time-range-dialog.dart.

Format lib/src/utils.dart.

Run flutter format to format lib/src/utils.dart.

Dependencies

Package Constraint Resolved Available
Direct dependencies
Dart SDK >=2.7.0 <3.0.0
flutter 0.0.0
Transitive dependencies
collection 1.14.12 1.14.13
meta 1.1.8 1.2.2
sky_engine 0.0.99
typed_data 1.1.6 1.2.0
vector_math 2.0.8 2.1.0-nullsafety
Dev dependencies
flutter_test