浏览代码

add dependence lib

/zxw-devTools
guanghuispark 3 年前
当前提交
e458cd4f
共有 6 个文件被更改,包括 424 次插入51 次删除
  1. 51
      com.unity.uiwidgets.devtools/Editor/v2/dependencies/provider/inherited_provider.cs
  2. 93
      com.unity.uiwidgets.devtools/Editor/v2/src/banner_messages.cs
  3. 46
      com.unity.uiwidgets.devtools/Editor/v2/src/scaffold.cs
  4. 2
      com.unity.uiwidgets.devtools/Editor/v2/src/theme.cs
  5. 219
      com.unity.uiwidgets.devtools/Editor/v2/dependencies/provider/deferred_inherited_provider.cs
  6. 64
      com.unity.uiwidgets.devtools/Editor/v2/dependencies/provider/value_listenable_provider.cs

51
com.unity.uiwidgets.devtools/Editor/v2/dependencies/provider/inherited_provider.cs


Dispose<T> dispose = null,
TransitionBuilder builder = null,
bool? lazy = null,
Widget child = null
Widget child = null,
_Delegate<T> _delegate = null
_lazy = lazy;
_delegate = new _CreateInheritedProvider<T>(
this._lazy = lazy;
this._delegate = _delegate?? new _CreateInheritedProvider<T>(
create: create,
update: update,
updateShouldNotify: updateShouldNotify,

);
this.builder = builder;
public InheritedProvider(
public InheritedProvider<T> _constructor(
bool lazy,
bool? lazy,
) :
base(key: key, child: child)
)
_lazy = lazy;
_delegate = _delegate;
return new InheritedProvider<T>(key: key, child: child, lazy: lazy, _delegate: _delegate, builder: builder);
throw new System.NotImplementedException();
// D.assert(
// builder != null || child != null,
// () => $"runtimeType used outside of MultiProvider must specify a child"
// );
return new _InheritedProviderScope<T>(
owner: this,
child: builder != null
? new Container(
child:new Builder(
builder: (context2) => builder(context2, child)
)
)
: new Container(child : new Text("child is null"))
);
}
}

