|
|
|
|
|
|
supportedLocales = supportedLocales ?? new List<Locale> {new Locale("en", "US")}; |
|
|
|
window = Window.instance; |
|
|
|
D.assert(routes != null); |
|
|
|
D.assert(color != null); |
|
|
|
D.assert(supportedLocales != null && supportedLocales.isNotEmpty()); |
|
|
|
this.home = home; |
|
|
|
this.navigatorKey = navigatorKey; |
|
|
|
this.onGenerateRoute = onGenerateRoute; |
|
|
|
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
public class WindowProvider : InheritedWidget { |
|
|
|
public readonly Window window; |
|
|
|
|
|
|
|
public WindowProvider(Key key = null, Window window = null, Widget child = null) : |
|
|
|
base(key, child) { |
|
|
|
D.assert(window != null); |
|
|
|
this.window = window; |
|
|
|
} |
|
|
|
|
|
|
|
public static Window of(BuildContext context) { |
|
|
|
var provider = (WindowProvider) context.inheritFromWidgetOfExactType(typeof(WindowProvider)); |
|
|
|
if (provider == null) { |
|
|
|
throw new UIWidgetsError("WindowProvider is missing"); |
|
|
|
} |
|
|
|
|
|
|
|
return provider.window; |
|
|
|
} |
|
|
|
|
|
|
|
public static Window of(GameObject gameObject) { |
|
|
|
D.assert(false, () => "window.Of is not implemented yet!"); |
|
|
|
return null; |
|
|
|
|
|
|
|
/* |
|
|
|
var panel = gameObject.GetComponent<UIWidgetsPanel>(); |
|
|
|
return panel == null ? null : panel.window; |
|
|
|
*/ |
|
|
|
} |
|
|
|
|
|
|
|
public override bool updateShouldNotify(InheritedWidget oldWidget) { |
|
|
|
D.assert(window == ((WindowProvider) oldWidget).window); |
|
|
|
return false; |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
class _WidgetsAppState : State<WidgetsApp>, WidgetsBindingObserver { |
|
|
|
public void didChangeMetrics() { |
|
|
|
setState(); |
|
|
|
|
|
|
public override void initState() { |
|
|
|
base.initState(); |
|
|
|
_updateNavigator(); |
|
|
|
|
|
|
|
//todo: xingwei.zhu: change the default locale to ui.Window.locale
|
|
|
|
|
|
|
|
/*D.assert(() => { |
|
|
|
WidgetInspectorService.instance.inspectorShowCallback += inspectorShowChanged; |
|
|
|
return true; |
|
|
|
});*/ |
|
|
|
|
|
|
|
WidgetsBinding.instance.addObserver(this); |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
public override void dispose() { |
|
|
|
WidgetsBinding.instance.removeObserver(this); |
|
|
|
|
|
|
|
/*D.assert(() => { |
|
|
|
WidgetInspectorService.instance.inspectorShowCallback -= inspectorShowChanged; |
|
|
|
return true; |
|
|
|
});*/ |
|
|
|
base.dispose(); |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
/*bool _debugCheckLocalizations(Locale appLocale) { |
|
|
|
bool _debugCheckLocalizations(Locale appLocale) { |
|
|
|
foreach ( LocalizationsDelegate<dynamic> _delegate in _localizationsDelegates) { |
|
|
|
foreach ( LocalizationsDelegate _delegate in _localizationsDelegates) { |
|
|
|
if (!unsupportedTypes.Contains(_delegate.type)) |
|
|
|
continue; |
|
|
|
if (_delegate.isSupported(appLocale)) |
|
|
|
|
|
|
if (unsupportedTypesList.SequenceEqual(list)) |
|
|
|
return true; |
|
|
|
|
|
|
|
StringBuffer message = new StringBuffer(); |
|
|
|
message.writeln('\u2550' * 8); |
|
|
|
message.writeln( |
|
|
|
StringBuilder message = new StringBuilder(); |
|
|
|
message.Append('\u2550' * 8); |
|
|
|
message.Append( |
|
|
|
// Currently the Cupertino library only provides english localizations.
|
|
|
|
// Remove this when https://github.com/flutter/flutter/issues/23847
|
|
|
|
// is fixed.
|
|
|
|
|
|
|
|
message.writeln( |
|
|
|
message.Append( |
|
|
|
message.writeln( |
|
|
|
message.Append( |
|
|
|
message.writeln('\u2550' * 8); |
|
|
|
//Debug.Log(message.toString());
|
|
|
|
message.Append('\u2550' * 8); |
|
|
|
|
|
|
|
}*/ |
|
|
|
} |
|
|
|
|
|
|
|
public override Widget build(BuildContext context) { |
|
|
|
Widget navigator = null; |
|
|
|
|
|
|
key: _navigator, |
|
|
|
initialRoute: widget.initialRoute ?? Navigator.defaultRouteName, |
|
|
|
/*WidgetsBinding.instance.window.defaultRouteName != Navigator.defaultRouteName |
|
|
|
initialRoute: |
|
|
|
WidgetsBinding.instance.window.defaultRouteName != Navigator.defaultRouteName |
|
|
|
: widget.initialRoute ?? WidgetsBinding.instance.window.defaultRouteName,*/ |
|
|
|
: widget.initialRoute ?? WidgetsBinding.instance.window.defaultRouteName, |
|
|
|
onGenerateRoute: _onGenerateRoute, |
|
|
|
onGenerateInitialRoutes: widget.onGenerateInitialRoutes == null |
|
|
|
? Navigator.defaultGenerateInitialRoutes |
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
PerformanceOverlay performanceOverlay = null; |
|
|
|
if (widget.showPerformanceOverlay) { |
|
|
|
performanceOverlay = PerformanceOverlay.allEnabled(); |
|
|
|
} |
|
|
|
/*if (widget.showPerformanceOverlay || WidgetsApp.showPerformanceOverlayOverride) { |
|
|
|
|
|
|
|
if (widget.showPerformanceOverlay || WidgetsApp.showPerformanceOverlayOverride) { |
|
|
|
performanceOverlay = PerformanceOverlay.allEnabled( |
|
|
|
checkerboardRasterCacheImages: widget.checkerboardRasterCacheImages, |
|
|
|
checkerboardOffscreenLayers: widget.checkerboardOffscreenLayers |
|
|
|
|
|
|
checkerboardRasterCacheImages: widget.checkerboardRasterCacheImages, |
|
|
|
checkerboardOffscreenLayers: widget.checkerboardOffscreenLayers |
|
|
|
); |
|
|
|
}*/ |
|
|
|
} |
|
|
|
|
|
|
|
if (performanceOverlay != null) { |
|
|
|
result = new Stack( |
|
|
|
|
|
|
}); |
|
|
|
} |
|
|
|
|
|
|
|
/*if (widget.showSemanticsDebugger) { |
|
|
|
result = SemanticsDebugger( |
|
|
|
child: result, |
|
|
|
); |
|
|
|
}*/ |
|
|
|
D.assert(() => { |
|
|
|
if (widget.debugShowWidgetInspector || WidgetsApp.debugShowWidgetInspectorOverride) { |
|
|
|
result = new WidgetInspector( |
|
|
|
|
|
|
); |
|
|
|
} |
|
|
|
return true; |
|
|
|
|
|
|
|
/*if (widget.debugShowWidgetInspector || WidgetsApp.debugShowWidgetInspectorOverride) { |
|
|
|
result = new WidgetInspector( |
|
|
|
child: result, |
|
|
|
selectButtonBuilder: widget.inspectorSelectButtonBuilder |
|
|
|
); |
|
|
|
} |
|
|
|
if (widget.debugShowCheckedModeBanner && WidgetsApp.debugAllowBannerOverride) { |
|
|
|
result = new CheckedModeBanner( |
|
|
|
child: result |
|
|
|
); |
|
|
|
}*/ |
|
|
|
return true; |
|
|
|
result = new Directionality(child: result, TextDirection.ltr); |
|
|
|
result = new WindowProvider( |
|
|
|
window: widget.window, |
|
|
|
child: result |
|
|
|
); |
|
|
|
/*Widget title = null; |
|
|
|
Widget title = null; |
|
|
|
if (widget.onGenerateTitle != null) { |
|
|
|
title = new Builder( |
|
|
|
builder: (BuildContext context1)=> { |
|
|
|
|
|
|
color: widget.color, |
|
|
|
child: result |
|
|
|
); |
|
|
|
}*/ |
|
|
|
} |
|
|
|
//D.assert(_debugCheckLocalizations(appLocale));
|
|
|
|
result = new MediaQuery( |
|
|
|
data: MediaQueryData.fromWindow(widget.window), |
|
|
|
child: new Localizations( |
|
|
|
locale: appLocale, |
|
|
|
delegates: _localizationsDelegates, |
|
|
|
child: result) |
|
|
|
); |
|
|
|
/////todo
|
|
|
|
///
|
|
|
|
/*result = new Shortcuts( |
|
|
|
D.assert(_debugCheckLocalizations(appLocale)); |
|
|
|
|
|
|
|
result = new Shortcuts( |
|
|
|
child: FocusTraversalGroup( |
|
|
|
policy: ReadingOrderTraversalPolicy(), |
|
|
|
child: _MediaQueryFromWindow( |
|
|
|
child: new FocusTraversalGroup( |
|
|
|
policy: new ReadingOrderTraversalPolicy(), |
|
|
|
child: new _MediaQueryFromWindow( |
|
|
|
delegates: _localizationsDelegates, |
|
|
|
delegates: _localizationsDelegates.ToList(), |
|
|
|
);*/ |
|
|
|
); |
|
|
|
|
|
|
|
return result; |
|
|
|
} |
|
|
|