debug.dart 1.07 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 15 16 17 18 19
    if (context.widget is! Material && context.ancestorWidgetOfExactType(Material) == null) {
      Element element = context;
      throw new WidgetError(
        'Missing Material widget.',
        '${context.widget} needs to be placed inside a Material widget. Ownership chain:\n${element.debugGetOwnershipChain(10)}'
      );
    }
    return true;
20 21 22
  });
  return true;
}
23 24 25 26 27 28 29 30 31 32 33 34 35 36 37


bool debugCheckHasScaffold(BuildContext context) {
  assert(() {
    if (Scaffold.of(context) == null) {
      Element element = context;
      throw new WidgetError(
        'Missing Scaffold widget.',
        '${context.widget} needs to be placed inside the body of a Scaffold widget. Ownership chain:\n${element.debugGetOwnershipChain(10)}'
      );
    }
    return true;
  });
  return true;
}