Commit 6dcd1271 authored by Ian Hickson's avatar Ian Hickson Committed by GitHub

Delay time dilation so users see the checkbox (#7803)

Fixes https://github.com/flutter/flutter/issues/5066
parent 5f38773e
...@@ -2,6 +2,8 @@ ...@@ -2,6 +2,8 @@
// Use of this source code is governed by a BSD-style license that can be // Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file. // found in the LICENSE file.
import 'dart:async';
import 'package:flutter/foundation.dart' show defaultTargetPlatform; import 'package:flutter/foundation.dart' show defaultTargetPlatform;
import 'package:flutter/material.dart'; import 'package:flutter/material.dart';
import 'package:flutter/scheduler.dart' show timeDilation; import 'package:flutter/scheduler.dart' show timeDilation;
...@@ -51,8 +53,23 @@ class GalleryAppState extends State<GalleryApp> { ...@@ -51,8 +53,23 @@ class GalleryAppState extends State<GalleryApp> {
bool _useLightTheme = true; bool _useLightTheme = true;
bool _showPerformanceOverlay = false; bool _showPerformanceOverlay = false;
bool _checkerboardRasterCacheImages = false; bool _checkerboardRasterCacheImages = false;
double _timeDilation = 1.0;
TargetPlatform _platform = defaultTargetPlatform;
TargetPlatform platform = defaultTargetPlatform; Timer _timeDilationTimer;
@override
void initState() {
_timeDilation = timeDilation;
super.initState();
}
@override
void dispose() {
_timeDilationTimer?.cancel();
_timeDilationTimer = null;
super.dispose();
}
@override @override
Widget build(BuildContext context) { Widget build(BuildContext context) {
...@@ -77,13 +94,25 @@ class GalleryAppState extends State<GalleryApp> { ...@@ -77,13 +94,25 @@ class GalleryAppState extends State<GalleryApp> {
} : null, } : null,
onPlatformChanged: (TargetPlatform value) { onPlatformChanged: (TargetPlatform value) {
setState(() { setState(() {
platform = value; _platform = value;
}); });
}, },
timeDilation: timeDilation, timeDilation: _timeDilation,
onTimeDilationChanged: (double value) { onTimeDilationChanged: (double value) {
setState(() { setState(() {
timeDilation = value; _timeDilationTimer?.cancel();
_timeDilationTimer = null;
_timeDilation = value;
if (_timeDilation > 1.0) {
// We delay the time dilation change long enough that the user can see
// that the checkbox in the drawer has started reacting, then we slam
// on the brakes so that they see that the time is in fact now dilated.
_timeDilationTimer = new Timer(const Duration(milliseconds: 150), () {
timeDilation = _timeDilation;
});
} else {
timeDilation = _timeDilation;
}
}); });
}, },
onSendFeedback: config.onSendFeedback, onSendFeedback: config.onSendFeedback,
...@@ -99,7 +128,7 @@ class GalleryAppState extends State<GalleryApp> { ...@@ -99,7 +128,7 @@ class GalleryAppState extends State<GalleryApp> {
return new MaterialApp( return new MaterialApp(
title: 'Flutter Gallery', title: 'Flutter Gallery',
color: Colors.grey[500], color: Colors.grey[500],
theme: (_useLightTheme ? _kGalleryLightTheme : _kGalleryDarkTheme).copyWith(platform: platform), theme: (_useLightTheme ? _kGalleryLightTheme : _kGalleryDarkTheme).copyWith(platform: _platform),
showPerformanceOverlay: _showPerformanceOverlay, showPerformanceOverlay: _showPerformanceOverlay,
checkerboardRasterCacheImages: _checkerboardRasterCacheImages, checkerboardRasterCacheImages: _checkerboardRasterCacheImages,
routes: _kRoutes, routes: _kRoutes,
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment