Skip to content
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
10 changes: 5 additions & 5 deletions example/main.dart
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ import 'package:flutter_sinusoidals/flutter_sinusoidals.dart';
void main() => runApp(const MyApp());

class MyApp extends StatelessWidget {
const MyApp({Key key}) : super(key: key);
const MyApp({Key? key}) : super(key: key);

@override
Widget build(BuildContext context) {
Expand All @@ -28,7 +28,7 @@ const _colors = [
];

class _SinusoidalsDemo extends StatelessWidget {
const _SinusoidalsDemo({Key key}) : super(key: key);
const _SinusoidalsDemo({Key? key}) : super(key: key);

static const _amplitude = 45.0;
static const _waves = 3.0;
Expand Down Expand Up @@ -85,7 +85,7 @@ class _SinusoidalsDemo extends StatelessWidget {
}

class _SinusoidalDemo extends StatelessWidget {
const _SinusoidalDemo({Key key}) : super(key: key);
const _SinusoidalDemo({Key? key}) : super(key: key);

@override
Widget build(BuildContext context) {
Expand Down Expand Up @@ -149,7 +149,7 @@ class _SinusoidalDemo extends StatelessWidget {
}

class _CombinedWaveDemo extends StatelessWidget {
const _CombinedWaveDemo({Key key}) : super(key: key);
const _CombinedWaveDemo({Key? key}) : super(key: key);

@override
Widget build(BuildContext context) {
Expand Down Expand Up @@ -205,7 +205,7 @@ class _CombinedWaveDemo extends StatelessWidget {
}

class _MagmaWaveDemo extends StatelessWidget {
const _MagmaWaveDemo({Key key}) : super(key: key);
const _MagmaWaveDemo({Key? key}) : super(key: key);

@override
Widget build(BuildContext context) {
Expand Down
98 changes: 48 additions & 50 deletions lib/flutter_sinusoidals.dart
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,6 @@
// Use of this source code is governed by a license that can be
// found in the LICENSE file.

// @dart = 2.9

import 'dart:math' as math;

import 'package:flutter/widgets.dart';
Expand All @@ -28,7 +26,7 @@ typedef SinusoidalItemBuilder = SinusoidalItem Function(
class SinusoidalItem {
const SinusoidalItem({
this.model = const SinusoidalModel(),
@required this.child,
required this.child,
}) : assert(child != null);

/// A given child at which will be clipped from to create a sinusoidal.
Expand Down Expand Up @@ -166,11 +164,11 @@ class SinusoidalModel extends Equatable {
///
class Sinusoidals extends _BaseWaveWidget {
const Sinusoidals({
Key key,
@required this.itemCount,
@required this.builder,
int period,
bool reverse,
Key? key,
required this.itemCount,
required this.builder,
int? period,
bool? reverse,
this.alignment = AlignmentDirectional.topStart,
}) : assert(itemCount != null),
assert(builder != null),
Expand Down Expand Up @@ -247,11 +245,11 @@ class _SinusoidalsState extends _BaseWaveWidgetState<Sinusoidals> {
///
class Sinusoidal extends _BaseWaveWidget {
const Sinusoidal({
Key key,
Key? key,
this.model = const SinusoidalModel(),
int period,
bool reverse,
@required this.child,
int? period,
bool? reverse,
required this.child,
}) : assert(child != null),
super(
key: key,
Expand Down Expand Up @@ -323,11 +321,11 @@ class _SinusoidalState extends _BaseWaveWidgetState<Sinusoidal> {
///
class CombinedWave extends _BaseWaveWidget {
const CombinedWave({
Key key,
@required this.models,
int period,
bool reverse,
@required this.child,
Key? key,
required this.models,
int? period,
bool? reverse,
required this.child,
}) : assert(child != null),
super(
key: key,
Expand Down Expand Up @@ -364,10 +362,10 @@ class _CombinedWaveState extends _BaseWaveWidgetState<CombinedWave> {
/// [child]'s height need to be at least 100 to work.
class MagmaWave extends _BaseWaveWidget {
const MagmaWave({
Key key,
int period,
bool reverse,
@required this.child,
Key? key,
int? period,
bool? reverse,
required this.child,
}) : assert(child != null),
super(
key: key,
Expand Down Expand Up @@ -397,23 +395,23 @@ class _MagmaWaveState extends _BaseWaveWidgetState<MagmaWave> {

abstract class _BaseWaveWidget extends StatefulWidget {
const _BaseWaveWidget({
Key key,
Key? key,
this.period,
this.reverse,
}) : super(key: key);

/// The period (measured in milliseconds) to complete a full revolution.
final int period;
final int? period;

/// If `reverse = true`, then clipping from bottom to top.
///
/// Default is clipping from top to bottom.
final bool reverse;
final bool? reverse;
}

abstract class _BaseWaveWidgetState<T extends _BaseWaveWidget> extends State<T>
with SingleTickerProviderStateMixin<T> {
AnimationController _timeController;
AnimationController? _timeController;

@override
void initState() {
Expand All @@ -424,12 +422,12 @@ abstract class _BaseWaveWidgetState<T extends _BaseWaveWidget> extends State<T>
animationBehavior: AnimationBehavior.preserve,
duration: Duration(milliseconds: widget.period ?? 5000),
);
_timeController.repeat();
_timeController!.repeat();
}

@override
void dispose() {
_timeController.dispose();
_timeController!.dispose();
super.dispose();
}
}
Expand All @@ -443,9 +441,9 @@ class _SinusoidalClipper extends CustomClipper<Path> {

static final List<Offset> offsets = <Offset>[];

final Animation<double> time;
final SinusoidalModel model;
final bool reverse;
final Animation<double>? time;
final SinusoidalModel? model;
final bool? reverse;

@override
Path getClip(Size size) {
Expand All @@ -455,13 +453,13 @@ class _SinusoidalClipper extends CustomClipper<Path> {
offsets.add(Offset(dx, _getY(size, dx)));
}

return _getPath(reverse, offsets, size);
return _getPath(reverse!, offsets, size);
}

double _getY(Size size, double dx) {
final y = model.getY(dx, time.value);
final amplitude = model.amplitude;
return reverse ? size.height - y - amplitude : y + amplitude;
final y = model!.getY(dx, time!.value);
final amplitude = model!.amplitude;
return reverse! ? size.height - y - amplitude : y + amplitude;
}

@override
Expand All @@ -480,9 +478,9 @@ class _CombinedWaveClipper extends CustomClipper<Path> {

static final List<Offset> offsets = <Offset>[];

final Animation<double> time;
final List<SinusoidalModel> models;
final bool reverse;
final Animation<double>? time;
final List<SinusoidalModel>? models;
final bool? reverse;

@override
Path getClip(Size size) {
Expand All @@ -492,17 +490,17 @@ class _CombinedWaveClipper extends CustomClipper<Path> {
offsets.add(Offset(dx, _getY(size, dx)));
}

return _getPath(reverse, offsets, size);
return _getPath(reverse!, offsets, size);
}

double _getY(Size size, double dx) {
final y = models
.map((model) => model.getY(dx, time.value))
final y = models!
.map((model) => model.getY(dx, time!.value))
.reduce((current, next) => current + next);
final amplitude = models
final amplitude = models!
.map((model) => model.amplitude)
.reduce((current, next) => current + next);
return reverse ? size.height - y - amplitude : y + amplitude;
return reverse! ? size.height - y - amplitude : y + amplitude;
}

@override
Expand All @@ -520,8 +518,8 @@ class _MagmaWaveClipper extends CustomClipper<Path> {

static final List<Offset> offsets = <Offset>[];

final Animation<double> time;
final bool reverse;
final Animation<double>? time;
final bool? reverse;

@override
Path getClip(Size size) {
Expand All @@ -531,18 +529,18 @@ class _MagmaWaveClipper extends CustomClipper<Path> {
offsets.add(Offset(dx, _getY(size, dx)));
}

return _getPath(reverse, offsets, size);
return _getPath(reverse!, offsets, size);
}

double _getY(Size size, double dx) {
final y = _getNormalY1(dx, time.value) +
_getNormalY2(dx, time.value) +
_getNormalY3(dx, time.value) +
_getNormalY4(dx, time.value);
final y = _getNormalY1(dx, time!.value) +
_getNormalY2(dx, time!.value) +
_getNormalY3(dx, time!.value) +
_getNormalY4(dx, time!.value);

const amplitude = 100;

return reverse ? size.height - y - amplitude : y + amplitude;
return reverse! ? size.height - y - amplitude : y + amplitude;
}

double _getNormalY1(double dx, double time) =>
Expand Down
6 changes: 3 additions & 3 deletions pubspec.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -2,16 +2,16 @@ name: flutter_sinusoidals
description: >-
A flutter package that helps you to visualize sine waves as you desire.
All basic waves are already supported, plus customized waves & some pre-defined waves.
version: 0.1.4
version: 0.1.4-nullsafety.0
homepage: https://github.com/dungnv2602/flutter_sinusoidals

environment:
sdk: '>=2.9.0 <3.0.0'
sdk: '>=2.12.0 <3.0.0'

dependencies:
flutter:
sdk: flutter
equatable: ^1.2.5
equatable: ^2.0.0-nullsafety.4

dev_dependencies:
flutter_test:
Expand Down