month_selector 1.0.2 copy "month_selector: ^1.0.2" to clipboard
month_selector: ^1.0.2 copied to clipboard

Package to select a month and a year in the calendar

example/lib/main.dart

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

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

class MyApp extends StatelessWidget {
  const MyApp({super.key});
  @override
  Widget build(BuildContext context) {
    return const MaterialApp(
      title: 'Month Selector',
      debugShowCheckedModeBanner: false,
      home: MyHomePage(),
    );
  }
}

class MyHomePage extends StatefulWidget {
  const MyHomePage({super.key});

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

class _MyHomePageState extends State<MyHomePage> {
  DateTime? month;

  String monthDisplay(DateTime date) {
    final month = date.month.toString().padLeft(2, '0');
    final year = date.year.toString();
    return "$month/$year";
  }

  @override
  Widget build(BuildContext context) {
    return Scaffold(
      body: Center(
        child: ElevatedButton(
          onPressed: () {
            showDialog(
                context: context,
                builder: (context) {
                  return MonthSelector(
                    selectedDate: month != null ? [month!] : [],
                    callback: (res) {
                      Navigator.pop(context);
                      if (res != null && res != []) {
                        setState(() {
                          month = res[0];
                        });
                      }
                    },
                  );
                });
          },
          child: Text(month != null ? monthDisplay(month!) : "Selecione o mês"),
        ),
      ),
    );
  }
}
3
likes
140
pub points
67%
popularity

Publisher

unverified uploader

Package to select a month and a year in the calendar

Repository (GitHub)
View/report issues

Documentation

API reference

License

MIT (license)

Dependencies

flutter

More

Packages that depend on month_selector