Dispose<T> dispose = null
)
{
D.assert(create != null || update != null);
// D.assert(create != null || update != null);
this.create = create;
this.update = update;
_updateShouldNotify = updateShouldNotify;

public abstract class _Delegate<T> {
public abstract _DelegateState<T, _Delegate<T>> createState();
void debugFillProperties(DiagnosticPropertiesBuilder properties) {}
public virtual void debugFillProperties(DiagnosticPropertiesBuilder properties) {}
_InheritedProviderScopeElement<T> element;
public _InheritedProviderScopeElement<T> element;
public T value
{

D _delegate
public D _delegate
{
get
{

return element._debugSetInheritedLock(value);
}
bool willUpdateDelegate(D newDelegate) => false;
public virtual bool willUpdateDelegate(D newDelegate) => false;
void debugFillProperties(DiagnosticPropertiesBuilder properties) {}
public virtual void debugFillProperties(DiagnosticPropertiesBuilder properties) {}
class _InheritedProviderScopeElement<T> : InheritedElement
public class _InheritedProviderScopeElement<T> : InheritedElement
{
public _InheritedProviderScopeElement(Widget widget) : base(widget)
{

}
class _InheritedProviderScope<T> : InheritedWidget {
public class _InheritedProviderScope<T> : InheritedWidget {
public _InheritedProviderScope(
InheritedProvider<T> owner = null,
Widget child = null

93
com.unity.uiwidgets.devtools/Editor/v2/src/banner_messages.cs


using System.Collections.Generic;
using Unity.UIWidgets.foundation;
using Unity.UIWidgets.material;
using Unity.UIWidgets.painting;
using Unity.UIWidgets.rendering;
using Unity.UIWidgets.ui;
using Unity.UIWidgets.widgets;
namespace Unity.UIWidgets.DevTools

// );
}
}
public class BannerMessage : StatelessWidget {
public BannerMessage(
Key key = null,
List<TextSpan> textSpans = null,
Color backgroundColor = null,
Color foregroundColor = null,
string screenId = null,
string headerText = null
) : base(key: key)
{
this.textSpans = textSpans;
this.backgroundColor = backgroundColor;
this.foregroundColor = foregroundColor;
this.screenId = screenId;
this.headerText = headerText;
}
// 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);
// }
// }
public readonly List<TextSpan> textSpans;
public readonly Color backgroundColor;
public readonly Color foregroundColor;
public readonly string screenId;
public readonly string headerText;
public override Widget build(BuildContext context)
{
List<InlineSpan> inlineSpans = new List<InlineSpan>();
foreach (var textSpan in textSpans)
{
inlineSpans.Add(textSpan);
}
return new Card(
color: backgroundColor,
margin: EdgeInsets.only(bottom: ThemeUtils.denseRowSpacing),
child: new Padding(
padding: EdgeInsets.all(ThemeUtils.defaultSpacing),
child: new Column(
mainAxisSize: MainAxisSize.min,
crossAxisAlignment: CrossAxisAlignment.start,
children: new List<Widget>{
new Row(
mainAxisAlignment: MainAxisAlignment.spaceBetween,
children: new List<Widget>{
new Text(
headerText,
style: Theme.of(context)
.textTheme
.headline6
.copyWith(color: foregroundColor)
),
}
),
new SizedBox(height: ThemeUtils.defaultSpacing),
new RichText(
text: new TextSpan(
children: inlineSpans
)
),
}
)
)
);
}
}
class BannerMessagesController
{
Dictionary<string, ValueNotifier<List<BannerMessage>>> _messages = new Dictionary<string, ValueNotifier<List<BannerMessage>>>();
ValueNotifier<List<BannerMessage>> _messagesForScreen(string screenId) {
return _messages.putIfAbsent(
screenId, () => new ValueNotifier<List<BannerMessage>>(null));
}
ValueListenable<List<BannerMessage>> messagesForScreen(string screenId) {
return _messagesForScreen(screenId);
}
}
}

46
com.unity.uiwidgets.devtools/Editor/v2/src/scaffold.cs


using Unity.UIWidgets.DevTools;
using Unity.UIWidgets.foundation;
using Unity.UIWidgets.painting;
using Unity.UIWidgets.ui;
using Unity.UIWidgets.widgets;
namespace Unity.UIWidgets.DevTools

class DevToolsScaffoldState : State<DevToolsScaffold>
{
ValueNotifier<Screen> _currentScreen = new ValueNotifier<Screen>(null);
public override Widget build(BuildContext context)
{
var tabBodies = new List<Widget>();

}
// 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 ValueListenableProvider<Screen>(
value: _currentScreen,
child: new Provider<BannerMessagesController>(
create: (_) => new BannerMessagesController(),
child: new Container(height:100,width:100,color:Color.white)
// 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"));
}
}

2
com.unity.uiwidgets.devtools/Editor/v2/src/theme.cs


public const float defaultIconSize = 16.0f;
public const float buttonMinWidth = 36.0f;
public const float denseRowSpacing = 6.0f;
public const float defaultSpacing = 16.0f;
static ColorSwatch<int> devtoolsGrey = new ColorSwatch<int>(0xFF202124, new Dictionary<int, Color>(){
{900, new Color(0xFF202124)},

219
com.unity.uiwidgets.devtools/Editor/v2/dependencies/provider/deferred_inherited_provider.cs


using Unity.UIWidgets.foundation;
using Unity.UIWidgets.ui;
using Unity.UIWidgets.widgets;
namespace Unity.UIWidgets.DevTools
{
public delegate void SetState<R>(R value);
public delegate VoidCallback DeferredStartListening<T, R>(
InheritedContext<R> context,
SetState<R> setState,
T controller,
R value
);
class DeferredInheritedProvider<T, R> : InheritedProvider<R> {
public DeferredInheritedProvider(
Key key = null,
Create<T> create = null,
Dispose<T> dispose = null,
DeferredStartListening<T, R> startListening = null,
UpdateShouldNotify<R> updateShouldNotify = null,
bool? lazy = null,
TransitionBuilder builder = null,
Widget child = null
)
{
base._constructor(
key: key,
child: child,
lazy: lazy,
builder: builder,
_delegate: new _CreateDeferredInheritedProvider<T,R>(
create: create,
dispose: dispose,
updateShouldNotify: updateShouldNotify,
startListening: startListening
)
);
}
/// Listens to `value` and expose its content to `child` and its descendants.
public DeferredInheritedProvider(
Key key = null,
T value = default,
DeferredStartListening<T, R> startListening = null,
UpdateShouldNotify<R> updateShouldNotify = null,
bool? lazy = null,
TransitionBuilder builder = null,
Widget child = null
)
{
base._constructor(
key: key,
lazy: lazy,
builder: builder,
_delegate: new _ValueDeferredInheritedProvider<T, R>(
value,
updateShouldNotify,
startListening
),
child: child
);
}
}
class _CreateDeferredInheritedProvider<T, R> : _DeferredDelegate<T, R> {
public _CreateDeferredInheritedProvider(
Create<T> create = null,
Dispose<T> dispose = null,
UpdateShouldNotify<R> updateShouldNotify = null,
DeferredStartListening<T, R> startListening = null
) : base(updateShouldNotify, startListening)
{
this.create = create;
this.dispose = dispose;
}
public readonly Create<T> create;
public readonly Dispose<T> dispose;
public _CreateDeferredInheritedProviderElement<T, R> createState() { // [attention] override
return new _CreateDeferredInheritedProviderElement<T, R>();
}
}
class _CreateDeferredInheritedProviderElement<T, R>
: _DeferredDelegateState<T, R, _CreateDeferredInheritedProvider<T, R>>
{
}
public abstract class _DeferredDelegate<T, R> : _Delegate<R> {
public _DeferredDelegate(UpdateShouldNotify<R> updateShouldNotify, DeferredStartListening<T, R> startListening)
{
this.updateShouldNotify = updateShouldNotify;
this.startListening = startListening;
}
public readonly UpdateShouldNotify<R> updateShouldNotify;
public readonly DeferredStartListening<T, R> startListening;
public override _DelegateState<R, _Delegate<R>> createState()
{
return null; // [attention] this function has no body in flutter
}
}
public abstract class _DeferredDelegateState<T, R, W > : _DelegateState<R, W> where W : _DeferredDelegate<T, R>
{
public VoidCallback _removeListener;
R _value;
public new R value {
get
{
// element._isNotifyDependentsEnabled = false;
// _removeListener ??= delegate.startListening(
// element,
// setState,
// controller,
// _value,
// );
// element._isNotifyDependentsEnabled = true;
// D.assert(element.hasValue, '''
// The callback "startListening" was called, but it left DeferredInhertitedProviderElement<$T, $R>
// in an unitialized state.
//
// It is necessary for "startListening" to call "setState" at least once the very
// first time "value" is requested.
//
// To fix, consider:
//
// DeferredInheritedProvider(
// ...,
// startListening: (element, setState, controller, value) {
// if (!element.hasValue) {
// setState(myInitialValue); // TODO replace myInitialValue with your own
// }
// ...
// }
// )
// ''');
// D.assert(_removeListener != null);
return _value;
}
}
}
public class _ValueDeferredInheritedProvider<T, R> : _DeferredDelegate<T, R> {
public _ValueDeferredInheritedProvider(
T value,
UpdateShouldNotify<R> updateShouldNotify,
DeferredStartListening<T, R> startListening
) : base(updateShouldNotify, startListening)
{
this.value = value;
}
public readonly T value;
public _ValueDeferredInheritedProviderState<T, R> createState() { // [attention] override
return new _ValueDeferredInheritedProviderState<T,R>();
}
public override void debugFillProperties(DiagnosticPropertiesBuilder properties) {
base.debugFillProperties(properties);
properties.add(new DiagnosticsProperty<T>("controller", value));
}
}
public class _ValueDeferredInheritedProviderState<T, R> : _DeferredDelegateState<
T, R, _ValueDeferredInheritedProvider<T, R>> {
public override bool willUpdateDelegate(_ValueDeferredInheritedProvider<T, R> oldDelegate) {
if (true) { // [attention] _delegate.value != oldDelegate.value
if (_removeListener != null) {
_removeListener();
_removeListener = null;
}
return true;
}
return false;
}
public new T controller
{
get
{
return _delegate.value;
}
}
public override void debugFillProperties(DiagnosticPropertiesBuilder properties) {
base.debugFillProperties(properties);
if (_removeListener != null) {
properties.add(new DiagnosticsProperty<R>("value", value));
} else {
properties.add(
new FlagProperty(
"value",
value: true,
showName: true,
ifTrue: "<not yet loaded>"
)
);
}
}
}
}

64
com.unity.uiwidgets.devtools/Editor/v2/dependencies/provider/value_listenable_provider.cs


using Unity.UIWidgets.foundation;
using Unity.UIWidgets.widgets;
namespace Unity.UIWidgets.DevTools
{
class ValueListenableProvider<T> : DeferredInheritedProvider<ValueListenable<T>, T> {
public ValueListenableProvider(
Key key = null,
Create<ValueListenable<T>> create = null,
UpdateShouldNotify<T> updateShouldNotify = null,
bool? lazy = null,
TransitionBuilder builder = null,
Widget child = null
) : base(
key: key,
create: create,
lazy: lazy,
builder: builder,
updateShouldNotify: updateShouldNotify,
startListening: _startListening<T>(),
dispose: _dispose,
child: child
)
{
}
private static void _dispose(BuildContext context, ValueListenable<T> notifier)
{
if (notifier is ValueNotifier<T>) {
((ValueNotifier<T>)notifier).dispose();
}
}
public ValueListenableProvider(
Key key = null,
ValueListenable<T> value = null,
UpdateShouldNotify<T> updateShouldNotify = null,
TransitionBuilder builder = null,
Widget child = null
) : base(
key: key,
builder: builder,
value: value,
updateShouldNotify: updateShouldNotify,
startListening: _startListening<T>(),
child: child
)
{
}
public static DeferredStartListening<ValueListenable<T>, T> _startListening<T>() {
return (_, setState, controller, __) => {
setState(controller.value);
controller.addListener(() => setState(controller.value));
return () => controller.removeListener(() => setState(controller.value));
};
}
}
}
正在加载...
取消
保存