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

Fix lints #4

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
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
39 changes: 24 additions & 15 deletions lib/flutter_fadein.dart
Original file line number Diff line number Diff line change
@@ -1,8 +1,19 @@
// ignore_for_file: library_private_types_in_public_api

import 'dart:async';

import 'package:flutter/widgets.dart';

class FadeIn extends StatefulWidget {
const FadeIn({
super.key,
this.controller,
this.child,
this.duration = const Duration(milliseconds: 250),
this.curve = Curves.easeIn,
this.delay = Duration.zero,
});

/// Fade-in controller
final FadeInController? controller;

Expand All @@ -12,17 +23,12 @@ class FadeIn extends StatefulWidget {
/// Duration of fade-in. Defaults to 250ms
final Duration duration;

/// Delay before fade-in. Defaults to 0ms. Cannot be used with a controller
final Duration delay;

/// Fade-in curve. Defaults to [Curves.easeIn]
final Curve curve;

const FadeIn({
Key? key,
this.controller,
this.child,
this.duration = const Duration(milliseconds: 250),
this.curve = Curves.easeIn,
}) : super(key: key);

@override
_FadeInState createState() => _FadeInState();
}
Expand All @@ -34,12 +40,13 @@ enum FadeInAction {

/// Fade-in controller which dispatches fade-in/fade-out actions
class FadeInController {
final _streamController = StreamController<FadeInAction>();
FadeInController({
this.autoStart = false,
});

/// Automatically starts the initial fade-in. Defaults to false
final bool autoStart;

FadeInController({this.autoStart = false});
final _streamController = StreamController<FadeInAction>();

void dispose() => _streamController.close();

Expand All @@ -64,15 +71,19 @@ class _FadeInState extends State<FadeIn> with TickerProviderStateMixin {
void initState() {
super.initState();

if (widget.controller != null && widget.delay.inMicroseconds > 0) {
throw 'Fadein controller and delay cannot be used together';
}

_controller = AnimationController(
vsync: this,
duration: widget.duration,
);

_setupCurve();

if (widget.controller?.autoStart != false) {
fadeIn();
if (widget.controller!.autoStart != false) {
Future.delayed(widget.delay).then((_) => fadeIn());
}

_listen();
Expand Down Expand Up @@ -102,10 +113,8 @@ class _FadeInState extends State<FadeIn> with TickerProviderStateMixin {
switch (action) {
case FadeInAction.fadeIn:
fadeIn();
break;
case FadeInAction.fadeOut:
fadeOut();
break;
}
}

Expand Down