mirror of
https://github.com/flutter/samples.git
synced 2025-11-10 23:08:59 +00:00
Update web/ samples to work with Flutter SDK (#134)
* add package:http dependency in dad_jokes * add package:http dependency in filipino_cuisine * don't build package:http demos until flutter/flutter#34858 is resolved * update gallery * update github_dataviz * update particle_background * don't build github_dataviz (uses package:http) * update slide_puzzle * update spinning_square * update timeflow * update vision_challenge * update charts * update dad_jokes * update filipino cuisine * ignore build output * update timeflow and vision_challenge * update slide_puzzle * don't commit build/ directory * move preview.png images to assets * fix path url join * update readme * update web/readme.md
This commit is contained in:
@@ -1,13 +1,29 @@
|
||||
// Copyright 2019 The Chromium Authors. All rights reserved.
|
||||
// Use of this source code is governed by a BSD-style license that can be
|
||||
// found in the LICENSE file.
|
||||
|
||||
import 'package:flutter_web/foundation.dart';
|
||||
|
||||
import 'core/puzzle_proxy.dart';
|
||||
import 'core/puzzle_animator.dart';
|
||||
import 'package:flutter/material.dart';
|
||||
import 'shared_theme.dart';
|
||||
|
||||
abstract class AppState {
|
||||
TabController get tabController;
|
||||
|
||||
Animation<Offset> get shuffleOffsetAnimation;
|
||||
|
||||
PuzzleProxy get puzzle;
|
||||
|
||||
Listenable get animationNotifier;
|
||||
bool get autoPlay;
|
||||
|
||||
void setAutoPlay(bool newValue);
|
||||
|
||||
AnimationNotifier get animationNotifier;
|
||||
|
||||
Iterable<SharedTheme> get themeData;
|
||||
|
||||
SharedTheme get currentTheme;
|
||||
|
||||
set currentTheme(SharedTheme theme);
|
||||
}
|
||||
|
||||
abstract class AnimationNotifier implements Listenable {
|
||||
void animate();
|
||||
|
||||
void dispose();
|
||||
}
|
||||
|
||||
@@ -1,7 +1,3 @@
|
||||
// Copyright 2019 The Chromium Authors. All rights reserved.
|
||||
// Use of this source code is governed by a BSD-style license that can be
|
||||
// found in the LICENSE file.
|
||||
|
||||
import 'dart:math' show Point;
|
||||
|
||||
const zeroPoint = Point<double>(0, 0);
|
||||
|
||||
@@ -1,7 +1,3 @@
|
||||
// Copyright 2019 The Chromium Authors. All rights reserved.
|
||||
// Use of this source code is governed by a BSD-style license that can be
|
||||
// found in the LICENSE file.
|
||||
|
||||
import 'dart:math' as math;
|
||||
|
||||
class Point extends math.Point<int> {
|
||||
|
||||
@@ -1,7 +1,3 @@
|
||||
// Copyright 2019 The Chromium Authors. All rights reserved.
|
||||
// Use of this source code is governed by a BSD-style license that can be
|
||||
// found in the LICENSE file.
|
||||
|
||||
import 'dart:collection';
|
||||
import 'dart:convert';
|
||||
import 'dart:math' show Random, max;
|
||||
@@ -127,7 +123,8 @@ abstract class Puzzle {
|
||||
value += delta * delta;
|
||||
}
|
||||
}
|
||||
return value * incorrectTiles;
|
||||
value *= incorrectTiles;
|
||||
return value;
|
||||
}
|
||||
|
||||
Puzzle clickRandom({bool vertical}) {
|
||||
@@ -140,8 +137,8 @@ abstract class Puzzle {
|
||||
|
||||
List<int> clickableValues({bool vertical}) {
|
||||
final open = openPosition();
|
||||
final doRow = vertical == null || vertical == false;
|
||||
final doColumn = vertical == null || vertical;
|
||||
final doRow = (vertical == null || vertical == false);
|
||||
final doColumn = (vertical == null || vertical);
|
||||
|
||||
final values =
|
||||
Uint8List((doRow ? (width - 1) : 0) + (doColumn ? (height - 1) : 0));
|
||||
|
||||
@@ -1,13 +1,34 @@
|
||||
// Copyright 2019 The Chromium Authors. All rights reserved.
|
||||
// Use of this source code is governed by a BSD-style license that can be
|
||||
// found in the LICENSE file.
|
||||
|
||||
import 'dart:async';
|
||||
import 'dart:math' show Point, Random;
|
||||
|
||||
import 'body.dart';
|
||||
import 'puzzle.dart';
|
||||
import 'puzzle_proxy.dart';
|
||||
|
||||
enum PuzzleEvent { click, reset, noop }
|
||||
|
||||
abstract class PuzzleProxy {
|
||||
int get width;
|
||||
|
||||
int get height;
|
||||
|
||||
int get length;
|
||||
|
||||
bool get solved;
|
||||
|
||||
void reset();
|
||||
|
||||
void clickOrShake(int tileValue);
|
||||
|
||||
int get tileCount;
|
||||
|
||||
int get clickCount;
|
||||
|
||||
int get incorrectTiles;
|
||||
|
||||
Point<double> location(int index);
|
||||
|
||||
bool isCorrectPosition(int value);
|
||||
}
|
||||
|
||||
class PuzzleAnimator implements PuzzleProxy {
|
||||
final _rnd = Random();
|
||||
@@ -36,10 +57,13 @@ class PuzzleAnimator implements PuzzleProxy {
|
||||
@override
|
||||
int get tileCount => _puzzle.tileCount;
|
||||
|
||||
@override
|
||||
int get incorrectTiles => _puzzle.incorrectTiles;
|
||||
|
||||
@override
|
||||
int get clickCount => _clickCount;
|
||||
|
||||
@override
|
||||
void reset() => _resetCore();
|
||||
|
||||
Stream<PuzzleEvent> get onEvent => _controller.stream;
|
||||
@@ -69,7 +93,7 @@ class PuzzleAnimator implements PuzzleProxy {
|
||||
_puzzle = _puzzle.clickRandom(vertical: _nextRandomVertical);
|
||||
_nextRandomVertical = !_nextRandomVertical;
|
||||
_clickCount++;
|
||||
_controller.add(PuzzleEvent.random);
|
||||
_controller.add(PuzzleEvent.click);
|
||||
}
|
||||
|
||||
@override
|
||||
@@ -141,7 +165,7 @@ class PuzzleAnimator implements PuzzleProxy {
|
||||
final delta = _puzzle.openPosition() - _puzzle.coordinatesOf(tileValue);
|
||||
deltaDouble = Point(delta.x.toDouble(), delta.y.toDouble());
|
||||
}
|
||||
deltaDouble *= 0.5 / deltaDouble.magnitude;
|
||||
deltaDouble *= (0.5 / deltaDouble.magnitude);
|
||||
|
||||
_locations[tileValue].kick(deltaDouble);
|
||||
}
|
||||
|
||||
@@ -1,25 +0,0 @@
|
||||
// Copyright 2019 The Chromium Authors. All rights reserved.
|
||||
// Use of this source code is governed by a BSD-style license that can be
|
||||
// found in the LICENSE file.
|
||||
|
||||
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<double> location(int index);
|
||||
|
||||
bool isCorrectPosition(int value);
|
||||
}
|
||||
@@ -1,7 +1,3 @@
|
||||
// Copyright 2019 The Chromium Authors. All rights reserved.
|
||||
// Use of this source code is governed by a BSD-style license that can be
|
||||
// found in the LICENSE file.
|
||||
|
||||
part of 'puzzle.dart';
|
||||
|
||||
class _PuzzleSimple extends Puzzle {
|
||||
|
||||
@@ -1,7 +1,3 @@
|
||||
// Copyright 2019 The Chromium Authors. All rights reserved.
|
||||
// Use of this source code is governed by a BSD-style license that can be
|
||||
// found in the LICENSE file.
|
||||
|
||||
part of 'puzzle.dart';
|
||||
|
||||
mixin _SliceListMixin on ListMixin<int> {
|
||||
|
||||
@@ -1,7 +1,3 @@
|
||||
// Copyright 2019 The Chromium Authors. All rights reserved.
|
||||
// Use of this source code is governed by a BSD-style license that can be
|
||||
// found in the LICENSE file.
|
||||
|
||||
void requireArgument(bool truth, String argName, [String message]) {
|
||||
if (!truth) {
|
||||
if (message == null || message.isEmpty) {
|
||||
|
||||
@@ -1,7 +0,0 @@
|
||||
// Copyright 2019 The Chromium Authors. All rights reserved.
|
||||
// Use of this source code is governed by a BSD-style license that can be
|
||||
// found in the LICENSE file.
|
||||
|
||||
export 'package:flutter_web/material.dart';
|
||||
|
||||
export 'package:flutter_web/scheduler.dart' show Ticker;
|
||||
63
web/slide_puzzle/lib/src/frame_nanny.dart
Normal file
63
web/slide_puzzle/lib/src/frame_nanny.dart
Normal file
@@ -0,0 +1,63 @@
|
||||
import 'dart:collection';
|
||||
|
||||
class FrameNanny {
|
||||
static const _bufferSize = 200;
|
||||
static const _maxFrameDuration = Duration(milliseconds: 34);
|
||||
final _buffer = ListQueue<Duration>(_bufferSize);
|
||||
final _watch = Stopwatch();
|
||||
|
||||
Duration tick(Duration source) {
|
||||
_watch.start();
|
||||
_buffer.add(source);
|
||||
|
||||
while (_buffer.length > _bufferSize) {
|
||||
_buffer.removeFirst();
|
||||
}
|
||||
|
||||
if (source > _maxFrameDuration) {
|
||||
source = _maxFrameDuration;
|
||||
}
|
||||
|
||||
if (_watch.elapsed > const Duration(seconds: 2)) {
|
||||
var goodCount = 0;
|
||||
var sum = const Duration();
|
||||
Duration best, worst;
|
||||
|
||||
for (var e in _buffer) {
|
||||
sum += e;
|
||||
if (e <= _maxFrameDuration) {
|
||||
goodCount++;
|
||||
}
|
||||
|
||||
if (best == null || e < best) {
|
||||
best = e;
|
||||
}
|
||||
|
||||
if (worst == null || e > worst) {
|
||||
worst = e;
|
||||
}
|
||||
}
|
||||
|
||||
_watch.reset();
|
||||
print([
|
||||
'**Nanny**',
|
||||
'${(100 * goodCount / _buffer.length).toStringAsFixed(1)}%',
|
||||
'<= ${_maxFrameDuration.inMilliseconds}ms',
|
||||
'best:',
|
||||
best?.inMilliseconds,
|
||||
'avg:',
|
||||
_safeDivide(sum, _buffer.length),
|
||||
'worst',
|
||||
worst?.inMilliseconds
|
||||
].join(' '));
|
||||
}
|
||||
return source;
|
||||
}
|
||||
}
|
||||
|
||||
Object _safeDivide(Duration source, int divisor) {
|
||||
if (divisor == 0) {
|
||||
return double.nan;
|
||||
}
|
||||
return (source ~/ divisor).inMilliseconds;
|
||||
}
|
||||
@@ -1,17 +0,0 @@
|
||||
// Copyright 2019 The Chromium Authors. All rights reserved.
|
||||
// Use of this source code is governed by a BSD-style license that can be
|
||||
// found in the LICENSE file.
|
||||
|
||||
import 'package:flutter_web/foundation.dart';
|
||||
|
||||
abstract class PuzzleControls implements Listenable {
|
||||
void reset();
|
||||
|
||||
int get clickCount;
|
||||
|
||||
int get incorrectTiles;
|
||||
|
||||
bool get autoPlay;
|
||||
|
||||
void Function(bool newValue) get setAutoPlayFunction;
|
||||
}
|
||||
@@ -1,9 +1,5 @@
|
||||
// Copyright 2019 The Chromium Authors. All rights reserved.
|
||||
// Use of this source code is governed by a BSD-style license that can be
|
||||
// found in the LICENSE file.
|
||||
|
||||
import 'core/puzzle_proxy.dart';
|
||||
import 'flutter.dart';
|
||||
import 'core/puzzle_animator.dart';
|
||||
import 'package:flutter/material.dart';
|
||||
|
||||
class PuzzleFlowDelegate extends FlowDelegate {
|
||||
final Size _tileSize;
|
||||
|
||||
@@ -1,84 +1,101 @@
|
||||
// Copyright 2019 The Chromium Authors. All rights reserved.
|
||||
// Use of this source code is governed by a BSD-style license that can be
|
||||
// found in the LICENSE file.
|
||||
|
||||
import 'dart:async';
|
||||
import 'dart:math' as math;
|
||||
|
||||
import 'package:provider/provider.dart';
|
||||
import 'package:flutter/material.dart';
|
||||
import 'package:flutter/scheduler.dart';
|
||||
|
||||
import 'app_state.dart';
|
||||
import 'core/puzzle_animator.dart';
|
||||
import 'core/puzzle_proxy.dart';
|
||||
import 'flutter.dart';
|
||||
import 'puzzle_controls.dart';
|
||||
import 'puzzle_flow_delegate.dart';
|
||||
import 'frame_nanny.dart';
|
||||
import 'shared_theme.dart';
|
||||
import 'themes.dart';
|
||||
import 'value_tab_controller.dart';
|
||||
|
||||
class _PuzzleControls extends ChangeNotifier implements PuzzleControls {
|
||||
final PuzzleHomeState _parent;
|
||||
|
||||
_PuzzleControls(this._parent);
|
||||
|
||||
@override
|
||||
bool get autoPlay => _parent._autoPlay;
|
||||
|
||||
void _notify() => notifyListeners();
|
||||
|
||||
@override
|
||||
void Function(bool newValue) get setAutoPlayFunction {
|
||||
if (_parent.puzzle.solved) {
|
||||
return null;
|
||||
}
|
||||
return _parent._setAutoPlay;
|
||||
}
|
||||
|
||||
@override
|
||||
int get clickCount => _parent.puzzle.clickCount;
|
||||
|
||||
@override
|
||||
int get incorrectTiles => _parent.puzzle.incorrectTiles;
|
||||
|
||||
@override
|
||||
void reset() => _parent.puzzle.reset();
|
||||
}
|
||||
import 'theme_plaster.dart';
|
||||
import 'theme_seattle.dart';
|
||||
import 'theme_simple.dart';
|
||||
|
||||
class PuzzleHomeState extends State
|
||||
with SingleTickerProviderStateMixin, AppState {
|
||||
with TickerProviderStateMixin
|
||||
implements AppState {
|
||||
TabController _tabController;
|
||||
AnimationController _controller;
|
||||
Animation<Offset> _shuffleOffsetAnimation;
|
||||
|
||||
@override
|
||||
Animation<Offset> get shuffleOffsetAnimation => _shuffleOffsetAnimation;
|
||||
|
||||
@override
|
||||
final PuzzleAnimator puzzle;
|
||||
|
||||
@override
|
||||
final _AnimationNotifier animationNotifier = _AnimationNotifier();
|
||||
final animationNotifier = _AnimationNotifier();
|
||||
|
||||
@override
|
||||
TabController get tabController => _tabController;
|
||||
|
||||
final _nanny = FrameNanny();
|
||||
|
||||
SharedTheme _currentTheme;
|
||||
|
||||
@override
|
||||
SharedTheme get currentTheme => _currentTheme;
|
||||
|
||||
@override
|
||||
set currentTheme(SharedTheme theme) {
|
||||
setState(() {
|
||||
_currentTheme = theme;
|
||||
});
|
||||
}
|
||||
|
||||
Duration _tickerTimeSinceLastEvent = Duration.zero;
|
||||
Ticker _ticker;
|
||||
Duration _lastElapsed;
|
||||
StreamSubscription _puzzleEventSubscription;
|
||||
StreamSubscription sub;
|
||||
|
||||
bool _autoPlay = false;
|
||||
_PuzzleControls _autoPlayListenable;
|
||||
@override
|
||||
bool autoPlay = false;
|
||||
|
||||
PuzzleHomeState(this.puzzle) {
|
||||
_puzzleEventSubscription = puzzle.onEvent.listen(_onPuzzleEvent);
|
||||
sub = puzzle.onEvent.listen(_onPuzzleEvent);
|
||||
|
||||
_themeDataCache = List.unmodifiable([
|
||||
ThemeSimple(this),
|
||||
ThemeSeattle(this),
|
||||
ThemePlaster(this),
|
||||
]);
|
||||
|
||||
_currentTheme = themeData.first;
|
||||
}
|
||||
|
||||
@override
|
||||
void initState() {
|
||||
super.initState();
|
||||
_autoPlayListenable = _PuzzleControls(this);
|
||||
_ticker ??= createTicker(_onTick);
|
||||
_ensureTicking();
|
||||
|
||||
_controller = AnimationController(
|
||||
vsync: this,
|
||||
duration: const Duration(milliseconds: 200),
|
||||
);
|
||||
|
||||
_shuffleOffsetAnimation = _controller.drive(const _Shake());
|
||||
_tabController = TabController(vsync: this, length: _themeDataCache.length);
|
||||
|
||||
_tabController.addListener(() {
|
||||
currentTheme = _themeDataCache[_tabController.index];
|
||||
});
|
||||
}
|
||||
|
||||
void _setAutoPlay(bool newValue) {
|
||||
if (newValue != _autoPlay) {
|
||||
List<SharedTheme> _themeDataCache;
|
||||
|
||||
@override
|
||||
Iterable<SharedTheme> get themeData => _themeDataCache;
|
||||
|
||||
@override
|
||||
void setAutoPlay(bool newValue) {
|
||||
if (newValue != autoPlay) {
|
||||
setState(() {
|
||||
// Only allow enabling autoPlay if the puzzle is not solved
|
||||
_autoPlayListenable._notify();
|
||||
_autoPlay = newValue && !puzzle.solved;
|
||||
if (_autoPlay) {
|
||||
autoPlay = newValue && !puzzle.solved;
|
||||
if (autoPlay) {
|
||||
_ensureTicking();
|
||||
}
|
||||
});
|
||||
@@ -86,46 +103,26 @@ class PuzzleHomeState extends State
|
||||
}
|
||||
|
||||
@override
|
||||
Widget build(BuildContext context) => MultiProvider(
|
||||
providers: [
|
||||
Provider<AppState>.value(value: this),
|
||||
ListenableProvider<PuzzleControls>.value(
|
||||
listenable: _autoPlayListenable,
|
||||
)
|
||||
],
|
||||
child: Material(
|
||||
child: Stack(
|
||||
children: <Widget>[
|
||||
const SizedBox.expand(
|
||||
child: FittedBox(
|
||||
fit: BoxFit.cover,
|
||||
child: Image(
|
||||
image: AssetImage('seattle.jpg'),
|
||||
),
|
||||
),
|
||||
),
|
||||
const LayoutBuilder(builder: _doBuild),
|
||||
],
|
||||
),
|
||||
),
|
||||
);
|
||||
Widget build(BuildContext context) => _currentTheme.build(context);
|
||||
|
||||
@override
|
||||
void dispose() {
|
||||
animationNotifier.dispose();
|
||||
_tabController.dispose();
|
||||
_controller?.dispose();
|
||||
_ticker?.dispose();
|
||||
_autoPlayListenable?.dispose();
|
||||
_puzzleEventSubscription.cancel();
|
||||
sub.cancel();
|
||||
super.dispose();
|
||||
}
|
||||
|
||||
void _onPuzzleEvent(PuzzleEvent e) {
|
||||
_autoPlayListenable._notify();
|
||||
if (e != PuzzleEvent.random) {
|
||||
_setAutoPlay(false);
|
||||
}
|
||||
_tickerTimeSinceLastEvent = Duration.zero;
|
||||
_ensureTicking();
|
||||
if (e == PuzzleEvent.noop) {
|
||||
assert(e == PuzzleEvent.noop);
|
||||
_controller.reset();
|
||||
_controller.forward();
|
||||
}
|
||||
setState(() {
|
||||
// noop
|
||||
});
|
||||
@@ -151,141 +148,40 @@ class PuzzleHomeState extends State
|
||||
}
|
||||
|
||||
_tickerTimeSinceLastEvent += delta;
|
||||
puzzle.update(delta > _maxFrameDuration ? _maxFrameDuration : delta);
|
||||
puzzle.update(_nanny.tick(delta));
|
||||
|
||||
if (!puzzle.stable) {
|
||||
animationNotifier.animate();
|
||||
} else {
|
||||
if (!_autoPlay) {
|
||||
if (!autoPlay) {
|
||||
_ticker.stop();
|
||||
_lastElapsed = null;
|
||||
}
|
||||
}
|
||||
|
||||
if (_autoPlay &&
|
||||
if (autoPlay &&
|
||||
_tickerTimeSinceLastEvent > const Duration(milliseconds: 200)) {
|
||||
puzzle.playRandom();
|
||||
|
||||
if (puzzle.solved) {
|
||||
_setAutoPlay(false);
|
||||
setAutoPlay(false);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
class _AnimationNotifier extends ChangeNotifier {
|
||||
class _Shake extends Animatable<Offset> {
|
||||
const _Shake();
|
||||
|
||||
@override
|
||||
Offset transform(double t) => Offset(0.01 * math.sin(t * math.pi * 3), 0);
|
||||
}
|
||||
|
||||
class _AnimationNotifier extends ChangeNotifier implements AnimationNotifier {
|
||||
_AnimationNotifier();
|
||||
|
||||
@override
|
||||
void animate() {
|
||||
notifyListeners();
|
||||
}
|
||||
}
|
||||
|
||||
const _maxFrameDuration = Duration(milliseconds: 34);
|
||||
|
||||
Widget _updateConstraints(
|
||||
BoxConstraints constraints, Widget Function(bool small) builder) {
|
||||
const _smallWidth = 580;
|
||||
|
||||
final constraintWidth =
|
||||
constraints.hasBoundedWidth ? constraints.maxWidth : 1000.0;
|
||||
|
||||
final constraintHeight =
|
||||
constraints.hasBoundedHeight ? constraints.maxHeight : 1000.0;
|
||||
|
||||
return builder(constraintWidth < _smallWidth || constraintHeight < 690);
|
||||
}
|
||||
|
||||
Widget _doBuild(BuildContext _, BoxConstraints constraints) =>
|
||||
_updateConstraints(constraints, _doBuildCore);
|
||||
|
||||
Widget _doBuildCore(bool small) => ValueTabController<SharedTheme>(
|
||||
values: themes,
|
||||
child: Consumer<SharedTheme>(
|
||||
builder: (_, theme, __) => AnimatedContainer(
|
||||
duration: puzzleAnimationDuration,
|
||||
color: theme.puzzleThemeBackground,
|
||||
child: Center(
|
||||
child: theme.styledWrapper(
|
||||
small,
|
||||
SizedBox(
|
||||
width: 580,
|
||||
child: Consumer<AppState>(
|
||||
builder: (context, appState, _) => Column(
|
||||
mainAxisSize: MainAxisSize.min,
|
||||
crossAxisAlignment: CrossAxisAlignment.center,
|
||||
children: <Widget>[
|
||||
Container(
|
||||
decoration: const BoxDecoration(
|
||||
border: Border(
|
||||
bottom: BorderSide(
|
||||
color: Colors.black26,
|
||||
width: 1,
|
||||
),
|
||||
),
|
||||
),
|
||||
margin:
|
||||
const EdgeInsets.symmetric(horizontal: 20),
|
||||
child: TabBar(
|
||||
controller: ValueTabController.of(context),
|
||||
labelPadding:
|
||||
const EdgeInsets.fromLTRB(0, 20, 0, 12),
|
||||
labelColor: theme.puzzleAccentColor,
|
||||
indicatorColor: theme.puzzleAccentColor,
|
||||
indicatorWeight: 1.5,
|
||||
unselectedLabelColor:
|
||||
Colors.black.withOpacity(0.6),
|
||||
tabs: themes
|
||||
.map((st) => Text(
|
||||
st.name.toUpperCase(),
|
||||
style: const TextStyle(
|
||||
letterSpacing: 0.5,
|
||||
),
|
||||
))
|
||||
.toList(),
|
||||
),
|
||||
),
|
||||
Flexible(
|
||||
child: Container(
|
||||
padding: const EdgeInsets.all(10),
|
||||
child: Flow(
|
||||
delegate: PuzzleFlowDelegate(
|
||||
small
|
||||
? const Size(90, 90)
|
||||
: const Size(140, 140),
|
||||
appState.puzzle,
|
||||
appState.animationNotifier,
|
||||
),
|
||||
children: List<Widget>.generate(
|
||||
appState.puzzle.length,
|
||||
(i) => theme.tileButtonCore(
|
||||
i, appState.puzzle, small),
|
||||
),
|
||||
),
|
||||
),
|
||||
),
|
||||
Container(
|
||||
decoration: const BoxDecoration(
|
||||
border: Border(
|
||||
top: BorderSide(
|
||||
color: Colors.black26, width: 1),
|
||||
),
|
||||
),
|
||||
padding: const EdgeInsets.only(
|
||||
left: 10,
|
||||
bottom: 6,
|
||||
top: 2,
|
||||
right: 10,
|
||||
),
|
||||
child: Consumer<PuzzleControls>(
|
||||
builder: (_, controls, __) => Row(
|
||||
children: theme.bottomControls(controls)),
|
||||
),
|
||||
)
|
||||
],
|
||||
),
|
||||
),
|
||||
),
|
||||
),
|
||||
),
|
||||
),
|
||||
),
|
||||
);
|
||||
|
||||
@@ -1,30 +1,30 @@
|
||||
// Copyright 2019 The Chromium Authors. All rights reserved.
|
||||
// Use of this source code is governed by a BSD-style license that can be
|
||||
// found in the LICENSE file.
|
||||
import 'package:flutter/material.dart';
|
||||
|
||||
import 'core/puzzle_proxy.dart';
|
||||
import 'flutter.dart';
|
||||
import 'puzzle_controls.dart';
|
||||
import 'app_state.dart';
|
||||
import 'core/puzzle_animator.dart';
|
||||
import 'puzzle_flow_delegate.dart';
|
||||
import 'widgets/material_interior_alt.dart';
|
||||
|
||||
final puzzleAnimationDuration = kThemeAnimationDuration * 3;
|
||||
|
||||
abstract class SharedTheme {
|
||||
const SharedTheme();
|
||||
SharedTheme(this._appState);
|
||||
|
||||
final AppState _appState;
|
||||
|
||||
PuzzleProxy get puzzle => _appState.puzzle;
|
||||
|
||||
String get name;
|
||||
|
||||
Color get puzzleThemeBackground;
|
||||
|
||||
RoundedRectangleBorder puzzleBorder(bool small);
|
||||
RoundedRectangleBorder get puzzleBorder;
|
||||
|
||||
Color get puzzleBackgroundColor;
|
||||
|
||||
Color get puzzleAccentColor;
|
||||
|
||||
EdgeInsetsGeometry tilePadding(PuzzleProxy puzzle) => const EdgeInsets.all(6);
|
||||
EdgeInsetsGeometry get tilePadding => const EdgeInsets.all(6);
|
||||
|
||||
Widget tileButton(int i, PuzzleProxy puzzle, bool small);
|
||||
Widget tileButton(int i);
|
||||
|
||||
Ink createInk(
|
||||
Widget child, {
|
||||
@@ -40,57 +40,159 @@ abstract class SharedTheme {
|
||||
);
|
||||
|
||||
Widget createButton(
|
||||
PuzzleProxy puzzle,
|
||||
bool small,
|
||||
int tileValue,
|
||||
Widget content, {
|
||||
Color color,
|
||||
RoundedRectangleBorder shape,
|
||||
}) =>
|
||||
AnimatedContainer(
|
||||
duration: puzzleAnimationDuration,
|
||||
padding: tilePadding(puzzle),
|
||||
duration: _puzzleAnimationDuration,
|
||||
padding: tilePadding,
|
||||
child: RaisedButton(
|
||||
elevation: 4,
|
||||
clipBehavior: Clip.hardEdge,
|
||||
animationDuration: puzzleAnimationDuration,
|
||||
onPressed: () => puzzle.clickOrShake(tileValue),
|
||||
shape: shape ?? puzzleBorder(small),
|
||||
animationDuration: _puzzleAnimationDuration,
|
||||
onPressed: () => _tilePress(tileValue),
|
||||
shape: shape ?? puzzleBorder,
|
||||
padding: const EdgeInsets.symmetric(),
|
||||
child: content,
|
||||
color: color,
|
||||
),
|
||||
);
|
||||
|
||||
Widget build(BuildContext context) => Material(
|
||||
child: Stack(
|
||||
children: <Widget>[
|
||||
const SizedBox.expand(
|
||||
child: FittedBox(
|
||||
fit: BoxFit.cover,
|
||||
child: Image(
|
||||
image: AssetImage('asset/seattle.jpg'),
|
||||
),
|
||||
),
|
||||
),
|
||||
AnimatedContainer(
|
||||
duration: _puzzleAnimationDuration,
|
||||
color: puzzleThemeBackground,
|
||||
child: Center(
|
||||
child: _styledWrapper(
|
||||
SizedBox(
|
||||
width: 580,
|
||||
child: Column(
|
||||
mainAxisSize: MainAxisSize.min,
|
||||
crossAxisAlignment: CrossAxisAlignment.center,
|
||||
children: <Widget>[
|
||||
Container(
|
||||
decoration: const BoxDecoration(
|
||||
border: Border(
|
||||
bottom: BorderSide(
|
||||
color: Colors.black26,
|
||||
width: 1,
|
||||
),
|
||||
),
|
||||
),
|
||||
margin: const EdgeInsets.symmetric(horizontal: 20),
|
||||
child: TabBar(
|
||||
controller: _appState.tabController,
|
||||
labelPadding: const EdgeInsets.fromLTRB(0, 20, 0, 12),
|
||||
labelColor: puzzleAccentColor,
|
||||
indicatorColor: puzzleAccentColor,
|
||||
indicatorWeight: 1.5,
|
||||
unselectedLabelColor: Colors.black.withOpacity(0.6),
|
||||
tabs: _appState.themeData
|
||||
.map((st) => Text(
|
||||
st.name.toUpperCase(),
|
||||
style: const TextStyle(
|
||||
letterSpacing: 0.5,
|
||||
),
|
||||
))
|
||||
.toList(),
|
||||
),
|
||||
),
|
||||
Container(
|
||||
constraints: const BoxConstraints.tightForFinite(),
|
||||
padding: const EdgeInsets.all(10),
|
||||
child: Flow(
|
||||
delegate: PuzzleFlowDelegate(
|
||||
_tileSize,
|
||||
puzzle,
|
||||
_appState.animationNotifier,
|
||||
),
|
||||
children: List<Widget>.generate(
|
||||
puzzle.length,
|
||||
_tileButton,
|
||||
),
|
||||
),
|
||||
),
|
||||
Container(
|
||||
decoration: const BoxDecoration(
|
||||
border: Border(
|
||||
top: BorderSide(color: Colors.black26, width: 1),
|
||||
),
|
||||
),
|
||||
padding: const EdgeInsets.only(
|
||||
left: 10,
|
||||
bottom: 6,
|
||||
top: 2,
|
||||
right: 10,
|
||||
),
|
||||
child: Row(children: _bottomControls(context)),
|
||||
)
|
||||
],
|
||||
),
|
||||
),
|
||||
),
|
||||
),
|
||||
)
|
||||
],
|
||||
));
|
||||
|
||||
Duration get _puzzleAnimationDuration => kThemeAnimationDuration * 3;
|
||||
|
||||
// Thought about using AnimatedContainer here, but it causes some weird
|
||||
// resizing behavior
|
||||
Widget styledWrapper(bool small, Widget child) => MaterialInterior(
|
||||
duration: puzzleAnimationDuration,
|
||||
shape: puzzleBorder(small),
|
||||
Widget _styledWrapper(Widget child) => MaterialInterior(
|
||||
duration: _puzzleAnimationDuration,
|
||||
shape: puzzleBorder,
|
||||
color: puzzleBackgroundColor,
|
||||
child: child,
|
||||
);
|
||||
|
||||
Size get _tileSize => const Size(140.0, 140.0);
|
||||
|
||||
void Function(bool newValue) get _setAutoPlay {
|
||||
if (puzzle.solved) {
|
||||
return null;
|
||||
}
|
||||
return _appState.setAutoPlay;
|
||||
}
|
||||
|
||||
void _tilePress(int tileValue) {
|
||||
_appState.setAutoPlay(false);
|
||||
_appState.puzzle.clickOrShake(tileValue);
|
||||
}
|
||||
|
||||
TextStyle get _infoStyle => TextStyle(
|
||||
color: puzzleAccentColor,
|
||||
fontWeight: FontWeight.bold,
|
||||
);
|
||||
|
||||
List<Widget> bottomControls(PuzzleControls controls) => <Widget>[
|
||||
List<Widget> _bottomControls(BuildContext context) => <Widget>[
|
||||
IconButton(
|
||||
onPressed: controls.reset,
|
||||
onPressed: puzzle.reset,
|
||||
icon: Icon(Icons.refresh, color: puzzleAccentColor),
|
||||
//Icons.refresh,
|
||||
),
|
||||
Checkbox(
|
||||
value: controls.autoPlay,
|
||||
onChanged: controls.setAutoPlayFunction,
|
||||
value: _appState.autoPlay,
|
||||
onChanged: _setAutoPlay,
|
||||
activeColor: puzzleAccentColor,
|
||||
),
|
||||
Expanded(
|
||||
child: Container(),
|
||||
),
|
||||
Text(
|
||||
controls.clickCount.toString(),
|
||||
puzzle.clickCount.toString(),
|
||||
textAlign: TextAlign.right,
|
||||
style: _infoStyle,
|
||||
),
|
||||
@@ -98,7 +200,7 @@ abstract class SharedTheme {
|
||||
SizedBox(
|
||||
width: 28,
|
||||
child: Text(
|
||||
controls.incorrectTiles.toString(),
|
||||
puzzle.incorrectTiles.toString(),
|
||||
textAlign: TextAlign.right,
|
||||
style: _infoStyle,
|
||||
),
|
||||
@@ -106,11 +208,11 @@ abstract class SharedTheme {
|
||||
const Text(' Tiles left ')
|
||||
];
|
||||
|
||||
Widget tileButtonCore(int i, PuzzleProxy puzzle, bool small) {
|
||||
Widget _tileButton(int i) {
|
||||
if (i == puzzle.tileCount && !puzzle.solved) {
|
||||
return const Center();
|
||||
}
|
||||
|
||||
return tileButton(i, puzzle, small);
|
||||
return tileButton(i);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,9 +1,6 @@
|
||||
// Copyright 2019 The Chromium Authors. All rights reserved.
|
||||
// Use of this source code is governed by a BSD-style license that can be
|
||||
// found in the LICENSE file.
|
||||
import 'package:flutter/material.dart';
|
||||
|
||||
import 'core/puzzle_proxy.dart';
|
||||
import 'flutter.dart';
|
||||
import 'app_state.dart';
|
||||
import 'shared_theme.dart';
|
||||
|
||||
const _yellowIsh = Color.fromARGB(255, 248, 244, 233);
|
||||
@@ -14,7 +11,7 @@ class ThemePlaster extends SharedTheme {
|
||||
@override
|
||||
String get name => 'Plaster';
|
||||
|
||||
const ThemePlaster();
|
||||
ThemePlaster(AppState baseTheme) : super(baseTheme);
|
||||
|
||||
@override
|
||||
Color get puzzleThemeBackground => _chocolate;
|
||||
@@ -26,18 +23,18 @@ class ThemePlaster extends SharedTheme {
|
||||
Color get puzzleAccentColor => _orangeIsh;
|
||||
|
||||
@override
|
||||
RoundedRectangleBorder puzzleBorder(bool small) => RoundedRectangleBorder(
|
||||
side: const BorderSide(
|
||||
RoundedRectangleBorder get puzzleBorder => const RoundedRectangleBorder(
|
||||
side: BorderSide(
|
||||
color: Color.fromARGB(255, 103, 103, 105),
|
||||
width: 8,
|
||||
),
|
||||
borderRadius: BorderRadius.all(
|
||||
Radius.circular(small ? 10 : 18),
|
||||
Radius.circular(18),
|
||||
),
|
||||
);
|
||||
|
||||
@override
|
||||
Widget tileButton(int i, PuzzleProxy puzzle, bool small) {
|
||||
Widget tileButton(int i) {
|
||||
final correctColumn = i % puzzle.width;
|
||||
final correctRow = i ~/ puzzle.width;
|
||||
|
||||
@@ -45,10 +42,10 @@ class ThemePlaster extends SharedTheme {
|
||||
|
||||
if (i == puzzle.tileCount) {
|
||||
assert(puzzle.solved);
|
||||
return Center(
|
||||
return const Center(
|
||||
child: Icon(
|
||||
Icons.thumb_up,
|
||||
size: small ? 50 : 72,
|
||||
size: 72,
|
||||
color: _orangeIsh,
|
||||
),
|
||||
);
|
||||
@@ -59,13 +56,11 @@ class ThemePlaster extends SharedTheme {
|
||||
style: TextStyle(
|
||||
color: primary ? _yellowIsh : _chocolate,
|
||||
fontFamily: 'Plaster',
|
||||
fontSize: small ? 40 : 77,
|
||||
fontSize: 77,
|
||||
),
|
||||
);
|
||||
|
||||
return createButton(
|
||||
puzzle,
|
||||
small,
|
||||
i,
|
||||
content,
|
||||
color: primary ? _orangeIsh : _yellowIsh,
|
||||
|
||||
@@ -1,9 +1,6 @@
|
||||
// Copyright 2019 The Chromium Authors. All rights reserved.
|
||||
// Use of this source code is governed by a BSD-style license that can be
|
||||
// found in the LICENSE file.
|
||||
import 'package:flutter/material.dart';
|
||||
|
||||
import 'core/puzzle_proxy.dart';
|
||||
import 'flutter.dart';
|
||||
import 'app_state.dart';
|
||||
import 'shared_theme.dart';
|
||||
import 'widgets/decoration_image_plus.dart';
|
||||
|
||||
@@ -11,7 +8,7 @@ class ThemeSeattle extends SharedTheme {
|
||||
@override
|
||||
String get name => 'Seattle';
|
||||
|
||||
const ThemeSeattle();
|
||||
ThemeSeattle(AppState proxy) : super(proxy);
|
||||
|
||||
@override
|
||||
Color get puzzleThemeBackground => const Color.fromARGB(153, 90, 135, 170);
|
||||
@@ -23,19 +20,18 @@ class ThemeSeattle extends SharedTheme {
|
||||
Color get puzzleAccentColor => const Color(0xff000579f);
|
||||
|
||||
@override
|
||||
RoundedRectangleBorder puzzleBorder(bool small) =>
|
||||
const RoundedRectangleBorder(
|
||||
RoundedRectangleBorder get puzzleBorder => const RoundedRectangleBorder(
|
||||
borderRadius: BorderRadius.all(
|
||||
Radius.circular(1),
|
||||
),
|
||||
);
|
||||
|
||||
@override
|
||||
EdgeInsetsGeometry tilePadding(PuzzleProxy puzzle) =>
|
||||
EdgeInsetsGeometry get tilePadding =>
|
||||
puzzle.solved ? const EdgeInsets.all(1) : const EdgeInsets.all(4);
|
||||
|
||||
@override
|
||||
Widget tileButton(int i, PuzzleProxy puzzle, bool small) {
|
||||
Widget tileButton(int i) {
|
||||
if (i == puzzle.tileCount && !puzzle.solved) {
|
||||
assert(puzzle.solved);
|
||||
}
|
||||
@@ -45,7 +41,7 @@ class ThemeSeattle extends SharedTheme {
|
||||
puzzleHeight: puzzle.height,
|
||||
pieceIndex: i,
|
||||
fit: BoxFit.cover,
|
||||
image: const AssetImage('seattle.jpg'));
|
||||
image: const AssetImage('asset/seattle.jpg'));
|
||||
|
||||
final correctPosition = puzzle.isCorrectPosition(i);
|
||||
final content = createInk(
|
||||
@@ -62,14 +58,14 @@ class ThemeSeattle extends SharedTheme {
|
||||
style: TextStyle(
|
||||
fontWeight: FontWeight.normal,
|
||||
color: correctPosition ? Colors.white : Colors.black,
|
||||
fontSize: small ? 25 : 42,
|
||||
fontSize: 42,
|
||||
),
|
||||
),
|
||||
),
|
||||
image: decorationImage,
|
||||
padding: EdgeInsets.all(small ? 20 : 32),
|
||||
padding: const EdgeInsets.all(32),
|
||||
);
|
||||
|
||||
return createButton(puzzle, small, i, content);
|
||||
return createButton(i, content);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,9 +1,6 @@
|
||||
// Copyright 2019 The Chromium Authors. All rights reserved.
|
||||
// Use of this source code is governed by a BSD-style license that can be
|
||||
// found in the LICENSE file.
|
||||
import 'package:flutter/material.dart';
|
||||
|
||||
import 'core/puzzle_proxy.dart';
|
||||
import 'flutter.dart';
|
||||
import 'app_state.dart';
|
||||
import 'shared_theme.dart';
|
||||
|
||||
const _accentBlue = Color(0xff000579e);
|
||||
@@ -12,7 +9,7 @@ class ThemeSimple extends SharedTheme {
|
||||
@override
|
||||
String get name => 'Simple';
|
||||
|
||||
const ThemeSimple();
|
||||
ThemeSimple(AppState proxy) : super(proxy);
|
||||
|
||||
@override
|
||||
Color get puzzleThemeBackground => Colors.white;
|
||||
@@ -24,8 +21,7 @@ class ThemeSimple extends SharedTheme {
|
||||
Color get puzzleAccentColor => _accentBlue;
|
||||
|
||||
@override
|
||||
RoundedRectangleBorder puzzleBorder(bool small) =>
|
||||
const RoundedRectangleBorder(
|
||||
RoundedRectangleBorder get puzzleBorder => const RoundedRectangleBorder(
|
||||
side: BorderSide(color: Colors.black26, width: 1),
|
||||
borderRadius: BorderRadius.all(
|
||||
Radius.circular(4),
|
||||
@@ -33,7 +29,7 @@ class ThemeSimple extends SharedTheme {
|
||||
);
|
||||
|
||||
@override
|
||||
Widget tileButton(int i, PuzzleProxy puzzle, bool small) {
|
||||
Widget tileButton(int i) {
|
||||
if (i == puzzle.tileCount) {
|
||||
assert(puzzle.solved);
|
||||
return const Center(
|
||||
@@ -54,15 +50,13 @@ class ThemeSimple extends SharedTheme {
|
||||
style: TextStyle(
|
||||
color: Colors.white,
|
||||
fontWeight: correctPosition ? FontWeight.bold : FontWeight.normal,
|
||||
fontSize: small ? 30 : 49,
|
||||
fontSize: 49,
|
||||
),
|
||||
),
|
||||
),
|
||||
);
|
||||
|
||||
return createButton(
|
||||
puzzle,
|
||||
small,
|
||||
i,
|
||||
content,
|
||||
color: const Color.fromARGB(255, 13, 87, 155),
|
||||
|
||||
@@ -1,9 +0,0 @@
|
||||
import 'theme_plaster.dart';
|
||||
import 'theme_seattle.dart';
|
||||
import 'theme_simple.dart';
|
||||
|
||||
const themes = [
|
||||
ThemeSimple(),
|
||||
ThemeSeattle(),
|
||||
ThemePlaster(),
|
||||
];
|
||||
@@ -1,88 +0,0 @@
|
||||
import 'package:flutter_web/material.dart';
|
||||
import 'package:provider/provider.dart';
|
||||
|
||||
class ValueTabController<T> 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<T> 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<T> createState() => _ValueTabControllerState<T>();
|
||||
}
|
||||
|
||||
class _ValueTabControllerState<T> extends State<ValueTabController<T>>
|
||||
with SingleTickerProviderStateMixin {
|
||||
final _notifier = ValueNotifier<T>(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;
|
||||
}
|
||||
@@ -1,12 +1,8 @@
|
||||
// Copyright 2019 The Chromium Authors. All rights reserved.
|
||||
// Use of this source code is governed by a BSD-style license that can be
|
||||
// found in the LICENSE file.
|
||||
|
||||
// ignore_for_file: omit_local_variable_types, annotate_overrides
|
||||
|
||||
import 'package:flutter_web_ui/ui.dart' as ui show Image;
|
||||
import 'dart:ui' as ui show Image;
|
||||
|
||||
import '../flutter.dart';
|
||||
import 'package:flutter/material.dart';
|
||||
|
||||
// A model on top of DecorationImage that supports slicing up the source image
|
||||
// efficiently to draw it as tiles in the puzzle game
|
||||
@@ -142,13 +138,13 @@ class DecorationImagePlus implements DecorationImage {
|
||||
|
||||
@override
|
||||
String toString() {
|
||||
final List<String> properties = <String>['$image'];
|
||||
final List<String> properties = <String>[];
|
||||
properties.add('$image');
|
||||
if (colorFilter != null) properties.add('$colorFilter');
|
||||
if (fit != null &&
|
||||
!(fit == BoxFit.fill && centerSlice != null) &&
|
||||
!(fit == BoxFit.scaleDown && centerSlice == null)) {
|
||||
!(fit == BoxFit.scaleDown && centerSlice == null))
|
||||
properties.add('$fit');
|
||||
}
|
||||
properties.add('$alignment');
|
||||
if (centerSlice != null) properties.add('centerSlice: $centerSlice');
|
||||
if (repeat != ImageRepeat.noRepeat) properties.add('$repeat');
|
||||
@@ -170,13 +166,16 @@ class DecorationImagePlus implements DecorationImage {
|
||||
/// longer needed.
|
||||
class DecorationImagePainterPlus implements DecorationImagePainter {
|
||||
DecorationImagePainterPlus._(this._details, this._onChanged)
|
||||
: assert(_details != null);
|
||||
: assert(_details != null) {
|
||||
_imageStreamListener = ImageStreamListener(_imageListener);
|
||||
}
|
||||
|
||||
final DecorationImagePlus _details;
|
||||
final VoidCallback _onChanged;
|
||||
|
||||
ImageStream _imageStream;
|
||||
ImageInfo _image;
|
||||
ImageStreamListener _imageStreamListener;
|
||||
|
||||
/// Draw the image onto the given canvas.
|
||||
///
|
||||
@@ -218,15 +217,14 @@ class DecorationImagePainterPlus implements DecorationImagePainter {
|
||||
|
||||
final ImageStream newImageStream = _details.image.resolve(configuration);
|
||||
if (newImageStream.key != _imageStream?.key) {
|
||||
_imageStream?.removeListener(_imageListener);
|
||||
_imageStream = newImageStream..addListener(_imageListener);
|
||||
_imageStream?.removeListener(_imageStreamListener);
|
||||
_imageStream = newImageStream..addListener(_imageStreamListener);
|
||||
}
|
||||
if (_image == null) return;
|
||||
|
||||
if (clipPath != null) {
|
||||
canvas
|
||||
..save()
|
||||
..clipPath(clipPath);
|
||||
canvas.save();
|
||||
canvas.clipPath(clipPath);
|
||||
}
|
||||
|
||||
_paintImage(
|
||||
@@ -259,7 +257,7 @@ class DecorationImagePainterPlus implements DecorationImagePainter {
|
||||
/// After this method has been called, the object is no longer usable.
|
||||
@mustCallSuper
|
||||
void dispose() {
|
||||
_imageStream?.removeListener(_imageListener);
|
||||
_imageStream?.removeListener(_imageStreamListener);
|
||||
}
|
||||
|
||||
@override
|
||||
|
||||
@@ -1,8 +1,4 @@
|
||||
// Copyright 2019 The Chromium Authors. All rights reserved.
|
||||
// Use of this source code is governed by a BSD-style license that can be
|
||||
// found in the LICENSE file.
|
||||
|
||||
import '../flutter.dart';
|
||||
import 'package:flutter/material.dart';
|
||||
|
||||
// Copied from
|
||||
// https://github.com/flutter/flutter/blob/f5b02e3c05ed1ab31e890add84fb56e35de2d392/packages/flutter/lib/src/material/material.dart#L593-L715
|
||||
|
||||
Reference in New Issue
Block a user