Flutter CupertinoTimerPicker Examples

Let us look at a Flutter cupertino example.

  1. Open your favorite Flutter IDE.
  2. Go to File-->New-->Project to create a new project.

Here are the examples:

  • CupertinoTimerPickerExample.dart

Example 1: CupertinoTimerPicker Example

Create a file Dart named CupertinoTimerPickerExample.dart.

Add two imports:

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

Extend the StatelessWidget as shown:

class CupertinoTimerPickerExample extends StatelessWidget {

Define one instance field, a string:

  final String title;

Define this class's constructor and make it accept a title as an argument:

  const CupertinoTimerPickerExample(this.title);

Override the build function and construct the TimePicker in the returned Scafold:

  @override
  Widget build(BuildContext context) {
    return Scaffold(
      appBar: CupertinoNavigationBar(
        middle: Text(title),
        previousPageTitle: "Back",
      ),
      body: Center(
        child: CupertinoTimerPicker(
          initialTimerDuration: const Duration(hours: 1),
          onTimerDurationChanged: (Duration value) {},
          minuteInterval: 5,
          secondInterval: 60,
        ),
      ),
    );
  }
}

Here is the full code

import 'package:flutter/cupertino.dart';
import 'package:flutter/material.dart';
class CupertinoTimerPickerExample extends StatelessWidget {
  final String title;
  const CupertinoTimerPickerExample(this.title);
  @override
  Widget build(BuildContext context) {
    return Scaffold(
      appBar: CupertinoNavigationBar(
        middle: Text(title),
        previousPageTitle: "Back",
      ),
      body: Center(
        child: CupertinoTimerPicker(
          initialTimerDuration: const Duration(hours: 1),
          onTimerDurationChanged: (Duration value) {},
          minuteInterval: 5,
          secondInterval: 60,
        ),
      ),
    );
  }
}

Reference.

Download code here.
Follow code author here.