shrine_demo.dart 1.47 KB
Newer Older
1 2 3 4 5 6 7 8 9 10 11 12
// Copyright 2016 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 'shrine/shrine_home.dart' show ShrineHome;
import 'shrine/shrine_theme.dart' show ShrineTheme;

// This code would ordinarily be part of the MaterialApp's home. It's being
// used by the ShrineDemo and by each route pushed from there because this
// isn't a standalone app with its own main() and MaterialApp.
13
Widget buildShrine(BuildContext context, Widget child) {
14 15
  return Theme(
    data: ThemeData(
16
      primarySwatch: Colors.grey,
17
      iconTheme: const IconThemeData(color: Color(0xFF707070)),
18
      platform: Theme.of(context).platform,
19
    ),
20
    child: ShrineTheme(child: child)
21 22 23 24 25 26 27
  );
}

// In a standalone version of this app, MaterialPageRoute<T> could be used directly.
class ShrinePageRoute<T> extends MaterialPageRoute<T> {
  ShrinePageRoute({
    WidgetBuilder builder,
28
    RouteSettings settings,
29
  }) : super(builder: builder, settings: settings);
30 31

  @override
32 33
  Widget buildPage(BuildContext context, Animation<double> animation, Animation<double> secondaryAnimation) {
    return buildShrine(context, super.buildPage(context, animation, secondaryAnimation));
34 35 36 37 38 39 40
  }
}

class ShrineDemo extends StatelessWidget {
  static const String routeName = '/shrine'; // Used by the Gallery app.

  @override
41
  Widget build(BuildContext context) => buildShrine(context, ShrineHome());
42
}