Skip to content

Commit

Permalink
Update analysis options and fix lints.
Browse files Browse the repository at this point in the history
  • Loading branch information
slightfoot committed May 15, 2022
1 parent 90bba83 commit ad64d79
Show file tree
Hide file tree
Showing 8 changed files with 47 additions and 35 deletions.
3 changes: 3 additions & 0 deletions .pubignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
*.iml
example/android/**
example/ios/**
5 changes: 1 addition & 4 deletions analysis_options.yaml
Original file line number Diff line number Diff line change
@@ -1,4 +1 @@
# https://www.dartlang.org/guides/language/analysis-options
analyzer:
errors:
mixin_inherits_from_not_object: ignore
include: package:flutter_lints/flutter.yaml
5 changes: 1 addition & 4 deletions example/analysis_options.yaml
Original file line number Diff line number Diff line change
@@ -1,4 +1 @@
# https://www.dartlang.org/guides/language/analysis-options
analyzer:
errors:
mixin_inherits_from_not_object: ignore
include: package:flutter_lints/flutter.yaml
39 changes: 26 additions & 13 deletions example/lib/main.dart
Original file line number Diff line number Diff line change
Expand Up @@ -3,22 +3,28 @@ import 'package:sticky_headers/sticky_headers.dart';

import './images.dart';

void main() => runApp(ExampleApp());
void main() => runApp(const ExampleApp());

@immutable
class ExampleApp extends StatelessWidget {
const ExampleApp({Key? key}) : super(key: key);

@override
Widget build(BuildContext context) {
return MaterialApp(
title: 'Sticky Headers Example',
theme: ThemeData(
primarySwatch: Colors.blueGrey,
),
home: MainScreen(),
home: const MainScreen(),
);
}
}

@immutable
class MainScreen extends StatelessWidget {
const MainScreen({Key? key}) : super(key: key);

@override
Widget build(BuildContext context) {
return ScaffoldWrapper(
Expand All @@ -29,19 +35,19 @@ class MainScreen extends StatelessWidget {
tiles: <Widget>[
ListTile(
title: const Text('Example 1 - Headers and Content'),
onTap: () => navigateTo(context, (context) => Example1()),
onTap: () => navigateTo(context, (context) => const Example1()),
),
ListTile(
title: const Text('Example 2 - Animated Headers with Content'),
onTap: () => navigateTo(context, (context) => Example2()),
onTap: () => navigateTo(context, (context) => const Example2()),
),
ListTile(
title: const Text('Example 3 - Headers overlapping the Content'),
onTap: () => navigateTo(context, (context) => Example3()),
onTap: () => navigateTo(context, (context) => const Example3()),
),
ListTile(
title: const Text('Example 4 - Example using scroll controller'),
onTap: () => navigateTo(context, (context) => Example4()),
onTap: () => navigateTo(context, (context) => const Example4()),
),
],
).toList(growable: false),
Expand All @@ -54,6 +60,7 @@ class MainScreen extends StatelessWidget {
}
}

@immutable
class Example1 extends StatelessWidget {
const Example1({
Key? key,
Expand All @@ -76,7 +83,7 @@ class Example1 extends StatelessWidget {
header: Container(
height: 50.0,
color: Colors.blueGrey[700],
padding: EdgeInsets.symmetric(horizontal: 16.0),
padding: const EdgeInsets.symmetric(horizontal: 16.0),
alignment: Alignment.centerLeft,
child: Text(
'Header #$index',
Expand All @@ -103,6 +110,7 @@ class Example1 extends StatelessWidget {
}
}

@immutable
class Example2 extends StatelessWidget {
const Example2({
Key? key,
Expand All @@ -127,7 +135,7 @@ class Example2 extends StatelessWidget {
return Container(
height: 50.0,
color: Color.lerp(Colors.blue[700], Colors.red[700], stuckAmount),
padding: EdgeInsets.symmetric(horizontal: 16.0),
padding: const EdgeInsets.symmetric(horizontal: 16.0),
alignment: Alignment.centerLeft,
child: Row(
children: <Widget>[
Expand All @@ -142,7 +150,7 @@ class Example2 extends StatelessWidget {
child: Opacity(
opacity: stuckAmount,
child: IconButton(
icon: Icon(Icons.favorite, color: Colors.white),
icon: const Icon(Icons.favorite, color: Colors.white),
onPressed: () => ScaffoldMessenger.of(context)
.showSnackBar(SnackBar(content: Text('Favorite #$index'))),
),
Expand Down Expand Up @@ -172,6 +180,7 @@ class Example2 extends StatelessWidget {
}
}

@immutable
class Example3 extends StatelessWidget {
const Example3({
Key? key,
Expand All @@ -197,7 +206,7 @@ class Example3 extends StatelessWidget {
return Container(
height: 50.0,
color: Colors.grey.shade900.withOpacity(0.6 + stuckAmount * 0.4),
padding: EdgeInsets.symmetric(horizontal: 16.0),
padding: const EdgeInsets.symmetric(horizontal: 16.0),
alignment: Alignment.centerLeft,
child: Text(
'Header #$index',
Expand Down Expand Up @@ -225,6 +234,7 @@ class Example3 extends StatelessWidget {
}
}

@immutable
class ScaffoldWrapper extends StatelessWidget {
const ScaffoldWrapper({
Key? key,
Expand All @@ -242,7 +252,7 @@ class ScaffoldWrapper extends StatelessWidget {
if (wrap) {
return Scaffold(
appBar: PreferredSize(
preferredSize: Size.fromHeight(kToolbarHeight),
preferredSize: const Size.fromHeight(kToolbarHeight),
child: Hero(
tag: 'app_bar',
child: AppBar(
Expand All @@ -261,9 +271,12 @@ class ScaffoldWrapper extends StatelessWidget {
}
}

@immutable
class Example4 extends StatefulWidget {
const Example4({Key? key}) : super(key: key);

@override
_Example4State createState() => _Example4State();
State<Example4> createState() => _Example4State();
}

class _Example4State extends State<Example4> {
Expand All @@ -282,7 +295,7 @@ class _Example4State extends State<Example4> {
title: const Text('Example 4'),
pinned: true,
forceElevated: innerBoxIsScrolled,
bottom: TabBar(
bottom: const TabBar(
tabs: <Tab>[
Tab(text: 'Example 1'),
Tab(text: 'Example 2'),
Expand Down
3 changes: 2 additions & 1 deletion example/pubspec.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -2,12 +2,13 @@ name: example
description: Example of Sticky Headers

environment:
sdk: ">=2.17.0"
sdk: ">=2.17.0 <3.0.0"
flutter: ">=3.0.0"

dependencies:
flutter:
sdk: flutter
flutter_lints: ^2.0.1
sticky_headers:
path: ../

Expand Down
4 changes: 2 additions & 2 deletions lib/sticky_headers/render.dart
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ import 'package:flutter/widgets.dart';
/// Called every layout to provide the amount of stickyness a header is in.
/// This lets the widgets animate their content and provide feedback.
///
typedef void RenderStickyHeaderCallback(double stuckAmount);
typedef RenderStickyHeaderCallback = void Function(double stuckAmount);

/// RenderObject for StickyHeader widget.
///
Expand All @@ -31,7 +31,7 @@ class RenderStickyHeader extends RenderBox
RenderStickyHeader({
required ScrollPosition scrollPosition,
RenderStickyHeaderCallback? callback,
bool overlapHeaders: false,
bool overlapHeaders = false,
RenderBox? header,
RenderBox? content,
}) : _scrollPosition = scrollPosition,
Expand Down
20 changes: 10 additions & 10 deletions lib/sticky_headers/widget.dart
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ import './render.dart';
/// -1.0 >= value >= 0.0: past stuck
/// ```
///
typedef Widget StickyHeaderWidgetBuilder(BuildContext context, double stuckAmount);
typedef StickyHeaderWidgetBuilder = Widget Function(BuildContext context, double stuckAmount);

/// Stick Header Widget
///
Expand All @@ -33,7 +33,7 @@ class StickyHeader extends MultiChildRenderObjectWidget {
Key? key,
required this.header,
required this.content,
this.overlapHeaders: false,
this.overlapHeaders = false,
this.controller,
this.callback,
}) : super(
Expand All @@ -60,21 +60,21 @@ class StickyHeader extends MultiChildRenderObjectWidget {

@override
RenderStickyHeader createRenderObject(BuildContext context) {
final scrollPosition = this.controller?.position ?? Scrollable.of(context)!.position;
final scrollPosition = controller?.position ?? Scrollable.of(context)!.position;
return RenderStickyHeader(
scrollPosition: scrollPosition,
callback: this.callback,
overlapHeaders: this.overlapHeaders,
callback: callback,
overlapHeaders: overlapHeaders,
);
}

@override
void updateRenderObject(BuildContext context, RenderStickyHeader renderObject) {
final scrollPosition = this.controller?.position ?? Scrollable.of(context)!.position;
final scrollPosition = controller?.position ?? Scrollable.of(context)!.position;
renderObject
..scrollPosition = scrollPosition
..callback = this.callback
..overlapHeaders = this.overlapHeaders;
..callback = callback
..overlapHeaders = overlapHeaders;
}
}

Expand All @@ -91,7 +91,7 @@ class StickyHeaderBuilder extends StatefulWidget {
Key? key,
required this.builder,
required this.content,
this.overlapHeaders: false,
this.overlapHeaders = false,
this.controller,
}) : super(key: key);

Expand All @@ -109,7 +109,7 @@ class StickyHeaderBuilder extends StatefulWidget {
final ScrollController? controller;

@override
_StickyHeaderBuilderState createState() => _StickyHeaderBuilderState();
State<StickyHeaderBuilder> createState() => _StickyHeaderBuilderState();
}

class _StickyHeaderBuilderState extends State<StickyHeaderBuilder> {
Expand Down
3 changes: 2 additions & 1 deletion pubspec.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -5,12 +5,13 @@ homepage: https://github.com/fluttercommunity/flutter_sticky_headers
maintainer: Simon Lightfoot (@slightfoot)

environment:
sdk: ">=2.17.0"
sdk: ">=2.17.0 <3.0.0"
flutter: ">=3.0.0"

dependencies:
flutter:
sdk: flutter
flutter_lints: ^2.0.1

dev_dependencies:
flutter_test:
Expand Down

0 comments on commit ad64d79

Please sign in to comment.