flutter_date_pickers 0.4.3 copy "flutter_date_pickers: ^0.4.3" to clipboard
flutter_date_pickers: ^0.4.3 copied to clipboard

Flutter package for day, week, range and month date pickers.

example/lib/main.dart

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

import 'date_pickers_widgets/day_picker_page.dart';
import 'date_pickers_widgets/days_picker_page.dart';
import 'date_pickers_widgets/month_picker_page.dart';
import 'date_pickers_widgets/months_picker_page.dart';
import 'date_pickers_widgets/range_picker_page.dart';
import 'date_pickers_widgets/week_picker_page.dart';
import 'date_pickers_widgets/year_picker_page.dart';
import 'date_pickers_widgets/years_picker_page.dart';
import 'event.dart';

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

///
class MyApp extends StatelessWidget {
  @override
  // ignore: prefer_expression_function_bodies
  Widget build(BuildContext context) {
    return MaterialApp(
      localizationsDelegates: GlobalMaterialLocalizations.delegates,
      supportedLocales: [
        const Locale('en', 'US'), // American English
        const Locale('ru', 'RU'), // Russian
        const Locale("pt"), // Portuguese
        const Locale('ar'), // Arabic
      ],
      debugShowCheckedModeBanner: false,
      title: 'Date pickers demo',
      theme: ThemeData(
        primarySwatch: Colors.blueGrey,
      ),
      home: MyHomePage(
        title: 'flutter_date_pickers Demo',
      ),
    );
  }
}

/// Start page.
class MyHomePage extends StatefulWidget {
  /// Page title.
  final String title;

  ///
  MyHomePage({
    required this.title,
    Key? key,
  }) : super(key: key);

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

class _MyHomePageState extends State<MyHomePage> with TickerProviderStateMixin {
  DateTime startOfPeriod = DateTime.now().subtract(Duration(days: 10));
  DateTime endOfPeriod = DateTime.now().add(Duration(days: 10));
  int _selectedTab = 0;

  final List<Widget> datePickers = <Widget>[
    DayPickerPage(
      events: events,
    ),
    DaysPickerPage(),
    WeekPickerPage(
      events: events,
    ),
    RangePickerPage(
      events: events,
    ),
    MonthPickerPage(),
    MonthsPickerPage(),
    YearPickerPage(),
    YearsPickerPage()
  ];

  @override
  // ignore: prefer_expression_function_bodies
  Widget build(BuildContext context) {
    return Scaffold(
      appBar: AppBar(
        title: Text(
          widget.title,
          style: TextStyle(letterSpacing: 1.15),
        ),
      ),
      body: datePickers[_selectedTab],
      bottomNavigationBar: Theme(
        data: Theme.of(context).copyWith(
            canvasColor: Colors.blueGrey,
            textTheme: Theme.of(context).textTheme.copyWith(
                bodySmall: TextStyle(color: Colors.white.withOpacity(0.5)))),
        child: BottomNavigationBar(
          type: BottomNavigationBarType.fixed,
          items: [
            BottomNavigationBarItem(icon: Icon(Icons.date_range), label: "Day"),
            BottomNavigationBarItem(
                icon: Icon(Icons.date_range), label: "Days"),
            BottomNavigationBarItem(
                icon: Icon(Icons.date_range), label: "Week"),
            BottomNavigationBarItem(
                icon: Icon(Icons.date_range), label: "Range"),
            BottomNavigationBarItem(
                icon: Icon(Icons.date_range), label: "Month"),
            BottomNavigationBarItem(
                icon: Icon(Icons.date_range), label: "Months"),
            BottomNavigationBarItem(
                icon: Icon(Icons.date_range), label: "Year"),
            BottomNavigationBarItem(
                icon: Icon(Icons.date_range), label: "Years"),
          ],
          fixedColor: Colors.yellow,
          currentIndex: _selectedTab,
          onTap: (newIndex) {
            setState(() {
              _selectedTab = newIndex;
            });
          },
        ),
      ),
    );
  }
}

/// Mock events.
final List<Event> events = [
  Event(DateTime.now(), "Today event"),
  Event(DateTime.now().subtract(Duration(days: 3)), "Ev1"),
  Event(DateTime.now().subtract(Duration(days: 13)), "Ev2"),
  Event(DateTime.now().subtract(Duration(days: 30)), "Ev3"),
  Event(DateTime.now().add(Duration(days: 3)), "Ev4"),
  Event(DateTime.now().add(Duration(days: 13)), "Ev5"),
  Event(DateTime.now().add(Duration(days: 30)), "Ev6"),
];
150
likes
150
points
28.9k
downloads

Publisher

unverified uploader

Weekly Downloads

Flutter package for day, week, range and month date pickers.

Repository (GitHub)
View/report issues

Documentation

API reference

License

MIT (license)

Dependencies

flutter, flutter_localizations, intl

More

Packages that depend on flutter_date_pickers