Untitled
user_2717664
plain_text
a year ago
7.2 kB
14
Indexable
import 'package:flutter/cupertino.dart';
import 'package:flutter/material.dart';
import 'package:table_calendar/table_calendar.dart';
class MyCalendar extends StatefulWidget {
@override
_MyCalendarState createState() => _MyCalendarState();
}
class _MyCalendarState extends State<MyCalendar> {
DateTime _focusedDay = DateTime.now();
DateTime? _selectedDay;
bool isVisible = false;
var samp;
void _onDaySelected(DateTime selectedDay, DateTime focusedDay) {
setState(() {
_selectedDay = selectedDay;
_focusedDay = focusedDay;
});
}
@override
Widget build(BuildContext context) {
return Scaffold(
backgroundColor: Colors.white,
appBar: AppBar(
title: const Text('TableCalendar Example'),
),
body: Column(
children: [
ElevatedButton(
onPressed: () {
setState(() {
isVisible = !isVisible;
});
},
child: const Text("hi")),
Padding(
padding: const EdgeInsets.symmetric(horizontal: 50),
child: Visibility(
visible: true,
child: TableCalendar(
onHeaderTapped: (focusedDay) {},
pageJumpingEnabled: true,
daysOfWeekStyle: const DaysOfWeekStyle(
weekdayStyle: TextStyle(color: Colors.grey),
weekendStyle: TextStyle(
color: Colors.grey,
)),
rowHeight: 40,
availableGestures: AvailableGestures.all,
calendarStyle: CalendarStyle(
markerDecoration: BoxDecoration(shape: BoxShape.rectangle),
selectedDecoration: BoxDecoration(
color: Colors.black,
shape: BoxShape.circle,
),
todayDecoration: BoxDecoration(
color: Colors.grey,
shape: BoxShape.circle,
),
),
selectedDayPredicate: (day) => isSameDay(day, _selectedDay),
onDaySelected: _onDaySelected,
headerStyle: const HeaderStyle(
titleTextStyle: TextStyle(color: Colors.amber),
formatButtonVisible: false,
titleCentered: true,
),
firstDay: DateTime.utc(2010, 10, 16),
lastDay: DateTime.utc(2030, 3, 14),
focusedDay: _focusedDay,
),
),
),
///////////////////////////////////////////
CustomSwitch(
value: isVisible,
onChanged: (s) {
setState(() {
isVisible = !isVisible;
});
}),
////////////////////////////////////////////
InputDropdown(
items: [],
// value: samp,
onChanged: (s) {},
)
],
),
);
}
}
void main() => runApp(MaterialApp(
home: MyCalendar(),
));
class CustomSwitch extends StatefulWidget {
final bool value;
final ValueChanged<bool> onChanged;
CustomSwitch({Key? key, required this.value, required this.onChanged})
: super(key: key);
@override
_CustomSwitchState createState() => _CustomSwitchState();
}
class _CustomSwitchState extends State<CustomSwitch>
with SingleTickerProviderStateMixin {
late AnimationController _animationController;
late Animation<Alignment> _circleAnimation;
bool isFirstCircleVisible = false;
@override
void initState() {
super.initState();
_animationController = AnimationController(
vsync: this,
duration: Duration(milliseconds: 200),
);
_circleAnimation = AlignmentTween(
begin: widget.value ? Alignment.centerRight : Alignment.centerLeft,
end: widget.value ? Alignment.centerLeft : Alignment.centerRight,
).animate(CurvedAnimation(
parent: _animationController,
curve: Curves.easeInOut,
));
}
@override
Widget build(BuildContext context) {
return GestureDetector(
onTap: () {
if (_animationController.isCompleted) {
_animationController.reverse();
} else {
_animationController.forward();
}
widget.onChanged(!widget.value);
setState(() {
isFirstCircleVisible = !isFirstCircleVisible;
});
},
child: Container(
width: 80.0,
height: 40.0,
decoration: BoxDecoration(
borderRadius: BorderRadius.circular(30),
color: Colors.transparent,
),
child: Stack(
children: [
Center(
child: Container(
height: 30.0,
width: 80.0,
decoration: BoxDecoration(
color: Color(0xffF1F1F1),
borderRadius: BorderRadius.circular(30),
),
),
),
AnimatedBuilder(
animation: _animationController,
builder: (context, child) {
return Align(
alignment: _circleAnimation.value,
child: Container(
width: 40.0,
height: 40.0,
decoration: BoxDecoration(
color: Colors.white,
border: Border.all(color: Color(0xffF1F1F1)),
shape: BoxShape.circle,
),
),
);
},
),
],
),
),
);
}
@override
void dispose() {
_animationController.dispose();
super.dispose();
}
}
//////
class InputDropdown extends StatelessWidget {
// final String? value;
final ValueChanged<String?>? onChanged;
final List<DropdownMenuItem<String>> items;
const InputDropdown({
Key? key,
// required this.value,
required this.onChanged,
required this.items,
}) : super(key: key);
@override
Widget build(BuildContext context) {
return InputDecorator(
decoration: InputDecoration(
border: InputBorder.none,
// OutlineInputBorder(
// borderRadius: BorderRadius.circular(10),
// // borderSide: BorderSide(
// // color: Colors.transparent), // Changed outline color to red
// ),
contentPadding: const EdgeInsets.symmetric(horizontal: 12.0),
suffixIcon: Icon(Icons.keyboard_arrow_down_outlined,
color: Colors
.black // Fallback to Colors.grey if colors(context).text is null
),
),
child: Container(
decoration: BoxDecoration(
borderRadius: BorderRadius.all(Radius.circular(8)),
border: Border.all(color: Colors.amber)),
child: DropdownButtonHideUnderline(
child: DropdownButton<String>(
// value: value,
onChanged: onChanged,
items: items,
icon: null, // No icon displayed
),
),
),
);
}
}
Editor is loading...
Leave a Comment