diff --git a/web/slide_puzzle/lib/src/core/puzzle_proxy.dart b/web/slide_puzzle/lib/src/core/puzzle_proxy.dart new file mode 100644 index 000000000..88a3b92dc --- /dev/null +++ b/web/slide_puzzle/lib/src/core/puzzle_proxy.dart @@ -0,0 +1,21 @@ +import 'dart:math' show Point; + +enum PuzzleEvent { click, random, reset, noop } + +abstract class PuzzleProxy { + int get width; + + int get height; + + int get length; + + bool get solved; + + void clickOrShake(int tileValue); + + int get tileCount; + + Point location(int index); + + bool isCorrectPosition(int value); +} diff --git a/web/slide_puzzle/lib/src/flutter.dart b/web/slide_puzzle/lib/src/flutter.dart new file mode 100644 index 000000000..0b4e17c4d --- /dev/null +++ b/web/slide_puzzle/lib/src/flutter.dart @@ -0,0 +1,2 @@ +export 'package:flutter/material.dart'; +export 'package:flutter/scheduler.dart' show Ticker; diff --git a/web/slide_puzzle/lib/src/puzzle_controls.dart b/web/slide_puzzle/lib/src/puzzle_controls.dart new file mode 100644 index 000000000..36420ac3c --- /dev/null +++ b/web/slide_puzzle/lib/src/puzzle_controls.dart @@ -0,0 +1,13 @@ +import 'package:flutter/foundation.dart'; + +abstract class PuzzleControls implements Listenable { + void reset(); + + int get clickCount; + + int get incorrectTiles; + + bool get autoPlay; + + void Function(bool newValue) get setAutoPlayFunction; +} diff --git a/web/slide_puzzle/lib/src/themes.dart b/web/slide_puzzle/lib/src/themes.dart new file mode 100644 index 000000000..7889db6c3 --- /dev/null +++ b/web/slide_puzzle/lib/src/themes.dart @@ -0,0 +1,9 @@ +import 'theme_plaster.dart'; +import 'theme_seattle.dart'; +import 'theme_simple.dart'; + +const themes = [ + ThemeSimple(), + ThemeSeattle(), + ThemePlaster(), +]; diff --git a/web/slide_puzzle/lib/src/value_tab_controller.dart b/web/slide_puzzle/lib/src/value_tab_controller.dart new file mode 100644 index 000000000..17ad1ee3c --- /dev/null +++ b/web/slide_puzzle/lib/src/value_tab_controller.dart @@ -0,0 +1,88 @@ +import 'package:flutter/material.dart'; +import 'package:provider/provider.dart'; + +class ValueTabController extends StatefulWidget { + /// Creates a default tab controller for the given [child] widget. + const ValueTabController({ + Key key, + @required this.child, + @required this.values, + }) : super(key: key); + + /// The widget below this widget in the tree. + /// + /// Typically a [Scaffold] whose [AppBar] includes a [TabBar]. + /// + /// {@macro flutter.widgets.child} + final Widget child; + + final List values; + + /// The closest instance of this class that encloses the given context. + /// + /// Typical usage: + /// + /// ```dart + /// TabController controller = DefaultTabBarController.of(context); + /// ``` + static TabController of(BuildContext context) { + final scope = context.inheritFromWidgetOfExactType(_ValueTabControllerScope) + as _ValueTabControllerScope; + return scope?.controller; + } + + @override + _ValueTabControllerState createState() => _ValueTabControllerState(); +} + +class _ValueTabControllerState extends State> + with SingleTickerProviderStateMixin { + final _notifier = ValueNotifier(null); + + TabController _controller; + + @override + void initState() { + super.initState(); + _controller = TabController( + vsync: this, + length: widget.values.length, + initialIndex: 0, + ); + + _notifier.value = widget.values.first; + + _controller.addListener(() { + _notifier.value = widget.values[_controller.index]; + }); + } + + @override + void dispose() { + _controller.dispose(); + super.dispose(); + } + + @override + Widget build(BuildContext context) => _ValueTabControllerScope( + controller: _controller, + enabled: TickerMode.of(context), + child: ValueListenableProvider.value( + valueListenable: _notifier, + child: widget.child, + ), + ); +} + +class _ValueTabControllerScope extends InheritedWidget { + const _ValueTabControllerScope( + {Key key, this.controller, this.enabled, Widget child}) + : super(key: key, child: child); + + final TabController controller; + final bool enabled; + + @override + bool updateShouldNotify(_ValueTabControllerScope old) => + enabled != old.enabled || controller != old.controller; +} diff --git a/web/slide_puzzle/pubspec.lock b/web/slide_puzzle/pubspec.lock index f7f6cf21d..ab2c0eb0f 100644 --- a/web/slide_puzzle/pubspec.lock +++ b/web/slide_puzzle/pubspec.lock @@ -1,13 +1,20 @@ # Generated by pub # See https://dart.dev/tools/pub/glossary#lockfile packages: + _fe_analyzer_shared: + dependency: transitive + description: + name: _fe_analyzer_shared + url: "https://pub.dartlang.org" + source: hosted + version: "2.2.0" analyzer: dependency: transitive description: name: analyzer url: "https://pub.dartlang.org" source: hosted - version: "0.36.4" + version: "0.39.7" archive: dependency: transitive description: @@ -88,13 +95,6 @@ packages: description: flutter source: sdk version: "0.0.0" - front_end: - dependency: transitive - description: - name: front_end - url: "https://pub.dartlang.org" - source: hosted - version: "0.1.19" glob: dependency: transitive description: @@ -115,21 +115,21 @@ packages: name: http url: "https://pub.dartlang.org" source: hosted - version: "0.12.0+2" + version: "0.12.0+4" http_multi_server: dependency: transitive description: name: http_multi_server url: "https://pub.dartlang.org" source: hosted - version: "2.1.0" + version: "2.2.0" http_parser: dependency: transitive description: name: http_parser url: "https://pub.dartlang.org" source: hosted - version: "3.1.3" + version: "3.1.4" image: dependency: transitive description: @@ -143,7 +143,7 @@ packages: name: io url: "https://pub.dartlang.org" source: hosted - version: "0.3.3" + version: "0.3.4" js: dependency: transitive description: @@ -151,13 +151,6 @@ packages: url: "https://pub.dartlang.org" source: hosted version: "0.6.1+1" - kernel: - dependency: transitive - description: - name: kernel - url: "https://pub.dartlang.org" - source: hosted - version: "0.3.19" logging: dependency: transitive description: @@ -221,13 +214,6 @@ packages: url: "https://pub.dartlang.org" source: hosted version: "1.9.3" - package_resolver: - dependency: transitive - description: - name: package_resolver - url: "https://pub.dartlang.org" - source: hosted - version: "1.0.10" path: dependency: transitive description: @@ -241,7 +227,7 @@ packages: name: pedantic url: "https://pub.dartlang.org" source: hosted - version: "1.8.0+1" + version: "1.9.0" petitparser: dependency: transitive description: @@ -269,7 +255,7 @@ packages: name: pub_semver url: "https://pub.dartlang.org" source: hosted - version: "1.4.2" + version: "1.4.4" quiver: dependency: transitive description: @@ -290,7 +276,7 @@ packages: name: shelf_packages_handler url: "https://pub.dartlang.org" source: hosted - version: "1.0.4" + version: "2.0.0" shelf_static: dependency: transitive description: @@ -323,7 +309,7 @@ packages: name: source_maps url: "https://pub.dartlang.org" source: hosted - version: "0.10.8" + version: "0.10.9" source_span: dependency: transitive description: @@ -407,7 +393,7 @@ packages: name: watcher url: "https://pub.dartlang.org" source: hosted - version: "0.9.7+12" + version: "0.9.7+15" web_socket_channel: dependency: transitive description: