diff --git a/example/lib/data.dart b/example/lib/data.dart index 58d3681..17666c6 100644 --- a/example/lib/data.dart +++ b/example/lib/data.dart @@ -1,6 +1,6 @@ class Place { - final String name; - final String url; + final String? name; + final String? url; const Place({this.name, this.url}); } diff --git a/example/lib/sample2.dart b/example/lib/sample2.dart index ed99c14..7ae1ad2 100644 --- a/example/lib/sample2.dart +++ b/example/lib/sample2.dart @@ -19,7 +19,7 @@ class Sample2 extends StatelessWidget { (item) => Stack( children: [ Image.network( - item.url, + item.url!, height: height, fit: BoxFit.cover, ), @@ -37,7 +37,7 @@ class Sample2 extends StatelessWidget { ), ]), child: Text( - item.name, + item.name!, style: Theme.of(context).textTheme.title, ), ), diff --git a/example/lib/sample3.dart b/example/lib/sample3.dart index 5b8f46a..05e2f7e 100644 --- a/example/lib/sample3.dart +++ b/example/lib/sample3.dart @@ -20,7 +20,7 @@ class Sample3 extends StatelessWidget { itemBuilder: (context, index, notifier) { final item = places[index]; final transform = Matrix4.identity(); - final t = (index - notifier).abs(); + final t = (index - notifier!).abs(); final scale = lerpDouble(1.5, 0, t); transform.scale(scale, scale); return CubeWidget( @@ -29,7 +29,7 @@ class Sample3 extends StatelessWidget { child: Stack( children: [ Image.network( - item.url, + item.url!, height: height, fit: BoxFit.cover, ), @@ -48,7 +48,7 @@ class Sample3 extends StatelessWidget { ), ]), child: Text( - item.name.split('-').join('\n'), + item.name!.split('-').join('\n'), textAlign: TextAlign.center, style: Theme.of(context).textTheme.title, ), diff --git a/example/pubspec.lock b/example/pubspec.lock index 67304a9..2aa68fb 100644 --- a/example/pubspec.lock +++ b/example/pubspec.lock @@ -1,62 +1,48 @@ # Generated by pub # See https://dart.dev/tools/pub/glossary#lockfile packages: - archive: - dependency: transitive - description: - name: archive - url: "https://pub.dartlang.org" - source: hosted - version: "2.0.11" - args: - dependency: transitive - description: - name: args - url: "https://pub.dartlang.org" - source: hosted - version: "1.5.2" async: dependency: transitive description: name: async url: "https://pub.dartlang.org" source: hosted - version: "2.4.0" + version: "2.6.1" boolean_selector: dependency: transitive description: name: boolean_selector url: "https://pub.dartlang.org" source: hosted - version: "1.0.5" - charcode: + version: "2.1.0" + characters: dependency: transitive description: - name: charcode + name: characters url: "https://pub.dartlang.org" source: hosted - version: "1.1.2" - collection: + version: "1.1.0" + charcode: dependency: transitive description: - name: collection + name: charcode url: "https://pub.dartlang.org" source: hosted - version: "1.14.11" - convert: + version: "1.2.0" + clock: dependency: transitive description: - name: convert + name: clock url: "https://pub.dartlang.org" source: hosted - version: "2.1.1" - crypto: + version: "1.1.0" + collection: dependency: transitive description: - name: crypto + name: collection url: "https://pub.dartlang.org" source: hosted - version: "2.1.3" + version: "1.15.0" cube_transition: dependency: "direct main" description: @@ -64,6 +50,13 @@ packages: relative: true source: path version: "1.0.2" + fake_async: + dependency: transitive + description: + name: fake_async + url: "https://pub.dartlang.org" + source: hosted + version: "1.2.0" flutter: dependency: "direct main" description: flutter @@ -74,55 +67,27 @@ packages: description: flutter source: sdk version: "0.0.0" - image: - dependency: transitive - description: - name: image - url: "https://pub.dartlang.org" - source: hosted - version: "2.1.4" matcher: dependency: transitive description: name: matcher url: "https://pub.dartlang.org" source: hosted - version: "0.12.6" + version: "0.12.10" meta: dependency: transitive description: name: meta url: "https://pub.dartlang.org" source: hosted - version: "1.1.8" + version: "1.3.0" path: dependency: transitive description: name: path url: "https://pub.dartlang.org" source: hosted - version: "1.6.4" - pedantic: - dependency: transitive - description: - name: pedantic - url: "https://pub.dartlang.org" - source: hosted - version: "1.8.0+1" - petitparser: - dependency: transitive - description: - name: petitparser - url: "https://pub.dartlang.org" - source: hosted - version: "2.4.0" - quiver: - dependency: transitive - description: - name: quiver - url: "https://pub.dartlang.org" - source: hosted - version: "2.0.5" + version: "1.8.0" sky_engine: dependency: transitive description: flutter @@ -134,62 +99,55 @@ packages: name: source_span url: "https://pub.dartlang.org" source: hosted - version: "1.5.5" + version: "1.8.1" stack_trace: dependency: transitive description: name: stack_trace url: "https://pub.dartlang.org" source: hosted - version: "1.9.3" + version: "1.10.0" stream_channel: dependency: transitive description: name: stream_channel url: "https://pub.dartlang.org" source: hosted - version: "2.0.0" + version: "2.1.0" string_scanner: dependency: transitive description: name: string_scanner url: "https://pub.dartlang.org" source: hosted - version: "1.0.5" + version: "1.1.0" term_glyph: dependency: transitive description: name: term_glyph url: "https://pub.dartlang.org" source: hosted - version: "1.1.0" + version: "1.2.0" test_api: dependency: transitive description: name: test_api url: "https://pub.dartlang.org" source: hosted - version: "0.2.11" + version: "0.3.0" typed_data: dependency: transitive description: name: typed_data url: "https://pub.dartlang.org" source: hosted - version: "1.1.6" + version: "1.3.0" vector_math: dependency: transitive description: name: vector_math url: "https://pub.dartlang.org" source: hosted - version: "2.0.8" - xml: - dependency: transitive - description: - name: xml - url: "https://pub.dartlang.org" - source: hosted - version: "3.5.0" + version: "2.1.0" sdks: - dart: ">=2.4.0 <3.0.0" + dart: ">=2.12.0 <3.0.0" diff --git a/example/pubspec.yaml b/example/pubspec.yaml index d022690..d371a2e 100644 --- a/example/pubspec.yaml +++ b/example/pubspec.yaml @@ -14,7 +14,7 @@ description: A new Flutter project. version: 1.0.0+1 environment: - sdk: ">=2.3.0 <3.0.0" + sdk: '>=2.12.0 <3.0.0' dependencies: flutter: diff --git a/example/test/widget_test.dart b/example/test/widget_test.dart new file mode 100644 index 0000000..747db1d --- /dev/null +++ b/example/test/widget_test.dart @@ -0,0 +1,30 @@ +// This is a basic Flutter widget test. +// +// To perform an interaction with a widget in your test, use the WidgetTester +// utility that Flutter provides. For example, you can send tap and scroll +// gestures. You can also use WidgetTester to find child widgets in the widget +// tree, read text, and verify that the values of widget properties are correct. + +import 'package:flutter/material.dart'; +import 'package:flutter_test/flutter_test.dart'; + +import 'package:example/main.dart'; + +void main() { + testWidgets('Counter increments smoke test', (WidgetTester tester) async { + // Build our app and trigger a frame. + await tester.pumpWidget(MyApp()); + + // Verify that our counter starts at 0. + expect(find.text('0'), findsOneWidget); + expect(find.text('1'), findsNothing); + + // Tap the '+' icon and trigger a frame. + await tester.tap(find.byIcon(Icons.add)); + await tester.pump(); + + // Verify that our counter has incremented. + expect(find.text('0'), findsNothing); + expect(find.text('1'), findsOneWidget); + }); +} diff --git a/example/web/favicon.png b/example/web/favicon.png new file mode 100644 index 0000000..8aaa46a Binary files /dev/null and b/example/web/favicon.png differ diff --git a/example/web/icons/Icon-192.png b/example/web/icons/Icon-192.png new file mode 100644 index 0000000..b749bfe Binary files /dev/null and b/example/web/icons/Icon-192.png differ diff --git a/example/web/icons/Icon-512.png b/example/web/icons/Icon-512.png new file mode 100644 index 0000000..88cfd48 Binary files /dev/null and b/example/web/icons/Icon-512.png differ diff --git a/example/web/index.html b/example/web/index.html new file mode 100644 index 0000000..0081e18 --- /dev/null +++ b/example/web/index.html @@ -0,0 +1,98 @@ + + + + + + + + + + + + + + + + + example + + + + + + + diff --git a/example/web/manifest.json b/example/web/manifest.json new file mode 100644 index 0000000..8c01291 --- /dev/null +++ b/example/web/manifest.json @@ -0,0 +1,23 @@ +{ + "name": "example", + "short_name": "example", + "start_url": ".", + "display": "standalone", + "background_color": "#0175C2", + "theme_color": "#0175C2", + "description": "A new Flutter project.", + "orientation": "portrait-primary", + "prefer_related_applications": false, + "icons": [ + { + "src": "icons/Icon-192.png", + "sizes": "192x192", + "type": "image/png" + }, + { + "src": "icons/Icon-512.png", + "sizes": "512x512", + "type": "image/png" + } + ] +} diff --git a/lib/src/cube_page_route.dart b/lib/src/cube_page_route.dart index 319eba5..27bdfe4 100644 --- a/lib/src/cube_page_route.dart +++ b/lib/src/cube_page_route.dart @@ -11,10 +11,10 @@ class CubePageRoute extends PageRouteBuilder { final Duration duration; /// The next page we will show - final Widget enterPage; + final Widget? enterPage; /// The current page we will dismiss - final Widget exitPage; + final Widget? exitPage; /// Background color used when the transition is running , it's [Colors.black] as default final Color backgroundColor; @@ -28,7 +28,7 @@ class CubePageRoute extends PageRouteBuilder { ), }) : super( transitionDuration: duration, - pageBuilder: (context, animation, secondaryAnimation) => enterPage, + pageBuilder: (context, animation, secondaryAnimation) => enterPage!, transitionsBuilder: (context, animation, secondaryAnimation, child) { return Container( color: backgroundColor, diff --git a/lib/src/cube_page_view.dart b/lib/src/cube_page_view.dart index fa31ecc..48df8e8 100644 --- a/lib/src/cube_page_view.dart +++ b/lib/src/cube_page_view.dart @@ -7,7 +7,7 @@ import 'package:flutter/material.dart'; /// Used by [CubePageView.builder] and other APIs that use lazily-generated widgets. /// typedef CubeWidgetBuilder = CubeWidget Function( - BuildContext context, int index, double pageNotifier); + BuildContext context, int index, double? pageNotifier); /// This Widget has the [PageView] widget inside. /// It works in two modes : @@ -16,28 +16,28 @@ typedef CubeWidgetBuilder = CubeWidget Function( class CubePageView extends StatefulWidget { /// Called whenever the page in the center of the viewport changes. - final ValueChanged onPageChanged; + final ValueChanged? onPageChanged; /// An object that can be used to control the position to which this page /// view is scrolled. - final PageController controller; + final PageController? controller; /// Builder to customize your items - final CubeWidgetBuilder itemBuilder; + final CubeWidgetBuilder? itemBuilder; /// The number of items you have, this is only required if you use [CubePageView.builder] - final int itemCount; + final int? itemCount; /// Widgets you want to use inside the [CubePageView], this is only required if you use [CubePageView] constructor - final List children; + final List? children; /// Creates a scrollable list that works page by page from an explicit [List] /// of widgets. const CubePageView({ - Key key, + Key? key, this.onPageChanged, this.controller, - @required this.children, + required List this.children, }) : itemBuilder = null, itemCount = null, assert(children != null), @@ -55,9 +55,9 @@ class CubePageView extends StatefulWidget { /// zero and less than [itemCount]. CubePageView.builder({ - Key key, - @required this.itemCount, - @required this.itemBuilder, + Key? key, + required int this.itemCount, + required this.itemBuilder, this.onPageChanged, this.controller, }) : this.children = null, @@ -71,25 +71,25 @@ class CubePageView extends StatefulWidget { class _CubePageViewState extends State { final _pageNotifier = ValueNotifier(0.0); - PageController _pageController; + PageController? _pageController; void _listener() { - _pageNotifier.value = _pageController.page; + _pageNotifier.value = _pageController!.page ?? 0; } @override void initState() { _pageController = widget.controller ?? PageController(); - WidgetsBinding.instance.addPostFrameCallback((_) { - _pageController.addListener(_listener); + WidgetsBinding.instance!.addPostFrameCallback((_) { + _pageController!.addListener(_listener); }); super.initState(); } @override void dispose() { - _pageController.removeListener(_listener); - _pageController.dispose(); + _pageController!.removeListener(_listener); + _pageController!.dispose(); _pageNotifier.dispose(); super.dispose(); } @@ -99,18 +99,18 @@ class _CubePageViewState extends State { return Material( color: Colors.transparent, child: Center( - child: ValueListenableBuilder( + child: ValueListenableBuilder( valueListenable: _pageNotifier, builder: (_, value, child) => PageView.builder( controller: _pageController, onPageChanged: widget.onPageChanged, physics: const ClampingScrollPhysics(), - itemCount: widget.itemCount ?? widget.children.length, + itemCount: widget.itemCount ?? widget.children!.length, itemBuilder: (_, index) { if (widget.itemBuilder != null) - return widget.itemBuilder(context, index, value); + return widget.itemBuilder!(context, index, value); return CubeWidget( - child: widget.children[index], + child: widget.children![index], index: index, pageNotifier: value, ); @@ -130,27 +130,27 @@ class CubeWidget extends StatelessWidget { final int index; /// Page Notifier value, it comes from the [CubeWidgetBuilder] - final double pageNotifier; + final double? pageNotifier; /// Child you want to use inside the Cube final Widget child; const CubeWidget({ - Key key, - @required this.index, - @required this.pageNotifier, - @required this.child, + Key? key, + required this.index, + required this.pageNotifier, + required this.child, }) : super(key: key); @override Widget build(BuildContext context) { - final isLeaving = (index - pageNotifier) <= 0; - final t = (index - pageNotifier); - final rotationY = lerpDouble(0, 90, t); - final opacity = lerpDouble(0, 1, t.abs()).clamp(0.0, 1.0); + final isLeaving = (index - pageNotifier!) <= 0; + final t = (index - pageNotifier!); + final rotationY = lerpDouble(0, 90, t)!; + final num opacity = lerpDouble(0, 1, t.abs())!.clamp(0.0, 1.0); final transform = Matrix4.identity(); transform.setEntry(3, 2, 0.003); - transform.rotateY(-degToRad(rotationY)); + transform.rotateY(-degToRad(rotationY) as double); return Transform( alignment: isLeaving ? Alignment.centerRight : Alignment.centerLeft, transform: transform, @@ -159,7 +159,7 @@ class CubeWidget extends StatelessWidget { child, Positioned.fill( child: Opacity( - opacity: opacity, + opacity: opacity as double, child: Container( child: Container( color: Colors.black87, diff --git a/pubspec.lock b/pubspec.lock index f85e4f2..a22483c 100644 --- a/pubspec.lock +++ b/pubspec.lock @@ -1,13 +1,20 @@ # Generated by pub # See https://dart.dev/tools/pub/glossary#lockfile packages: + characters: + dependency: transitive + description: + name: characters + url: "https://pub.dartlang.org" + source: hosted + version: "1.1.0" collection: dependency: transitive description: name: collection url: "https://pub.dartlang.org" source: hosted - version: "1.14.11" + version: "1.15.0" flutter: dependency: "direct main" description: flutter @@ -19,7 +26,7 @@ packages: name: meta url: "https://pub.dartlang.org" source: hosted - version: "1.1.8" + version: "1.3.0" sky_engine: dependency: transitive description: flutter @@ -31,13 +38,13 @@ packages: name: typed_data url: "https://pub.dartlang.org" source: hosted - version: "1.1.6" + 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.3.0 <3.0.0" + dart: ">=2.12.0 <3.0.0" diff --git a/pubspec.yaml b/pubspec.yaml index a74616a..72dd311 100644 --- a/pubspec.yaml +++ b/pubspec.yaml @@ -6,7 +6,7 @@ homepage: https://aeyrium.com/products/mxtracker/ repository: https://github.com/aeyrium/cube_transition environment: - sdk: ">=2.3.0 <3.0.0" + sdk: '>=2.12.0 <3.0.0' dependencies: flutter: