guanghuispark
3 年前
当前提交
ead80815
共有 13 个文件被更改,包括 971 次插入 和 284 次删除
-
16com.unity.uiwidgets.devtools/Editor/v2/dependencies/nested/nested.cs
-
315com.unity.uiwidgets.devtools/Editor/v2/dependencies/provider/inherited_provider.cs
-
128com.unity.uiwidgets.devtools/Editor/v2/dependencies/provider/provider.cs
-
443com.unity.uiwidgets.devtools/Editor/v2/src/app.cs
-
47com.unity.uiwidgets.devtools/Editor/v2/src/inspector/inspector_screen.cs
-
2com.unity.uiwidgets.devtools/Editor/v2/src/screen.cs
-
43com.unity.uiwidgets.devtools/Editor/v2/src/snapshot_screen.cs
-
17com.unity.uiwidgets.devtools/Editor/v2/src/split.cs
-
12com.unity.uiwidgets.devtools/Editor/v2/dependencies/nested/nested.mixin.gen.cs
-
15com.unity.uiwidgets.devtools/Editor/v2/dependencies/nested/nested.mixin.njk
-
57com.unity.uiwidgets.devtools/Editor/v2/src/banner_messages.cs
-
51com.unity.uiwidgets.devtools/Editor/v2/src/initializer.cs
-
109com.unity.uiwidgets.devtools/Editor/v2/src/scaffold.cs
|
|||
using System; |
|||
using System.Collections.Generic; |
|||
using Unity.UIWidgets.foundation; |
|||
using Unity.UIWidgets.rendering; |
|||
delegate bool UpdateShouldNotify<T>(T previous, T current); |
|||
public delegate bool UpdateShouldNotify<T>(T previous, T current); |
|||
delegate T Create<T>(BuildContext context); |
|||
public delegate T Create<T>(BuildContext context); |
|||
delegate void Dispose<T>(BuildContext context, T value); |
|||
public delegate T Update<T>(BuildContext context, T value); |
|||
public delegate void Dispose<T>(BuildContext context, T value); |
|||
// delegate VoidCallback StartListening<T>(InheritedContext<T> element, T value);
|
|||
public delegate void DebugCheckInvalidValueType<T>(T value); |
|||
public delegate VoidCallback StartListening<T>(InheritedContext<T> element, T value); |
|||
public InheritedProvider( |
|||
Key key = null, |
|||
Create<T> create = null, |
|||
Update<T> update = null, |
|||
UpdateShouldNotify<T> updateShouldNotify = null, |
|||
DebugCheckInvalidValueType<T> debugCheckInvalidValueType = null, |
|||
StartListening<T> startListening = null, |
|||
Dispose<T> dispose = null, |
|||
TransitionBuilder builder = null, |
|||
bool? lazy = null, |
|||
Widget child = null |
|||
) : |
|||
base(key: key, child: child) |
|||
{ |
|||
_lazy = lazy; |
|||
_delegate = new _CreateInheritedProvider<T>( |
|||
create: create, |
|||
update: update, |
|||
updateShouldNotify: updateShouldNotify, |
|||
debugCheckInvalidValueType: debugCheckInvalidValueType, |
|||
startListening: startListening, |
|||
dispose: dispose |
|||
); |
|||
} |
|||
|
|||
public readonly _Delegate<T> _delegate; |
|||
public readonly bool? _lazy; |
|||
public readonly TransitionBuilder builder; |
|||
|
|||
public InheritedProvider( |
|||
Key key, |
|||
_Delegate<T> _delegate, |
|||
bool lazy, |
|||
TransitionBuilder builder, |
|||
Widget child |
|||
) : |
|||
base(key: key, child: child) |
|||
{ |
|||
_lazy = lazy; |
|||
_delegate = _delegate; |
|||
} |
|||
|
|||
|
|||
|
|||
class _CreateInheritedProvider<T> : _Delegate<T> { |
|||
public _CreateInheritedProvider( |
|||
Create<T> create, |
|||
Update<T> update, |
|||
UpdateShouldNotify<T> updateShouldNotify = null, |
|||
DebugCheckInvalidValueType<T> debugCheckInvalidValueType = null, |
|||
StartListening<T> startListening = null, |
|||
Dispose<T> dispose = null |
|||
) |
|||
{ |
|||
D.assert(create != null || update != null); |
|||
this.create = create; |
|||
this.update = update; |
|||
_updateShouldNotify = updateShouldNotify; |
|||
this.debugCheckInvalidValueType = debugCheckInvalidValueType; |
|||
this.startListening = startListening; |
|||
this.dispose = dispose; |
|||
} |
|||
|
|||
public readonly Create<T> create; |
|||
public readonly Update<T> update; |
|||
public readonly UpdateShouldNotify<T> _updateShouldNotify; |
|||
public readonly DebugCheckInvalidValueType<T> debugCheckInvalidValueType; |
|||
public readonly StartListening<T> startListening; |
|||
public readonly Dispose<T> dispose; |
|||
|
|||
|
|||
public override _DelegateState<T, _Delegate<T>> createState() |
|||
{ |
|||
throw new System.NotImplementedException(); |
|||
} |
|||
} |
|||
|
|||
|
|||
public abstract class _Delegate<T> { |
|||
public abstract _DelegateState<T, _Delegate<T>> createState(); |
|||
|
|||
void debugFillProperties(DiagnosticPropertiesBuilder properties) {} |
|||
} |
|||
|
|||
public abstract class _DelegateState<T, D> where D : _Delegate<T>{ |
|||
_InheritedProviderScopeElement<T> element; |
|||
|
|||
public T value |
|||
{ |
|||
get; |
|||
} |
|||
|
|||
D _delegate |
|||
{ |
|||
get |
|||
{ |
|||
return element.widget.owner._delegate as D; |
|||
} |
|||
} |
|||
|
|||
private bool hasValue |
|||
{ |
|||
get; |
|||
} |
|||
|
|||
bool debugSetInheritedLock(bool value) { |
|||
return element._debugSetInheritedLock(value); |
|||
} |
|||
|
|||
bool willUpdateDelegate(D newDelegate) => false; |
|||
|
|||
void dispose() {} |
|||
|
|||
void debugFillProperties(DiagnosticPropertiesBuilder properties) {} |
|||
|
|||
void build(bool isBuildFromExternalSources) {} |
|||
} |
|||
|
|||
class _InheritedProviderScopeElement<T> : InheritedElement |
|||
{ |
|||
public _InheritedProviderScopeElement(Widget widget) : base(widget) |
|||
{ |
|||
} |
|||
|
|||
bool _debugInheritLocked = false; |
|||
_DelegateState<T, _Delegate<T>> _delegateState; |
|||
|
|||
public new _InheritedProviderScope<T> widget |
|||
{ |
|||
get |
|||
{ |
|||
return base.widget as _InheritedProviderScope<T>; |
|||
} |
|||
} |
|||
|
|||
public bool _debugSetInheritedLock(bool value) { |
|||
D.assert(() => { |
|||
_debugInheritLocked = value; |
|||
return true; |
|||
}); |
|||
return true; |
|||
} |
|||
|
|||
public new T value |
|||
{ |
|||
get |
|||
{ |
|||
return _delegateState.value; |
|||
} |
|||
} |
|||
|
|||
} |
|||
|
|||
class _InheritedProviderScope<T> : InheritedWidget { |
|||
public _InheritedProviderScope( |
|||
InheritedProvider<T> owner = null, |
|||
Widget child = null |
|||
) : base(child: child) |
|||
{ |
|||
this.owner = owner; |
|||
} |
|||
|
|||
public readonly InheritedProvider<T> owner; |
|||
|
|||
public override bool updateShouldNotify(InheritedWidget oldWidget) { |
|||
return false; |
|||
} |
|||
public override Element createElement() { |
|||
return new _InheritedProviderScopeElement<T>(this); |
|||
} |
|||
} |
|||
|
|||
public abstract class InheritedContext<T> : BuildContext { |
|||
/// The current value exposed by [InheritedProvider].
|
|||
///
|
|||
/// This property is lazy loaded, and reading it the first time may trigger
|
|||
/// some side-effects such as creating a [T] instance or start a subscription.
|
|||
private T value { get; } |
|||
|
|||
/// Marks the [InheritedProvider] as needing to update dependents.
|
|||
///
|
|||
/// This bypass [InheritedWidget.updateShouldNotify] and will force widgets
|
|||
/// that depends on [T] to rebuild.
|
|||
void markNeedsNotifyDependents(){} |
|||
|
|||
/// Wether `setState` was called at least once or not.
|
|||
///
|
|||
/// It can be used by [DeferredStartListening] to differentiate between the
|
|||
/// very first listening, and a rebuild after `controller` changed.
|
|||
private bool hasValue { get; } |
|||
|
|||
public Widget widget { get; } |
|||
public BuildOwner owner { get; } |
|||
public bool debugDoingBuild { get; } |
|||
public RenderObject findRenderObject() |
|||
{ |
|||
throw new NotImplementedException(); |
|||
} |
|||
|
|||
public Size size { get; } |
|||
public InheritedWidget inheritFromElement(InheritedElement ancestor, object aspect = null) |
|||
{ |
|||
throw new NotImplementedException(); |
|||
} |
|||
|
|||
public InheritedWidget dependOnInheritedElement(InheritedElement ancestor, object aspect = null) |
|||
{ |
|||
throw new NotImplementedException(); |
|||
} |
|||
|
|||
public InheritedWidget inheritFromWidgetOfExactType(Type targetType, object aspect = null) |
|||
{ |
|||
throw new NotImplementedException(); |
|||
} |
|||
|
|||
public T1 dependOnInheritedWidgetOfExactType<T1>(object aspect = null) where T1 : InheritedWidget |
|||
{ |
|||
throw new NotImplementedException(); |
|||
} |
|||
|
|||
public InheritedElement ancestorInheritedElementForWidgetOfExactType(Type targetType) |
|||
{ |
|||
throw new NotImplementedException(); |
|||
} |
|||
|
|||
public InheritedElement getElementForInheritedWidgetOfExactType<T1>() where T1 : InheritedWidget |
|||
{ |
|||
throw new NotImplementedException(); |
|||
} |
|||
|
|||
public Widget ancestorWidgetOfExactType(Type targetType) |
|||
{ |
|||
throw new NotImplementedException(); |
|||
} |
|||
|
|||
public T1 findAncestorWidgetOfExactType<T1>() where T1 : Widget |
|||
{ |
|||
throw new NotImplementedException(); |
|||
} |
|||
|
|||
public State ancestorStateOfType(TypeMatcher matcher) |
|||
{ |
|||
throw new NotImplementedException(); |
|||
} |
|||
|
|||
public T1 findAncestorStateOfType<T1>() where T1 : State |
|||
{ |
|||
throw new NotImplementedException(); |
|||
} |
|||
|
|||
public State rootAncestorStateOfType(TypeMatcher matcher) |
|||
{ |
|||
throw new NotImplementedException(); |
|||
} |
|||
|
|||
public T1 findRootAncestorStateOfType<T1>() where T1 : State |
|||
{ |
|||
throw new NotImplementedException(); |
|||
} |
|||
|
|||
public RenderObject ancestorRenderObjectOfType(TypeMatcher matcher) |
|||
{ |
|||
throw new NotImplementedException(); |
|||
} |
|||
|
|||
public T1 findAncestorRenderObjectOfType<T1>() where T1 : RenderObject |
|||
{ |
|||
throw new NotImplementedException(); |
|||
} |
|||
|
|||
public void visitAncestorElements(ElementVisitorBool visitor) |
|||
{ |
|||
throw new NotImplementedException(); |
|||
} |
|||
|
|||
public void visitChildElements(ElementVisitor visitor) |
|||
{ |
|||
throw new NotImplementedException(); |
|||
} |
|||
|
|||
public DiagnosticsNode describeElement(string name, DiagnosticsTreeStyle style = DiagnosticsTreeStyle.errorProperty) |
|||
{ |
|||
throw new NotImplementedException(); |
|||
} |
|||
|
|||
public DiagnosticsNode describeWidget(string name, DiagnosticsTreeStyle style = DiagnosticsTreeStyle.errorProperty) |
|||
{ |
|||
throw new NotImplementedException(); |
|||
} |
|||
|
|||
public List<DiagnosticsNode> describeMissingAncestor(Type expectedAncestorType) |
|||
{ |
|||
throw new NotImplementedException(); |
|||
} |
|||
|
|||
public DiagnosticsNode describeOwnershipChain(string name) |
|||
{ |
|||
throw new NotImplementedException(); |
|||
} |
|||
} |
|||
|
|||
} |
|
|||
|
|||
using System.Collections.Generic; |
|||
using Unity.UIWidgets.foundation; |
|||
using Unity.UIWidgets.widgets; |
|||
using UnityEditor.VersionControl; |
|||
using UnityEngine; |
|||
|
|||
public class Privoder<T> : InheritedProvider<T> |
|||
public class Provider<T> : InheritedProvider<T> |
|||
public Provider( |
|||
Key key = null, |
|||
Create<T> create = null, |
|||
Dispose<T> dispose = null, |
|||
bool? lazy = null, |
|||
TransitionBuilder builder = null, |
|||
Widget child = null |
|||
) : |
|||
base( |
|||
key: key, |
|||
lazy: lazy, |
|||
builder: builder, |
|||
create: create, |
|||
dispose: dispose, |
|||
debugCheckInvalidValueType: null, |
|||
child: child |
|||
) |
|||
{ |
|||
D.assert(create != null); |
|||
} |
|||
|
|||
public static T of<T>(BuildContext context, bool listen = true) { |
|||
D.assert(context != null); |
|||
// D.assert(
|
|||
// context.owner.debugBuilding ||
|
|||
// listen == false ||
|
|||
// debugIsInInheritedProviderUpdate,
|
|||
// @"
|
|||
// Tried to listen to a value exposed with provider, from outside of the widget tree.
|
|||
//
|
|||
// This is likely caused by an event handler (like a button's onPressed) that called
|
|||
// Provider.of without passing `listen: false`.
|
|||
//
|
|||
// To fix, write:
|
|||
// Provider.of<$T>(context, listen: false);
|
|||
//
|
|||
// It is unsupported because may pointlessly rebuild the widget associated to the
|
|||
// event handler, when the widget tree doesn't care about the value.
|
|||
//
|
|||
// The context used was: $context
|
|||
// "
|
|||
// );
|
|||
|
|||
var inheritedElement = _inheritedElementOf<T>(context); |
|||
|
|||
if (listen) { |
|||
context.dependOnInheritedElement(inheritedElement); |
|||
} |
|||
|
|||
return inheritedElement.value; |
|||
} |
|||
|
|||
static _InheritedProviderScopeElement<T> _inheritedElementOf<T>( |
|||
BuildContext context |
|||
) { |
|||
D.assert(context != null, ()=> @"
|
|||
Tried to call context.read/watch/select or similar on a `context` that is null. |
|||
|
|||
This can happen if you used the context of a StatefulWidget and that |
|||
StatefulWidget was disposed. |
|||
");
|
|||
// D.assert(
|
|||
// _debugIsSelecting == false,
|
|||
// 'Cannot call context.read/watch/select inside the callback of a context.select'
|
|||
// );
|
|||
// assert(
|
|||
// T != dynamic,
|
|||
// '''
|
|||
// Tried to call Provider.of<dynamic>. This is likely a mistake and is therefore
|
|||
// unsupported.
|
|||
//
|
|||
// If you want to expose a variable that can be anything, consider changing
|
|||
// `dynamic` to `Object` instead.
|
|||
// ''',
|
|||
// );
|
|||
_InheritedProviderScopeElement<T> inheritedElement = null; |
|||
|
|||
if (context.widget is _InheritedProviderScope<T>) { |
|||
// An InheritedProvider<T>'s update tries to obtain a parent provider of
|
|||
// the same type.
|
|||
context.visitAncestorElements((parent) => { |
|||
inheritedElement = parent.getElementForInheritedWidgetOfExactType< |
|||
_InheritedProviderScope<T>>() as _InheritedProviderScopeElement<T>; |
|||
return false; |
|||
}); |
|||
} else { |
|||
inheritedElement = context.getElementForInheritedWidgetOfExactType< |
|||
_InheritedProviderScope<T>>() as _InheritedProviderScopeElement<T>; |
|||
} |
|||
|
|||
if (inheritedElement == null) { |
|||
Debug.Log("error:" + context.widget.GetType()); |
|||
} |
|||
|
|||
return inheritedElement; |
|||
} |
|||
|
|||
} |
|||
|
|||
public class MultiProvider : Nested |
|||
{ |
|||
public MultiProvider( |
|||
Key key = null, |
|||
List<SingleChildWidgetMixinStatelessWidget> providers = null, |
|||
Widget child = null, |
|||
TransitionBuilder builder = null |
|||
) : |
|||
base( |
|||
key: key, |
|||
children: providers, |
|||
child: builder != null |
|||
? new Builder( |
|||
builder: (context) => builder(context, child) |
|||
) |
|||
: child |
|||
) |
|||
{ |
|||
D.assert(providers != null); |
|||
} |
|||
} |
|||
} |
|
|||
using System; |
|||
using System.Collections.Generic; |
|||
using System.Linq; |
|||
using Unity.UIWidgets.ui; |
|||
using UnityEngine; |
|||
static class AppUtils |
|||
{ |
|||
public static string homeRoute = "/"; |
|||
public static string snapshotRoute = "/snapshot"; |
|||
|
|||
public static List<DevToolsScreen<object>> defaultScreens { |
|||
get |
|||
{ |
|||
return new List<DevToolsScreen<object>> |
|||
{ |
|||
new DevToolsScreen<object>( |
|||
new InspectorScreen(), |
|||
createController: null |
|||
) |
|||
}; |
|||
} |
|||
} |
|||
} |
|||
|
|||
|
|||
class DevToolsApp : StatefulWidget { |
|||
public DevToolsApp(List<DevToolsScreen<object>> screens, PreferencesController preferences) |
|||
{ |
|||
this.screens = screens; |
|||
this.preferences = preferences; |
|||
} |
|||
|
|||
public delegate Widget UrlParametersBuilder(BuildContext buildContext, Dictionary<string, string> dictionary, |
|||
SnapshotArguments args); |
|||
|
|||
static class AppUtils |
|||
{ |
|||
public static string homeRoute = "/"; |
|||
public static string snapshotRoute = "/snapshot"; |
|||
|
|||
public static List<DevToolsScreen<object>> defaultScreens |
|||
{ |
|||
get |
|||
{ |
|||
return new List<DevToolsScreen<object>> |
|||
{ |
|||
new DevToolsScreen<object>( |
|||
screen: new InspectorScreen(), |
|||
createController: null |
|||
) |
|||
}; |
|||
} |
|||
} |
|||
} |
|||
|
|||
|
|||
class DevToolsApp : StatefulWidget |
|||
{ |
|||
public DevToolsApp(List<DevToolsScreen<object>> screens, PreferencesController preferences) |
|||
{ |
|||
this.screens = screens; |
|||
this.preferences = preferences; |
|||
} |
|||
public readonly List<DevToolsScreen<object>> screens; |
|||
public readonly PreferencesController preferences; |
|||
public readonly List<DevToolsScreen<object>> screens; |
|||
public readonly PreferencesController preferences; |
|||
public override State createState() => new DevToolsAppState(); |
|||
public override State createState() => new DevToolsAppState(); |
|||
public static DevToolsAppState of(BuildContext context) { |
|||
public static DevToolsAppState of(BuildContext context) |
|||
{ |
|||
} |
|||
} |
|||
|
|||
class DevToolsAppState : State<DevToolsApp> |
|||
{ |
|||
List<Screen> _screens |
|||
{ |
|||
get |
|||
{ |
|||
List<Screen> screensList = new List<Screen>(); |
|||
foreach (var screen in widget.screens) |
|||
{ |
|||
screensList.Add(screen.screen); |
|||
} |
|||
|
|||
return screensList; |
|||
} |
|||
} |
|||
class DevToolsAppState : State<DevToolsApp> { |
|||
|
|||
|
|||
Route _generateRoute(RouteSettings settings) |
|||
{ |
|||
return new MaterialPageRoute( |
|||
settings: settings, |
|||
builder: (BuildContext context2) => { return new Container(); }); |
|||
} |
|||
|
|||
public override Widget build(BuildContext context) |
|||
{ |
|||
return new ValueListenableBuilder<bool>( |
|||
valueListenable: widget.preferences.darkModeTheme, |
|||
builder: (subContext, value, _) => { |
|||
return new MaterialApp( |
|||
debugShowCheckedModeBanner: false, |
|||
theme: ThemeUtils.themeFor(isDarkTheme: true), |
|||
builder: (subsubContext, child) => new Notifications(child: child), |
|||
onGenerateRoute: _generateRoute |
|||
); |
|||
} |
|||
); |
|||
} |
|||
} |
|||
Route _generateRoute(RouteSettings settings) |
|||
{ |
|||
// var uri = new Uri(settings.name);
|
|||
// var path = uri.PathAndQuery.isEmpty() ? AppUtils.homeRoute : uri.PathAndQuery;
|
|||
var args = (SnapshotArguments) settings.arguments; |
|||
|
|||
var path = AppUtils.snapshotRoute; |
|||
|
|||
// Provide the appropriate page route.
|
|||
if (routes.ContainsKey(path)) |
|||
{ |
|||
WidgetBuilder builder = (context2) => routes[path]( |
|||
context2, |
|||
null, |
|||
args |
|||
); |
|||
D.assert(() => |
|||
{ |
|||
// builder = (context2) => _AlternateCheckedModeBanner(
|
|||
// builder: (context3) => routes[path](
|
|||
// context3,
|
|||
// null,
|
|||
// args
|
|||
// )
|
|||
// );
|
|||
return true; |
|||
}); |
|||
return new MaterialPageRoute(settings: settings, builder: builder); |
|||
} |
|||
|
|||
return new MaterialPageRoute( |
|||
settings: settings, |
|||
builder: (BuildContext context) => { |
|||
return DevToolsScaffold.withChild( |
|||
child: new Container() |
|||
); |
|||
} |
|||
); |
|||
|
|||
|
|||
|
|||
} |
|||
|
|||
Dictionary<string, UrlParametersBuilder> routes |
|||
{ |
|||
|
|||
get |
|||
{ |
|||
if (_routes != null) |
|||
{ |
|||
return _routes; |
|||
} |
|||
|
|||
Dictionary<string, UrlParametersBuilder> builders = new Dictionary<string, UrlParametersBuilder>(); |
|||
builders.Add(AppUtils.homeRoute, (_, _params, __) => |
|||
{ |
|||
if (_params.ContainsKey("uri")) |
|||
{ |
|||
var embed = _params["embed"] == "true"; |
|||
var page = _params["page"]; |
|||
return new Initializer( |
|||
url: _params["uri"].ToString(), |
|||
allowConnectionScreenOnDisconnect: !embed, |
|||
builder: null |
|||
); |
|||
} |
|||
|
|||
// return DevToolsScaffold.withChild(child: ConnectScreenBody());
|
|||
return new Container(child: new Text("this is a text!")); |
|||
}); |
|||
builders.Add(AppUtils.snapshotRoute, (_, __, args) => |
|||
{ |
|||
return DevToolsScaffold.withChild( |
|||
child: _providedControllers( |
|||
offline: true, |
|||
child: new SnapshotScreenBody(args, _screens) |
|||
) |
|||
); |
|||
}); |
|||
|
|||
return builders; |
|||
} |
|||
|
|||
} |
|||
|
|||
Dictionary<string, UrlParametersBuilder> _routes; |
|||
|
|||
Widget _providedControllers(Widget child = null, bool offline = false) |
|||
{ |
|||
List<SingleChildWidgetMixinStatelessWidget> _providers = new List<SingleChildWidgetMixinStatelessWidget>(); |
|||
foreach (var screen in widget.screens) |
|||
{ |
|||
if (screen.createController != null) |
|||
{ |
|||
_providers.Add((SingleChildWidgetMixinStatelessWidget)screen.controllerProvider); |
|||
} |
|||
} |
|||
|
|||
return new MultiProvider( |
|||
providers: _providers, |
|||
child: child |
|||
); |
|||
} |
|||
|
|||
|
|||
|
|||
public override Widget build(BuildContext context) |
|||
{ |
|||
return new ValueListenableBuilder<bool>( |
|||
valueListenable: widget.preferences.darkModeTheme, |
|||
builder: (subContext, value, _) => |
|||
{ |
|||
return new MaterialApp( |
|||
debugShowCheckedModeBanner: false, |
|||
theme: ThemeUtils.themeFor(isDarkTheme: true), |
|||
builder: (subsubContext, child) => new Notifications(child: child), |
|||
onGenerateRoute: _generateRoute |
|||
); |
|||
} |
|||
); |
|||
} |
|||
} |
|||
|
|||
|
|||
|
|||
class DevToolsScreen<C> |
|||
{ |
|||
public DevToolsScreen( |
|||
Screen screen, |
|||
Func<C> createController, |
|||
bool supportsOffline = false |
|||
) |
|||
{ |
|||
this.screen = screen; |
|||
this.createController = createController; |
|||
this.supportsOffline = supportsOffline; |
|||
} |
|||
public readonly Screen screen; |
|||
// class DevToolsAppState : State<DevToolsApp> {
|
|||
// List<Screen> _screens => widget.screens.Select(s => s.screen).ToList();
|
|||
//
|
|||
// PreferencesController preferences => widget.preferences;
|
|||
//
|
|||
// public override void initState() {
|
|||
// base.initState();
|
|||
//
|
|||
// Globals.serviceManager.isolateManager.onSelectedIsolateChanged.listen((_) => {
|
|||
// setState(() => {
|
|||
// _clearCachedRoutes();
|
|||
// });
|
|||
// });
|
|||
// }
|
|||
//
|
|||
// public override void didUpdateWidget(StatefulWidget oldWidget) {
|
|||
// base.didUpdateWidget(oldWidget);
|
|||
// _clearCachedRoutes();
|
|||
// }
|
|||
//
|
|||
// /// Generates routes, separating the path from URL query parameters.
|
|||
// Route _generateRoute(RouteSettings settings) {
|
|||
// var uri = settings.name;
|
|||
// var path = uri.isEmpty() ? AppUtils.homeRoute : uri;
|
|||
// var args = settings.arguments as SnapshotArguments;
|
|||
//
|
|||
// // Provide the appropriate page route.
|
|||
// if (routes.ContainsKey(path)) {
|
|||
// WidgetBuilder builder = (context) => routes[path](
|
|||
// context,
|
|||
// uri.queryParameters,
|
|||
// args
|
|||
// );
|
|||
// D.assert(() => {
|
|||
// builder = (context) => new _AlternateCheckedModeBanner(
|
|||
// builder: (subContext) => routes[path](
|
|||
// subContext,
|
|||
// uri.queryParameters,
|
|||
// args
|
|||
// )
|
|||
// );
|
|||
// return true;
|
|||
// }());
|
|||
//
|
|||
// return new MaterialPageRoute(settings: settings, builder: builder);
|
|||
// }
|
|||
//
|
|||
// // Return a page not found.
|
|||
// return new MaterialPageRoute(
|
|||
// settings: settings,
|
|||
// builder: (BuildContext context) => {
|
|||
// return DevToolsScaffold.withChild(
|
|||
// child: new CenteredMessage("'$uri' not found.")
|
|||
// );
|
|||
// }
|
|||
// );
|
|||
// }
|
|||
//
|
|||
// /// The routes that the app exposes.
|
|||
// Dictionary<string, UrlParametersBuilder> routes => {
|
|||
// _routes = _routes ?? new Dictionary<string, UrlParametersBuilder>(){
|
|||
// {AppUtils.homeRoute, (_, buildParam, __) => {
|
|||
// if (buildParam.getOrDefault("uri")?.isNotEmpty() ?? false) {
|
|||
// var embed = buildParam["embed"] == "true";
|
|||
// var page = buildParam["page"];
|
|||
// var tabs = embed && page != null
|
|||
// ? _visibleScreens().Where((p) => p.screenId == page)
|
|||
// : _visibleScreens();
|
|||
// return new Initializer(
|
|||
// url: buildParam["uri"],
|
|||
// allowConnectionScreenOnDisconnect: !embed,
|
|||
// builder: (_) => _providedControllers(
|
|||
// child: new DevToolsScaffold(
|
|||
// embed: embed,
|
|||
// initialPage: page,
|
|||
// tabs: tabs,
|
|||
// actions: [
|
|||
// if (serviceManager.connectedApp.isFlutterAppNow) ...[
|
|||
// HotReloadButton(),
|
|||
// HotRestartButton(),
|
|||
// ],
|
|||
// OpenSettingsAction(),
|
|||
// OpenAboutAction(),
|
|||
// ],
|
|||
// ),
|
|||
// ),
|
|||
// );
|
|||
// } else {
|
|||
// return DevToolsScaffold.withChild(child: ConnectScreenBody());
|
|||
// }
|
|||
// },
|
|||
// snapshotRoute: (_, __, args) => {
|
|||
// return DevToolsScaffold.withChild(
|
|||
// child: _providedControllers(
|
|||
// offline: true,
|
|||
// child: SnapshotScreenBody(args, _screens),
|
|||
// ),
|
|||
// );
|
|||
// },
|
|||
// }};
|
|||
//
|
|||
// return _routes;
|
|||
// }
|
|||
//
|
|||
// Dictionary<string, UrlParametersBuilder> _routes;
|
|||
//
|
|||
// void _clearCachedRoutes() {
|
|||
// _routes = null;
|
|||
// }
|
|||
//
|
|||
// List<Screen> _visibleScreens() {
|
|||
// var visibleScreens = new List<Screen>();
|
|||
// foreach (var screen in _screens) {
|
|||
// if (screen.conditionalLibrary != null) {
|
|||
// if (Globals.serviceManager.isServiceAvailable &&
|
|||
// Globals.serviceManager
|
|||
// .isolateManager.selectedIsolateAvailable.isCompleted &&
|
|||
// Globals.serviceManager.libraryUriAvailableNow(screen.conditionalLibrary)) {
|
|||
// visibleScreens.Add(screen);
|
|||
// }
|
|||
// } else {
|
|||
// visibleScreens.Add(screen);
|
|||
// }
|
|||
// }
|
|||
// return visibleScreens;
|
|||
// }
|
|||
//
|
|||
// Widget _providedControllers(Widget child, bool offline = false)
|
|||
// {
|
|||
// var _providers = widget.screens
|
|||
// .Where((s) =>
|
|||
// s.createController != null && (offline ? s.supportsOffline : true))
|
|||
// .Select((s) => s.controllerProvider);
|
|||
//
|
|||
// return new MultiProvider(
|
|||
// providers: _providers,
|
|||
// child: child
|
|||
// );
|
|||
// }
|
|||
//
|
|||
// public override Widget build(BuildContext context) {
|
|||
// return new ValueListenableBuilder<bool>(
|
|||
// valueListenable: widget.preferences.darkModeTheme,
|
|||
// builder: (subContext, value, _) => {
|
|||
// return new MaterialApp(
|
|||
// debugShowCheckedModeBanner: false,
|
|||
// theme: ThemeUtils.themeFor(isDarkTheme: value),
|
|||
// builder: (subsubContext, child) => new Notifications(child: child),
|
|||
// onGenerateRoute: _generateRoute
|
|||
// );
|
|||
// }
|
|||
// );
|
|||
// }
|
|||
// }
|
|||
//
|
|||
class DevToolsScreen<C> { |
|||
public DevToolsScreen( |
|||
Screen screen, |
|||
Func<C> createController, |
|||
bool supportsOffline = false |
|||
) |
|||
{ |
|||
this.screen = screen; |
|||
this.createController = createController; |
|||
this.supportsOffline = supportsOffline; |
|||
} |
|||
public readonly Func<C> createController; |
|||
public readonly Screen screen; |
|||
|
|||
public readonly Func<C> createController; |
|||
|
|||
public readonly bool supportsOffline; |
|||
public readonly bool supportsOffline; |
|||
public Provider<C> controllerProvider { |
|||
get |
|||
{ |
|||
D.assert(createController != null); |
|||
return new Provider<C>(create: (_) => createController()); |
|||
} |
|||
|
|||
} |
|||
// internal Provider<C> controllerProvider => {
|
|||
// D.assert(createController != null);
|
|||
// return new Provider<C>(create: (_) => createController());
|
|||
// }
|
|||
} |
|||
// public delegate Widget UrlParametersBuilder(
|
|||
// BuildContext buildContext,
|
|||
// Dictionary<string, string> route,
|
|||
// SnapshotArguments args
|
|||
// );
|
|||
} |
|||
} |
|
|||
using Unity.UIWidgets.widgets; |
|||
using Unity.UIWidgets.foundation; |
|||
|
|||
namespace Unity.UIWidgets.DevTools { |
|||
public abstract class SingleChildWidgetMixinStatelessWidget : StatelessWidget { |
|||
|
|||
public SingleChildWidgetMixinStatelessWidget(Key key = null) : base(key: key){} |
|||
|
|||
public abstract override Element createElement(); |
|||
} |
|||
|
|||
} |
|
|||
using Unity.UIWidgets.widgets; |
|||
using Unity.UIWidgets.foundation; |
|||
|
|||
namespace Unity.UIWidgets.DevTools { |
|||
{% macro SingleChildWidgetMixin(with) %} |
|||
{% set className = 'SingleChildWidgetMixin' + with %} |
|||
public abstract class {{className}} : {{with}} { |
|||
|
|||
public SingleChildWidgetMixin{{with}}(Key key = null) : base(key: key){} |
|||
|
|||
public abstract override Element createElement(); |
|||
} |
|||
{% endmacro %} |
|||
{{ SingleChildWidgetMixin('StatelessWidget') }} |
|||
} |
|
|||
using System.Collections.Generic; |
|||
using Unity.UIWidgets.foundation; |
|||
using Unity.UIWidgets.widgets; |
|||
|
|||
namespace Unity.UIWidgets.DevTools |
|||
{ |
|||
class BannerMessages : StatelessWidget { |
|||
public BannerMessages(Key key = null, Screen screen = null) : base(key: key) |
|||
{ |
|||
this.screen = screen; |
|||
} |
|||
|
|||
public readonly Screen screen; |
|||
|
|||
|
|||
public override Widget build(BuildContext context) |
|||
{ |
|||
return new Container(); |
|||
// var controller = Provider<object>.of<BannerMessagesController>(context);
|
|||
// var messagesForScreen = controller?.messagesForScreen(screen.screenId);
|
|||
// List<Widget> temp = new List<Widget>();
|
|||
// if (messagesForScreen != null)
|
|||
// {
|
|||
// temp.Add(new ValueListenableBuilder<List<BannerMessage>>(
|
|||
// valueListenable: messagesForScreen,
|
|||
// builder: (context2, messages, _) => {
|
|||
// return new Column(
|
|||
// children: messages
|
|||
// );
|
|||
// }
|
|||
// ));
|
|||
// }
|
|||
// temp.Add(new Expanded(
|
|||
// child: screen.build(context)
|
|||
// ));
|
|||
//
|
|||
//
|
|||
// return new Column(
|
|||
// children: temp
|
|||
// );
|
|||
} |
|||
} |
|||
|
|||
// class BannerMessagesController
|
|||
// {
|
|||
// ValueNotifier<List<BannerMessage>> _messagesForScreen(string screenId) {
|
|||
// return _messages.putIfAbsent(
|
|||
// screenId, () => new ValueNotifier<List<BannerMessage>>());
|
|||
// }
|
|||
//
|
|||
// ValueListenable<List<BannerMessage>> messagesForScreen(string screenId) {
|
|||
// return _messagesForScreen(screenId);
|
|||
// }
|
|||
// }
|
|||
|
|||
|
|||
} |
|
|||
using Unity.UIWidgets.foundation; |
|||
using Unity.UIWidgets.material; |
|||
using Unity.UIWidgets.widgets; |
|||
|
|||
namespace Unity.UIWidgets.DevTools |
|||
{ |
|||
class Initializer : StatefulWidget |
|||
{ |
|||
public Initializer( |
|||
Key key = null, |
|||
string url = null, |
|||
WidgetBuilder builder = null, |
|||
bool allowConnectionScreenOnDisconnect = true |
|||
) : base(key: key) |
|||
{ |
|||
D.assert(builder != null); |
|||
this.url = url; |
|||
this.builder = builder; |
|||
this.allowConnectionScreenOnDisconnect = allowConnectionScreenOnDisconnect; |
|||
} |
|||
|
|||
public readonly WidgetBuilder builder; |
|||
|
|||
public readonly string url; |
|||
|
|||
public readonly bool allowConnectionScreenOnDisconnect; |
|||
|
|||
public override State createState() |
|||
{ |
|||
return new _InitializerState(); |
|||
} |
|||
} |
|||
|
|||
class _InitializerState : State<Initializer> |
|||
{ |
|||
public override Widget build(BuildContext context) |
|||
{ |
|||
// return _checkLoaded() && _dependenciesLoaded
|
|||
// ? widget.builder(context)
|
|||
// : new Scaffold(
|
|||
// body: new Center(child: new CircularProgressIndicator())
|
|||
// );
|
|||
return new Scaffold( |
|||
body: new Center(child: new CircularProgressIndicator()) |
|||
); |
|||
} |
|||
} |
|||
|
|||
|
|||
|
|||
} |
|
|||
using System.Collections.Generic; |
|||
using Unity.UIWidgets.DevTools; |
|||
using Unity.UIWidgets.foundation; |
|||
using Unity.UIWidgets.painting; |
|||
using Unity.UIWidgets.widgets; |
|||
|
|||
namespace Unity.UIWidgets.DevTools |
|||
{ |
|||
class DevToolsScaffold : StatefulWidget |
|||
{ |
|||
|
|||
public DevToolsScaffold( |
|||
Key key = null, |
|||
List<Screen> tabs = null, |
|||
string initialPage = null, |
|||
List<Widget> actions = null, |
|||
bool embed = false |
|||
) : |
|||
base(key: key) |
|||
{ |
|||
D.assert(tabs != null); |
|||
} |
|||
|
|||
public static readonly EdgeInsets appPadding = |
|||
EdgeInsets.fromLTRB(16.0f, 16.0f, 16.0f, 8.0f); |
|||
|
|||
public readonly List<Screen> tabs; |
|||
|
|||
public readonly string initialPage; |
|||
|
|||
public readonly bool embed; |
|||
|
|||
public readonly List<Widget> actions; |
|||
|
|||
public override State createState() |
|||
{ |
|||
return new DevToolsScaffoldState(); |
|||
} |
|||
|
|||
public static DevToolsScaffold withChild(Key key = null, Widget child = null) |
|||
{ |
|||
return new DevToolsScaffold(key: key, tabs: new List<Screen>(){new SimpleScreen(child)}); |
|||
} |
|||
} |
|||
|
|||
class DevToolsScaffoldState : State<DevToolsScaffold> |
|||
{ |
|||
public override Widget build(BuildContext context) |
|||
{ |
|||
var tabBodies = new List<Widget>(); |
|||
if (widget.tabs != null) |
|||
{ |
|||
foreach (var screen in widget.tabs) |
|||
{ |
|||
tabBodies.Add(new Container( |
|||
padding: DevToolsScaffold.appPadding, |
|||
alignment: Alignment.topLeft, |
|||
child: new FocusScope( |
|||
child: new BannerMessages( |
|||
screen: screen |
|||
) |
|||
) |
|||
)); |
|||
}; |
|||
} |
|||
|
|||
|
|||
// return ValueListenableProvider.value(
|
|||
// value: _currentScreen,
|
|||
// child: Provider<BannerMessagesController>(
|
|||
// create: (_) => BannerMessagesController(),
|
|||
// child: DragAndDrop(
|
|||
// // TODO(kenz): we are handling drops from multiple scaffolds. We need
|
|||
// // to make sure we are only handling drops from the active scaffold.
|
|||
// handleDrop: _importController.importData,
|
|||
// child: Scaffold(
|
|||
// appBar: widget.embed ? null : _buildAppBar(),
|
|||
// body: TabBarView(
|
|||
// physics: defaultTabBarViewPhysics,
|
|||
// controller: _tabController,
|
|||
// children: tabBodies
|
|||
// ),
|
|||
// bottomNavigationBar:
|
|||
// widget.embed ? null : _buildStatusLine(context)
|
|||
// )
|
|||
// )
|
|||
// )
|
|||
// );
|
|||
return new Container(child:new Text("enter here")); |
|||
} |
|||
} |
|||
|
|||
|
|||
class SimpleScreen : Screen { |
|||
public SimpleScreen(Widget child) : base(id) |
|||
{ |
|||
this.child = child; |
|||
} |
|||
|
|||
public static readonly string id = "simple"; |
|||
|
|||
public readonly Widget child; |
|||
|
|||
public override Widget build(BuildContext context) |
|||
{ |
|||
return child; |
|||
} |
|||
} |
|||
} |
撰写
预览
正在加载...
取消
保存
Reference in new issue