calendar_appbar 0.0.1 calendar_appbar: ^0.0.1 copied to clipboard
Flutter package for custom AppBar with calendar view.
import 'dart:math';
import 'package:calendar_appbar/calendar_appbar.dart';
import 'package:flutter/material.dart';
void main() {
runApp(MyApp());
}
class MyApp extends StatelessWidget {
@override
Widget build(BuildContext context) {
return MaterialApp(
title: 'Calendar AppBar Example App',
home: MyHomePage(),
);
}
}
class MyHomePage extends StatefulWidget {
@override
_MyHomePageState createState() => _MyHomePageState();
}
class _MyHomePageState extends State<MyHomePage> {
DateTime selectedDate;
Random random = new Random();
@override
void initState() {
setState(() {
selectedDate = DateTime.now();
});
super.initState();
}
@override
Widget build(BuildContext context) {
return Scaffold(
appBar: CalendarAppBar(
onDateChanged: (value) => setState(() => selectedDate = value),
firstDate: DateTime.now().subtract(Duration(days: 140)),
lastDate: DateTime.now(),
events: List.generate(
100,
(index) => DateTime.now()
.subtract(Duration(days: index * random.nextInt(5)))),
),
body: Center(child: Text(selectedDate.toString())),
);
}
}