week_day_picker 1.1.3
week_day_picker: ^1.1.3 copied to clipboard
week day picker is a dart package to show a date calandar as a week, targeting all platform, customized Theme and Locale
example/lib/main.dart
import 'package:flutter/material.dart';
import 'package:flutter_localizations/flutter_localizations.dart';
import 'package:week_day_picker/week_day_picker.dart';
void main() {
runApp(const MyApp());
}
class MyApp extends StatefulWidget {
const MyApp({super.key});
@override
State<MyApp> createState() => _MyAppState();
}
class _MyAppState extends State<MyApp> {
late ThemeMode theme;
@override
void initState() {
super.initState();
theme = ThemeMode.light;
}
@override
Widget build(BuildContext context) {
return MaterialApp(
title: 'Week day picker Demo',
themeMode: theme,
theme: ThemeData(
colorScheme: ColorScheme.fromSeed(
seedColor: const Color(0xFF00b266),
brightness: Brightness.light,
),
useMaterial3: true,
),
darkTheme: ThemeData(
colorScheme: ColorScheme.fromSeed(
seedColor: const Color(0xFF00b266),
brightness: Brightness.dark,
),
useMaterial3: true,
),
home: MyHomePage(
title: 'Week day picker Demo',
isDark: theme == ThemeMode.dark,
callback: () {
setState(() {
theme =
(theme == ThemeMode.dark) ? ThemeMode.light : ThemeMode.dark;
});
},
),
localizationsDelegates: const [
GlobalMaterialLocalizations.delegate,
GlobalWidgetsLocalizations.delegate,
GlobalCupertinoLocalizations.delegate,
],
supportedLocales: const [
Locale('en', ''),
Locale('fr', ''),
Locale('ar', ''),
Locale('es', ''),
Locale('de', ''),
Locale('it', ''),
],
locale: const Locale('en'),
);
}
}
class MyHomePage extends StatefulWidget {
final bool isDark;
final VoidCallback callback;
const MyHomePage({
super.key,
required this.title,
required this.isDark,
required this.callback,
});
final String title;
@override
State<MyHomePage> createState() => _MyHomePageState();
}
class _MyHomePageState extends State<MyHomePage> {
DateTime? selectedDate;
@override
Widget build(BuildContext context) {
DateTime firstDate = DateTime.now().add(const Duration(days: -356));
DateTime lastDate = DateTime.now().add(const Duration(days: 356));
return Scaffold(
appBar: AppBar(
title: Text(widget.title),
actions: [
IconButton(
icon: Icon(widget.isDark
? Icons.light_mode_rounded
: Icons.dark_mode_rounded),
tooltip: 'Theme',
onPressed: widget.callback,
),
const SizedBox(width: 30),
],
),
body: Center(
child: ListView(
children: <Widget>[
Center(
child: Text(
(selectedDate != null)
? 'Selected Date : ${selectedDate.toString().substring(0, 10)}'
: 'Select a date',
style: Theme.of(context).textTheme.titleLarge,
),
),
const SizedBox(height: 10),
Center(
child: ElevatedButton(
onPressed: () async {
var dayWeekPicker = WeekDayPicker(
context: context,
firstDate: firstDate,
lastDate: lastDate,
initialDate: selectedDate,
);
var response = await dayWeekPicker.show();
setState(() {
selectedDate = response;
});
},
child: const Text('Simple Week Day'),
),
),
const SizedBox(height: 10),
Center(
child: ElevatedButton(
onPressed: () async {
var response = await WeekDayPicker(
context: context,
firstDate: firstDate,
lastDate: lastDate,
// currentDate: DateTime(2022, 10, 24),
selectableDayInWeek: [1, 5], //Active Date: Monday & Friday
).show();
setState(() {
selectedDate = response;
});
},
child: const Text('Selectable Day of week'),
),
),
const SizedBox(height: 10),
Center(
child: ElevatedButton(
onPressed: () async {
var response = await WeekDayPicker(
context: context,
firstDate: firstDate,
lastDate: lastDate,
currentDate: DateTime.now(),
selectableDay: [
DateTime.now().add(const Duration(days: -5)),
DateTime.now().add(const Duration(days: 2)),
DateTime.now().add(const Duration(days: 5)),
DateTime.now().add(const Duration(days: 6)),
DateTime.now().add(const Duration(days: 8)),
DateTime.now().add(const Duration(days: 10)),
],
).show();
setState(() {
selectedDate = response;
});
},
child: const Text('Selectable Day'),
),
),
const SizedBox(height: 10),
Center(
child: ElevatedButton(
onPressed: () async {
var response = await WeekDayPicker(
context: context,
firstDate: firstDate,
lastDate: lastDate,
currentDate: DateTime.now(),
selectableDay: [
DateTime.now().add(const Duration(days: -5)),
DateTime.now().add(const Duration(days: 2)),
DateTime.now().add(const Duration(days: 5)),
DateTime.now().add(const Duration(days: 6)),
DateTime.now().add(const Duration(days: 8)),
DateTime.now().add(const Duration(days: 10)),
],
selectableDayInWeek: [1, 5],
).show();
setState(() {
selectedDate = response;
});
},
child: const Text('Two Selectable Inner Join'),
),
),
const SizedBox(height: 10),
Center(
child: ElevatedButton(
onPressed: () async {
WeekDayPicker(
context: context,
firstDate: firstDate,
lastDate: lastDate,
currentDate: DateTime.now(),
initialDate: selectedDate,
selectableDay: [
DateTime.now().add(const Duration(days: -5)),
DateTime.now().add(const Duration(days: 2)),
DateTime.now().add(const Duration(days: 5)),
DateTime.now().add(const Duration(days: 6)),
],
selectableDayInWeek: [1, 5],
selectableBitwiseOperator: BitwiseOperator.or,
);
var response = await WeekDayPicker(
context: context,
//initialDate: DateTime.now(),
firstDate: DateTime.now().add(const Duration(days: -356)),
lastDate: DateTime.now().add(const Duration(days: 356)),
selectableDay: [
DateTime.now().add(const Duration(days: 2)),
DateTime.now().add(const Duration(days: 4)),
],
selectableDayInWeek: [1, 5],
selectableBitwiseOperator: BitwiseOperator.or,
).show();
setState(() {
selectedDate = response;
});
},
child: const Text('Two Selectable Outer Join'),
),
),
const SizedBox(height: 10),
Center(
child: ElevatedButton(
onPressed: () async {
var dayWeekPicker = WeekDayPicker(
context: context,
initialDate: DateTime.now(),
currentDate: DateTime.now().add(const Duration(days: -3)),
firstDate: DateTime.now().add(const Duration(days: -356)),
lastDate: DateTime.now().add(const Duration(days: 356)),
colorHeader: Colors.blue[700],
colorOnHeader: Colors.blue[100],
colorIcon: Colors.blueAccent[200],
colorDisabled: Colors.blueGrey[100],
colorSelected: Colors.blue[800],
colorOnSelected: Colors.lightBlue[100],
);
var response = await dayWeekPicker.show();
setState(() {
selectedDate = response;
});
},
child: const Text('Custom Color'),
),
),
const SizedBox(height: 10),
Center(
child: ElevatedButton(
onPressed: () async {
var dayWeekPicker = WeekDayPicker(
context: context,
firstDate: DateTime.now().add(const Duration(days: -500)),
lastDate: DateTime.now().add(const Duration(days: 500)),
locale: const Locale('de', ''),
);
var response = await dayWeekPicker.show();
setState(() {
selectedDate = response;
});
},
child: const Text('Dutch'),
),
),
const SizedBox(height: 10),
Center(
child: ElevatedButton(
onPressed: () async {
var dayWeekPicker = WeekDayPicker(
context: context,
firstDate: DateTime.now().add(const Duration(days: -500)),
lastDate: DateTime.now().add(const Duration(days: 500)),
locale: const Locale('it', ''),
);
var response = await dayWeekPicker.show();
setState(() {
selectedDate = response;
});
},
child: const Text('Italie'),
),
),
const SizedBox(height: 10),
Center(
child: ElevatedButton(
onPressed: () async {
var dayWeekPicker = WeekDayPicker(
context: context,
firstDate: DateTime.now().add(const Duration(days: -500)),
lastDate: DateTime.now().add(const Duration(days: 500)),
locale: const Locale('en', ''),
);
var response = await dayWeekPicker.show();
setState(() {
selectedDate = response;
});
},
child: const Text('English'),
),
),
const SizedBox(height: 10),
Center(
child: ElevatedButton(
onPressed: () async {
//showDatePicker(context: context, initialDate: initialDate, firstDate: firstDate, lastDate: lastDate)
var dayWeekPicker = WeekDayPicker(
context: context,
firstDate: DateTime.now().add(const Duration(days: -500)),
lastDate: DateTime.now().add(const Duration(days: 500)),
locale: const Locale('ar', ''),
);
var response = await dayWeekPicker.show();
setState(() {
selectedDate = response;
});
},
child: const Text('Arabe'),
),
),
],
),
),
);
}
}