public static bool debugCheckHasMaterialLocalizations(BuildContext context) { D.assert(() => { if (Localizations.of <MaterialLocalizations>(context, typeof(MaterialLocalizations)) == null) { var list = new List <DiagnosticsNode>() { new ErrorSummary("No MaterialLocalizations found."), new ErrorDescription( "${context.widget.runtimeType} widgets require MaterialLocalizations " + "to be provided by a Localizations widget ancestor." ), new ErrorDescription( "Localizations are used to generate many different messages, labels, " + "and abbreviations which are used by the material library." ), new ErrorHint( "To introduce a MaterialLocalizations, either use a " + "MaterialApp at the root of your application to include them " + "automatically, or add a Localization widget with a " + "MaterialLocalizations delegate." ), }; list.AddRange(context.describeMissingAncestor(expectedAncestorType: typeof(MaterialLocalizations))); throw new UIWidgetsError(list); } return(true); }); return(true); }
public static bool debugCheckHasMaterialLocalizations(BuildContext context) { D.assert(() => { if (Localizations.of <MaterialLocalizations>(context, typeof(MaterialLocalizations)) == null) { StringBuilder message = new StringBuilder(); message.AppendLine("No MaterialLocalizations found."); message.AppendLine( context.widget.GetType() + " widgets require MaterialLocalizations " + "to be provided by a Localizations widget ancestor."); message.AppendLine( "Localizations are used to generate many different messages, labels," + "and abbreviations which are used by the material library. "); message.AppendLine( "To introduce a MaterialLocalizations, either use a " + " MaterialApp at the root of your application to include them " + "automatically, or add a Localization widget with a " + "MaterialLocalizations delegate."); message.AppendLine( "The specific widget that could not find a MaterialLocalizations ancestor was:" ); message.AppendLine(" " + context.widget); List <Widget> ancestors = new List <Widget>(); context.visitAncestorElements((Element element) => { ancestors.Add(element.widget); return(true); }); if (ancestors.isNotEmpty()) { message.Append("The ancestors of this widget were:"); foreach (Widget ancestor in ancestors) { message.Append("\n " + ancestor); } } else { message.AppendLine( "This widget is the root of the tree, so it has no " + "ancestors, let alone a \"Localizations\" ancestor." ); } throw new UIWidgetsError(message.ToString()); } return(true); }); return(true); }
public static CupertinoLocalizations of(BuildContext context) { return(Localizations.of <CupertinoLocalizations>(context, typeof(CupertinoLocalizations))); }
public static L of(BuildContext context) { return(Localizations.of <L>(context, typeof(MaterialLocalizations))); }