debug.dart 1.96 KB
Newer Older
1 2 3 4 5 6 7
// 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 'package:flutter/widgets.dart';

import 'material.dart';
8
import 'scaffold.dart';
9 10 11

bool debugCheckHasMaterial(BuildContext context) {
  assert(() {
Hixie's avatar
Hixie committed
12 13 14
    if (context.widget is! Material && context.ancestorWidgetOfExactType(Material) == null) {
      Element element = context;
      throw new WidgetError(
15
        'No Material widget found.\n'
16
        '${context.widget.runtimeType} widgets require a Material widget ancestor.\n'
17 18 19 20 21
        'In material design, most widgets are conceptually "printed" on a sheet of material. In Flutter\'s material library, '
        'that material is represented by the Material widget. It is the Material widget that renders ink splashes, for instance. '
        'Because of this, many material library widgets require that there be a Material widget in the tree above them.\n'
        'To introduce a Material widget, you can either directly include one, or use a widget that contains Material itself, '
        'such as a Card, Dialog, Drawer, or Scaffold.\n'
22 23
        'The specific widget that could not find a Material ancestor was:\n'
        '  ${context.widget}'
24 25
        'The ownership chain for the affected widget is:\n'
        '  ${element.debugGetOwnershipChain(10)}'
Hixie's avatar
Hixie committed
26 27 28
      );
    }
    return true;
29 30 31
  });
  return true;
}
32 33 34 35 36 37 38


bool debugCheckHasScaffold(BuildContext context) {
  assert(() {
    if (Scaffold.of(context) == null) {
      Element element = context;
      throw new WidgetError(
39
        'No Scaffold widget found.\n'
40 41 42
        '${context.widget.runtimeType} widgets require a Scaffold widget ancestor.\n'
        'The specific widget that could not find a Scaffold ancestor was:\n'
        '  ${context.widget}'
43 44
        'The ownership chain for the affected widget is:\n'
        '  ${element.debugGetOwnershipChain(10)}'
45 46 47 48 49 50
      );
    }
    return true;
  });
  return true;
}