
This lets us preview widgets in the gallery using small, normal, large, and HUGE text. Added selections to the main drawer for these options. Defaults to "normal", obviously.
180 lines
5.4 KiB
Dart
180 lines
5.4 KiB
Dart
// Copyright 2015 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 'package:flutter/foundation.dart' show defaultTargetPlatform;
|
|
import 'package:flutter/material.dart';
|
|
import 'package:flutter/scheduler.dart' show timeDilation;
|
|
|
|
import 'home.dart';
|
|
import 'item.dart';
|
|
import 'updates.dart';
|
|
|
|
final ThemeData _kGalleryLightTheme = new ThemeData(
|
|
brightness: Brightness.light,
|
|
primarySwatch: Colors.blue,
|
|
);
|
|
|
|
final ThemeData _kGalleryDarkTheme = new ThemeData(
|
|
brightness: Brightness.dark,
|
|
primarySwatch: Colors.blue,
|
|
);
|
|
|
|
class GalleryApp extends StatefulWidget {
|
|
const GalleryApp({
|
|
this.updateUrlFetcher,
|
|
this.enablePerformanceOverlay: true,
|
|
this.checkerboardRasterCacheImages: true,
|
|
this.checkerboardOffscreenLayers: true,
|
|
this.onSendFeedback,
|
|
Key key}
|
|
) : super(key: key);
|
|
|
|
final UpdateUrlFetcher updateUrlFetcher;
|
|
|
|
final bool enablePerformanceOverlay;
|
|
|
|
final bool checkerboardRasterCacheImages;
|
|
|
|
final bool checkerboardOffscreenLayers;
|
|
|
|
final VoidCallback onSendFeedback;
|
|
|
|
@override
|
|
GalleryAppState createState() => new GalleryAppState();
|
|
}
|
|
|
|
class GalleryAppState extends State<GalleryApp> {
|
|
bool _useLightTheme = true;
|
|
bool _showPerformanceOverlay = false;
|
|
bool _checkerboardRasterCacheImages = false;
|
|
bool _checkerboardOffscreenLayers = false;
|
|
double _timeDilation = 1.0;
|
|
TargetPlatform _platform;
|
|
|
|
// A null value indicates "use system default".
|
|
double _textScaleFactor;
|
|
|
|
Timer _timeDilationTimer;
|
|
|
|
@override
|
|
void initState() {
|
|
_timeDilation = timeDilation;
|
|
super.initState();
|
|
}
|
|
|
|
@override
|
|
void dispose() {
|
|
_timeDilationTimer?.cancel();
|
|
_timeDilationTimer = null;
|
|
super.dispose();
|
|
}
|
|
|
|
@override
|
|
Widget build(BuildContext context) {
|
|
Widget home = new GalleryHome(
|
|
useLightTheme: _useLightTheme,
|
|
onThemeChanged: (bool value) {
|
|
setState(() {
|
|
_useLightTheme = value;
|
|
});
|
|
},
|
|
showPerformanceOverlay: _showPerformanceOverlay,
|
|
onShowPerformanceOverlayChanged: widget.enablePerformanceOverlay ? (bool value) {
|
|
setState(() {
|
|
_showPerformanceOverlay = value;
|
|
});
|
|
} : null,
|
|
checkerboardRasterCacheImages: _checkerboardRasterCacheImages,
|
|
onCheckerboardRasterCacheImagesChanged: widget.checkerboardRasterCacheImages ? (bool value) {
|
|
setState(() {
|
|
_checkerboardRasterCacheImages = value;
|
|
});
|
|
} : null,
|
|
checkerboardOffscreenLayers: _checkerboardOffscreenLayers,
|
|
onCheckerboardOffscreenLayersChanged: widget.checkerboardOffscreenLayers ? (bool value) {
|
|
setState(() {
|
|
_checkerboardOffscreenLayers = value;
|
|
});
|
|
} : null,
|
|
onPlatformChanged: (TargetPlatform value) {
|
|
setState(() {
|
|
_platform = value == defaultTargetPlatform ? null : value;
|
|
});
|
|
},
|
|
timeDilation: _timeDilation,
|
|
onTimeDilationChanged: (double value) {
|
|
setState(() {
|
|
_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;
|
|
}
|
|
});
|
|
},
|
|
textScaleFactor: _textScaleFactor,
|
|
onTextScaleFactorChanged: (double value) {
|
|
setState(() {
|
|
_textScaleFactor = value;
|
|
});
|
|
},
|
|
onSendFeedback: widget.onSendFeedback,
|
|
);
|
|
|
|
if (widget.updateUrlFetcher != null) {
|
|
home = new Updater(
|
|
updateUrlFetcher: widget.updateUrlFetcher,
|
|
child: home,
|
|
);
|
|
}
|
|
|
|
final Map<String, WidgetBuilder> _kRoutes = new Map<String,
|
|
WidgetBuilder>.fromIterable(
|
|
// For a different example of how to set up an application routing table
|
|
// using named routes, consider the example in the Navigator class documentation:
|
|
// https://docs.flutter.io/flutter/widgets/Navigator-class.html
|
|
kAllGalleryItems,
|
|
key: (GalleryItem item) => item.routeName,
|
|
value: (GalleryItem item) =>
|
|
(BuildContext context) {
|
|
if (_textScaleFactor != null) {
|
|
return new MediaQuery(
|
|
data: new MediaQueryData(textScaleFactor: _textScaleFactor),
|
|
child: item.buildRoute(context),
|
|
);
|
|
} else {
|
|
return item.buildRoute(context);
|
|
}
|
|
}
|
|
);
|
|
|
|
if (_textScaleFactor != null) {
|
|
home = new MediaQuery(
|
|
data: new MediaQueryData(textScaleFactor: _textScaleFactor),
|
|
child: home,
|
|
);
|
|
}
|
|
|
|
return new MaterialApp(
|
|
title: 'Flutter Gallery',
|
|
color: Colors.grey,
|
|
theme: (_useLightTheme ? _kGalleryLightTheme : _kGalleryDarkTheme).copyWith(platform: _platform ?? defaultTargetPlatform),
|
|
showPerformanceOverlay: _showPerformanceOverlay,
|
|
checkerboardRasterCacheImages: _checkerboardRasterCacheImages,
|
|
checkerboardOffscreenLayers: _checkerboardOffscreenLayers,
|
|
routes: _kRoutes,
|
|
home: home,
|
|
);
|
|
}
|
|
}
|