daily pastebin goal
10%
SHARE
TWEET

Untitled

a guest Jan 24th, 2019 67 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. import 'package:flutter/material.dart';
  2. import 'package:father_home_flutter/model/constants.dart';
  3. import 'package:flutter_calendar_carousel/classes/event.dart';
  4. import 'package:flutter_calendar_carousel/classes/event_list.dart';
  5. import 'package:flutter_calendar_carousel/flutter_calendar_carousel.dart'
  6.     show CalendarCarousel;
  7.  
  8. class ScreenCalendar extends StatefulWidget {
  9.   @override
  10.   _ScreenCalendarState createState() => new _ScreenCalendarState();
  11. }
  12.  
  13. class _ScreenCalendarState extends State<ScreenCalendar> {
  14.   static String noEventText = "No event here";
  15.   String calendarText = noEventText;
  16.  
  17.   @override
  18.   void initState() {
  19.     _markedDateMap.add(
  20.         new DateTime(2019, 1, 25),
  21.         new Event(
  22.           date: new DateTime(2019, 1, 25),
  23.           title: 'Event 5',
  24.           icon: _eventIcon,
  25.         ));
  26.  
  27.     _markedDateMap.add(
  28.         new DateTime(2019, 1, 10),
  29.         new Event(
  30.           date: new DateTime(2019, 1, 10),
  31.           title: 'Event 4',
  32.           icon: _eventIcon,
  33.         ));
  34.  
  35.     _markedDateMap.addAll(new DateTime(2019, 1, 11), [
  36.       new Event(
  37.         date: new DateTime(2019, 1, 11),
  38.         title: 'Event 1',
  39.         icon: _eventIcon,
  40.       ),
  41.       new Event(
  42.         date: new DateTime(2019, 1, 11),
  43.         title: 'Event 2',
  44.         icon: _eventIcon,
  45.       ),
  46.       new Event(
  47.         date: new DateTime(2019, 1, 11),
  48.         title: 'Event 3',
  49.         icon: _eventIcon,
  50.       ),
  51.     ]);
  52.     super.initState();
  53.   }
  54.  
  55.   @override
  56.   Widget build(BuildContext context) {
  57.     return Scaffold(
  58.         appBar: AppBar(
  59.           title: Text(
  60.             'Календар',
  61.             style: Constants.myTextStyleAppBar,
  62.           ),
  63.           iconTheme: Constants.myIconThemeDataAppBar,
  64.           elevation: Constants.myElevationAppBar,
  65.           backgroundColor: Constants.myAppBarColor,
  66.         ),
  67.         body: SingleChildScrollView(
  68.             child: Column(children: <Widget>[
  69.           Card(
  70.               child: CalendarCarousel(
  71.             weekendTextStyle: TextStyle(
  72.               color: Colors.red,
  73.             ),
  74.             weekFormat: false,
  75.             selectedDayBorderColor: Colors.green,
  76.             markedDatesMap: _markedDateMap,
  77.             selectedDayButtonColor: Colors.green,
  78.             selectedDayTextStyle: TextStyle(color: Colors.green),
  79.             todayBorderColor: Colors.transparent,
  80.             weekdayTextStyle: TextStyle(color: Colors.black),
  81.             height: 420.0,
  82.             daysHaveCircularBorder: true,
  83.             todayButtonColor: Colors.indigo,
  84.             locale: 'RUS',
  85.             onDayPressed: (DateTime date, List<Event> events) {
  86.               this.setState(() => refresh(date));
  87.             },
  88.           )),
  89.           Card(
  90.               child: Container(
  91.                   child: Padding(
  92.                       padding: EdgeInsets.fromLTRB(16.0, 16.0, 16.0, 16.0),
  93.                       child: Center(
  94.                           child: Text(
  95.                         calendarText,
  96.                         style: Constants.textStyleCommonText,
  97.                       )))))
  98.         ])));
  99.   }
  100.  
  101.   void refresh(DateTime date) {
  102.     print('selected date ' +
  103.         date.day.toString() +
  104.         date.month.toString() +
  105.         date.year.toString() +
  106.         ' ' +
  107.         date.toString());
  108.     if(_markedDateMap.getEvents(new DateTime(date.year, date.month, date.day)).isNotEmpty){
  109.       calendarText = _markedDateMap
  110.           .getEvents(new DateTime(date.year, date.month, date.day))[0]
  111.           .title;
  112.     } else{
  113.       calendarText = noEventText;
  114.     }
  115.     }
  116.   }
  117.  
  118.   EventList<Event> _markedDateMap = new EventList<Event>(events: {
  119.     new DateTime(2019, 1, 24): [
  120.       new Event(
  121.         date: new DateTime(2019, 1, 24),
  122.         title: 'Lorem ipsum dolor sit amet, consectetur adipiscing elit, '
  123.             'sed eiusmod tempor incidunt ut labore et dolore magna aliqua.'
  124.             ' nnUt enim ad minim veniam,'
  125.             ' quis nostrud exercitation ullamco laboris nisi ut aliquid ex ea commodi consequat.'
  126.             ' nnQuis aute iure reprehenderit in voluptate velit esse cillum dolore eu fugiat nulla pariatur. '
  127.             'Excepteur sint obcaecat cupiditat non proident, sunt in culpa qui officia deserunt mollit anim id est laborum.',
  128.         icon: _eventIcon,
  129.       )
  130.     ]
  131.   });
  132.  
  133.    Widget _eventIcon = new Container(
  134.     decoration: new BoxDecoration(
  135.         color: Colors.white,
  136.         borderRadius: BorderRadius.all(Radius.circular(1000)),
  137.         border: Border.all(color: Colors.blue, width: 2.0)),
  138.     child: new Icon(
  139.       Icons.person,
  140.       color: Colors.amber,
  141.     ),
  142.   );
  143.    
  144. selectedDayBorderColor: Colors.green,
  145.  selectedDayButtonColor: Colors.green,
  146.  selectedDayTextStyle: TextStyle(color: Colors.green),
  147.    
  148. Theme(data: ThemeData(
  149.       splashColor: Colors.green,
  150.     )
  151.     child: YourCarouselWidget(),
  152. );
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand
 
Top