Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Migrating to nullsafe. #11

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 6 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,11 @@
# Changelog

## [2.0.0-nullsafety.1] - 2021-03-31

### Fixed

- Migrating to null-safe.

## [1.3.1] - 2020-08-10

### Fixed
Expand Down
9 changes: 5 additions & 4 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,16 +1,17 @@
<p align="center">
<img
src="https://raw.githubusercontent.com/mennorenkens/flutter_scrolling_calendar/master/screenshots/screenshot.png"
src="https://raw.githubusercontent.com/marcosneivanery/flutter_scrolling_calendar/master/screenshots/screenshot.png"
height="400"
>
</p>

[![Pub Version](https://img.shields.io/pub/v/scrolling_years_calendar)](https://pub.dev/packages/scrolling_years_calendar)
[![Starware](https://img.shields.io/badge/Starware-⭐-black?labelColor=f9b00d)](https://github.com/zepfietje/starware)
[![Pub Version](https://img.shields.io/pub/v/scrolling_years_calendar_nullsafety)](https://pub.dev/packages/scrolling_years_calendar_nullsafety)

# Flutter Scrolling Calendar
# Flutter Scrolling Calendar Null Safety

A customizable calendar widget to easily scroll through the years.
Forked from:
https://github.com/mennorenkens/flutter_scrolling_calendar/

## Features

Expand Down
27 changes: 21 additions & 6 deletions example/android/app/src/main/AndroidManifest.xml
Original file line number Diff line number Diff line change
Expand Up @@ -17,17 +17,32 @@
android:configChanges="orientation|keyboardHidden|keyboard|screenSize|locale|layoutDirection|fontScale|screenLayout|density|uiMode"
android:hardwareAccelerated="true"
android:windowSoftInputMode="adjustResize">
<!-- This keeps the window background of the activity showing
until Flutter renders its first frame. It can be removed if
there is no splash screen (such as the default splash screen
defined in @style/LaunchTheme). -->
<!-- Specifies an Android theme to apply to this Activity as soon as
the Android process has started. This theme is visible to the user
while the Flutter UI initializes. After that, this theme continues
to determine the Window background behind the Flutter UI. -->
<meta-data
android:name="io.flutter.app.android.SplashScreenUntilFirstFrame"
android:value="true" />
android:name="io.flutter.embedding.android.NormalTheme"
android:resource="@style/NormalTheme"
/>
<!-- Displays an Android View that continues showing the launch screen
Drawable until Flutter paints its first frame, then this splash
screen fades out. A splash screen is useful to avoid any visual
gap between the end of Android's launch screen and the painting of
Flutter's first frame. -->
<meta-data
android:name="io.flutter.embedding.android.SplashScreenDrawable"
android:resource="@drawable/launch_background"
/>
<intent-filter>
<action android:name="android.intent.action.MAIN"/>
<category android:name="android.intent.category.LAUNCHER"/>
</intent-filter>
</activity>
<!-- Don't delete the meta-data below.
This is used by the Flutter tool to generate GeneratedPluginRegistrant.java -->
<meta-data
android:name="flutterEmbedding"
android:value="2" />
</application>
</manifest>
Original file line number Diff line number Diff line change
@@ -1,13 +1,7 @@
package com.example.example;

import android.os.Bundle;
import io.flutter.app.FlutterActivity;
import io.flutter.plugins.GeneratedPluginRegistrant;
import io.flutter.embedding.android.FlutterActivity;

public class MainActivity extends FlutterActivity {
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
GeneratedPluginRegistrant.registerWith(this);
}

}
10 changes: 10 additions & 0 deletions example/android/app/src/main/res/values/styles.xml
Original file line number Diff line number Diff line change
@@ -1,8 +1,18 @@
<?xml version="1.0" encoding="utf-8"?>
<resources>
<!-- Theme applied to the Android Window while the process is starting -->
<style name="LaunchTheme" parent="@android:style/Theme.Black.NoTitleBar">
<!-- Show a splash screen on the activity. Automatically removed when
Flutter draws its first frame -->
<item name="android:windowBackground">@drawable/launch_background</item>
</style>
<!-- Theme applied to the Android Window as soon as the process has started.
This theme determines the color of the Android Window while your
Flutter UI initializes, as well as behind your Flutter UI while its
running.

This Theme is only used starting with V2 of Flutter's Android embedding. -->
<style name="NormalTheme" parent="@android:style/Theme.Black.NoTitleBar">
<item name="android:windowBackground">@android:color/white</item>
</style>
</resources>
13 changes: 13 additions & 0 deletions example/ios/Flutter/flutter_export_environment.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
#!/bin/sh
# This is a generated file; do not edit or check into version control.
export "FLUTTER_ROOT=C:\flutter"
export "FLUTTER_APPLICATION_PATH=D:\VS\SourceGit\scrolling_years_calendar_nullsafe\example"
export "FLUTTER_TARGET=lib\main.dart"
export "FLUTTER_BUILD_DIR=build"
export "SYMROOT=${SOURCE_ROOT}/../build\ios"
export "FLUTTER_BUILD_NAME=1.0.0"
export "FLUTTER_BUILD_NUMBER=1"
export "DART_OBFUSCATION=false"
export "TRACK_WIDGET_CREATION=false"
export "TREE_SHAKE_ICONS=false"
export "PACKAGE_CONFIG=.packages"
4 changes: 2 additions & 2 deletions example/lib/main.dart
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import 'package:flutter/material.dart';
import 'package:scrolling_years_calendar/scrolling_years_calendar.dart';
import 'package:scrolling_years_calendar_nullsafety/scrolling_years_calendar.dart';

void main() => runApp(MyApp());

Expand Down Expand Up @@ -54,7 +54,7 @@ class HomePage extends StatelessWidget {
'Dec',
],
onMonthTap: (int year, int month) => print('Tapped $month/$year'),
monthTitleStyle: TextStyle(
monthTitleStyle: const TextStyle(
fontSize: 16,
fontWeight: FontWeight.bold,
color: Colors.blue,
Expand Down
17 changes: 8 additions & 9 deletions example/pubspec.lock
Original file line number Diff line number Diff line change
Expand Up @@ -7,14 +7,14 @@ packages:
name: characters
url: "https://pub.dartlang.org"
source: hosted
version: "1.0.0"
version: "1.1.0"
collection:
dependency: transitive
description:
name: collection
url: "https://pub.dartlang.org"
source: hosted
version: "1.14.13"
version: "1.15.0"
flutter:
dependency: "direct main"
description: flutter
Expand All @@ -26,14 +26,14 @@ packages:
name: meta
url: "https://pub.dartlang.org"
source: hosted
version: "1.1.8"
scrolling_years_calendar:
version: "1.3.0"
scrolling_years_calendar_nullsafety:
dependency: "direct main"
description:
path: ".."
relative: true
source: path
version: "1.2.1"
version: "2.0.0-nullsafety.1"
sky_engine:
dependency: transitive
description: flutter
Expand All @@ -45,14 +45,13 @@ packages:
name: typed_data
url: "https://pub.dartlang.org"
source: hosted
version: "1.2.0"
version: "1.3.0"
vector_math:
dependency: transitive
description:
name: vector_math
url: "https://pub.dartlang.org"
source: hosted
version: "2.0.8"
version: "2.1.0"
sdks:
dart: ">=2.9.0-14.0.dev <3.0.0"
flutter: ">=1.5.0 <2.0.0"
dart: ">=2.12.0 <3.0.0"
5 changes: 4 additions & 1 deletion example/pubspec.yaml
Original file line number Diff line number Diff line change
@@ -1,8 +1,11 @@
name: scrolling_years_calendar_example
description: Demonstrates how to use the scrolling_years_calendar plugin.

environment:
sdk: '>=2.12.0 <3.0.0'

dependencies:
flutter:
sdk: flutter
scrolling_years_calendar:
scrolling_years_calendar_nullsafety:
path: ../
6 changes: 3 additions & 3 deletions lib/day_number.dart
Original file line number Diff line number Diff line change
@@ -1,14 +1,14 @@
import 'package:flutter/material.dart';
import 'package:scrolling_years_calendar/utils/screen_sizes.dart';
import 'package:scrolling_years_calendar_nullsafety/utils/screen_sizes.dart';

class DayNumber extends StatelessWidget {
const DayNumber({
@required this.day,
required this.day,
this.color,
});

final int day;
final Color color;
final Color? color;

@override
Widget build(BuildContext context) {
Expand Down
8 changes: 4 additions & 4 deletions lib/month_title.dart
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
import 'package:flutter/material.dart';
import 'package:scrolling_years_calendar/utils/dates.dart';
import 'package:scrolling_years_calendar_nullsafety/utils/dates.dart';

class MonthTitle extends StatelessWidget {
const MonthTitle({
@required this.month,
required this.month,
this.monthNames,
this.style = const TextStyle(
fontSize: 18,
Expand All @@ -12,8 +12,8 @@ class MonthTitle extends StatelessWidget {
});

final int month;
final List<String> monthNames;
final TextStyle style;
final List<String>? monthNames;
final TextStyle? style;

@override
Widget build(BuildContext context) {
Expand Down
49 changes: 28 additions & 21 deletions lib/month_view.dart
Original file line number Diff line number Diff line change
@@ -1,41 +1,42 @@
import 'package:flutter/material.dart';
import 'package:scrolling_years_calendar/utils/dates.dart';
import 'package:scrolling_years_calendar/utils/screen_sizes.dart';
import 'package:scrolling_years_calendar/month_title.dart';
import 'package:scrolling_years_calendar/day_number.dart';
import 'package:scrolling_years_calendar_nullsafety/utils/dates.dart';
import 'package:scrolling_years_calendar_nullsafety/utils/screen_sizes.dart';
import 'package:scrolling_years_calendar_nullsafety/month_title.dart';
import 'package:scrolling_years_calendar_nullsafety/day_number.dart';

class MonthView extends StatelessWidget {
const MonthView({
@required this.context,
@required this.year,
@required this.month,
@required this.padding,
@required this.currentDateColor,
required this.context,
required this.year,
required this.month,
required this.padding,
required this.currentDateColor,
this.highlightedDates,
this.highlightedDateColor,
this.monthNames,
this.onTap,
this.titleStyle,
this.titleStyle =
const TextStyle(fontSize: 18, fontWeight: FontWeight.w600),
});

final BuildContext context;
final int year;
final int month;
final double padding;
final Color currentDateColor;
final List<DateTime> highlightedDates;
final Color highlightedDateColor;
final List<String> monthNames;
final Function onTap;
final TextStyle titleStyle;
final List<DateTime>? highlightedDates;
final Color? highlightedDateColor;
final List<String>? monthNames;
final Function? onTap;
final TextStyle? titleStyle;

Color getDayNumberColor(DateTime date) {
Color color;
Color color = Colors.transparent;
if (isCurrentDate(date)) {
color = currentDateColor;
} else if (highlightedDates != null &&
isHighlightedDate(date, highlightedDates)) {
color = highlightedDateColor;
color = highlightedDateColor ?? color;
}
return color;
}
Expand All @@ -48,7 +49,7 @@ class MonthView extends StatelessWidget {
final int firstWeekdayOfMonth = DateTime(year, month, 1).weekday;

for (int day = 2 - firstWeekdayOfMonth; day <= daysInMonth; day++) {
Color color;
Color color = Colors.transparent;
if (day > 0) {
color = getDayNumberColor(DateTime(year, month, day));
}
Expand Down Expand Up @@ -104,9 +105,15 @@ class MonthView extends StatelessWidget {
? Container(
child: buildMonthView(context),
)
: FlatButton(
onPressed: () => onTap(year, month),
padding: const EdgeInsets.all(0.0),
: TextButton(
onPressed: () {
if (onTap != null) {
onTap!(year, month);
}
},
style: TextButton.styleFrom(
padding: const EdgeInsets.all(0.0),
),
child: buildMonthView(context),
);
}
Expand Down
31 changes: 13 additions & 18 deletions lib/scrolling_years_calendar.dart
Original file line number Diff line number Diff line change
@@ -1,32 +1,27 @@
library scrolling_years_calendar;

import 'package:flutter/material.dart';
import 'package:scrolling_years_calendar/utils/screen_sizes.dart';
import 'package:scrolling_years_calendar/year_view.dart';
import 'package:scrolling_years_calendar_nullsafety/utils/screen_sizes.dart';
import 'package:scrolling_years_calendar_nullsafety/year_view.dart';

class ScrollingYearsCalendar extends StatefulWidget {
ScrollingYearsCalendar({
@required this.context,
@required this.initialDate,
@required this.firstDate,
@required this.lastDate,
@required this.currentDateColor,
required this.context,
required this.initialDate,
required this.firstDate,
required this.lastDate,
required this.currentDateColor,
this.highlightedDates,
this.highlightedDateColor,
this.monthNames,
this.onMonthTap,
this.monthTitleStyle,
}) : assert(context != null),
assert(initialDate != null),
assert(firstDate != null),
assert(lastDate != null),
assert(!initialDate.isBefore(firstDate),
}) : assert(!initialDate.isBefore(firstDate),
'initialDate must be on or after firstDate'),
assert(!initialDate.isAfter(lastDate),
'initialDate must be on or before lastDate'),
assert(!firstDate.isAfter(lastDate),
'lastDate must be on or after firstDate'),
assert(currentDateColor != null),
assert(highlightedDates == null || highlightedDateColor != null,
'highlightedDateColor is required if highlightedDates is not null'),
assert(
Expand All @@ -38,11 +33,11 @@ class ScrollingYearsCalendar extends StatefulWidget {
final DateTime firstDate;
final DateTime lastDate;
final Color currentDateColor;
final List<DateTime> highlightedDates;
final Color highlightedDateColor;
final List<String> monthNames;
final Function onMonthTap;
final TextStyle monthTitleStyle;
final List<DateTime>? highlightedDates;
final Color? highlightedDateColor;
final List<String>? monthNames;
final Function? onMonthTap;
final TextStyle? monthTitleStyle;

@override
_ScrollingYearsCalendarState createState() => _ScrollingYearsCalendarState();
Expand Down
Loading