浏览代码

scaffold step 2

/main
xingwei.zhu 6 年前
当前提交
286a9757
共有 10 个文件被更改,包括 906 次插入41 次删除
  1. 2
      Runtime/material/app_bar.cs
  2. 6
      Runtime/material/float_action_button.cs
  3. 2
      Runtime/material/float_action_button_location.cs
  4. 711
      Runtime/material/scaffold.cs
  5. 93
      Runtime/material/snack_bar.cs
  6. 2
      Runtime/material/bottom_sheet.cs.meta
  7. 2
      Runtime/widgets/framework.cs
  8. 124
      Runtime/material/bottom_sheet.cs
  9. 5
      Runtime/material/bottom_app_bar.cs
  10. 0
      /Runtime/material/bottom_sheet.cs.meta

2
Runtime/material/app_bar.cs


}
else {
if (canPop) {
leading = useCloseButton ? (Widget)new CloseButton() : new BackButton() :
leading = useCloseButton ? (Widget) new CloseButton() : new BackButton();
}
}
}

6
Runtime/material/float_action_button.cs


namespace Unity.UIWidgets.material {
static class FloatActionButtonUtils {
public static BoxConstraints _kSizeConstraints = BoxConstraints.tightFor(width: 56.0f, height: 56.0f);
public static readonly BoxConstraints _kSizeConstraints = BoxConstraints.tightFor(width: 56.0f, height: 56.0f);
public static BoxConstraints _kMiniSizeConstraints = BoxConstraints.tightFor(width: 40.0f, height: 40.0f);
public static readonly BoxConstraints _kMiniSizeConstraints = BoxConstraints.tightFor(width: 40.0f, height: 40.0f);
public static BoxConstraints _kExtendedSizeConstraints = new BoxConstraints(minHeight: 48.0f, maxHeight: 48.0f);
public static readonly BoxConstraints _kExtendedSizeConstraints = new BoxConstraints(minHeight: 48.0f, maxHeight: 48.0f);
}

2
Runtime/material/float_action_button_location.cs


public static class FloatingActionButtonLocationUtils {
public const float kFloatingActionButtonMargin = 16.0f;
public static TimeSpan kFloatingActionButtonSegue = new TimeSpan(0, 0, 0, 0, 200);
public static readonly TimeSpan kFloatingActionButtonSegue = new TimeSpan(0, 0, 0, 0, 200);
public const float kFloatingActionButtonTurnInterval = 0.125f;
}

711
Runtime/material/scaffold.cs


using System;
using System.Linq;
using RSG;
using Unity.UIWidgets.async;
using Unity.UIWidgets.foundation;
using Unity.UIWidgets.painting;
using Unity.UIWidgets.rendering;

namespace Unity.UIWidgets.material {
static class ScaffoldUtils {
public static FloatingActionButtonLocation _kDefaultFloatingActionButtonLocation =
public static readonly FloatingActionButtonLocation _kDefaultFloatingActionButtonLocation =
public static FloatingActionButtonAnimator _kDefaultFloatingActionButtonAnimator =
public static readonly FloatingActionButtonAnimator _kDefaultFloatingActionButtonAnimator =
FloatingActionButtonAnimator.scaling;
}

public static ScaffoldState of(BuildContext context, bool nullOk = false) {
D.assert(context != null);
ScaffoldState result = (ScaffoldState)context.ancestorStateOfType(new TypeMatcher<ScaffoldState>());
ScaffoldState result = (ScaffoldState) context.ancestorStateOfType(new TypeMatcher<ScaffoldState>());
if (nullOk || result != null) {
return result;
}

}
static ValueListenable<ScaffoldGeometry> geometryOf(BuildContext context) {
_ScaffoldScope scaffoldScope = (_ScaffoldScope)context.inheritFromWidgetOfExactType(typeof(_ScaffoldScope));
_ScaffoldScope scaffoldScope =
(_ScaffoldScope) context.inheritFromWidgetOfExactType(typeof(_ScaffoldScope));
if (scaffoldScope == null) {
throw new UIWidgetsError(
"Scaffold.geometryOf() called with a context that does not contain a Scaffold.\n" +

static bool hasDrawer(BuildContext context, bool registerForUpdates = true) {
D.assert(context != null);
if (registerForUpdates) {
_ScaffoldScope scaffold = (_ScaffoldScope)context.inheritFromWidgetOfExactType(typeof(_ScaffoldScope));
_ScaffoldScope scaffold = (_ScaffoldScope) context.inheritFromWidgetOfExactType(typeof(_ScaffoldScope));
ScaffoldState scaffold = context.ancestorStateOfType(new TypeMatcher<ScaffoldState>());
ScaffoldState scaffold = (ScaffoldState) context.ancestorStateOfType(new TypeMatcher<ScaffoldState>());
return scaffold?.hasDrawer ?? false;
}
}

}
public class ScaffoldState : TickerProviderStateMixin<Scaffold> {
public readonly GlobalKey<DrawerControllerState> _drawerKey = GlobalKey<DrawerControllerState>.key();
public readonly GlobalKey<DrawerControllerState> _endDrawerKey = GlobalKey<DrawerControllerState>.key();

if (this._drawerKey.currentState != null && this._drawerOpened) {
this._drawerKey.currentState.close();
}
readonly Queue<ScaffoldFeatureController<SnackBar, SnackBarClosedReason>> _snackBars =
new Queue<ScaffoldFeatureController<SnackBar, SnackBarClosedReason>>();
AnimationController _snackBarController;
Timer _snackBarTimer;
bool _accessibleNavigation;
ScaffoldFeatureController<SnackBar, SnackBarClosedReason> showSnackBar(SnackBar snackbar) {
this._snackBarController = this._snackBarController ?? SnackBar.createAnimationController(vsync: this);
this._snackBarController.addStatusListener(this._handleSnackBarStatusChange);
if (this._snackBars.isEmpty()) {
D.assert(this._snackBarController.isDismissed);
this._snackBarController.forward();
}
ScaffoldFeatureController<SnackBar, SnackBarClosedReason> controller =
new ScaffoldFeatureController<SnackBar, SnackBarClosedReason>(
snackbar.withAnimation(this._snackBarController, fallbackKey: new UniqueKey()),
new Promise<SnackBarClosedReason>(),
() => {
D.assert(this._snackBars.First() == controller);
this.hideCurrentSnackBar(reason: SnackBarClosedReason.hide);
},
null);
this.setState(() => { this._snackBars.Enqueue(controller); });
return controller;
}
void _handleSnackBarStatusChange(AnimationStatus status) {
switch (status) {
case AnimationStatus.dismissed: {
D.assert(this._snackBars.isNotEmpty());
this.setState(() => { this._snackBars.Dequeue(); });
if (this._snackBars.isNotEmpty()) {
this._snackBarController.forward();
}
break;
}
case AnimationStatus.completed: {
this.setState(() => { D.assert(this._snackBarTimer == null); });
break;
}
case AnimationStatus.forward:
case AnimationStatus.reverse: {
break;
}
}
}
public void removeCurrentSnackBar(SnackBarClosedReason reason = SnackBarClosedReason.remove) {
if (this._snackBars.isEmpty()) {
return;
}
Promise<SnackBarClosedReason> completer = this._snackBars.First()._completer;
if (!completer.isCompleted) {
completer.Resolve(reason);
}
this._snackBarTimer?.cancel();
this._snackBarTimer = null;
this._snackBarController.setValue(0.0f);
}
public void hideCurrentSnackBar(SnackBarClosedReason reason = SnackBarClosedReason.hide) {
if (this._snackBars.isEmpty() || this._snackBarController.status == AnimationStatus.dismissed) {
return;
}
MediaQueryData mediaQuery = MediaQuery.of(this.context);
Promise<SnackBarClosedReason> completer = this._snackBars.First()._completer;
if (mediaQuery.accessibleNavigation) {
this._snackBarController.setValue(0.0f);
completer.Resolve(reason);
}
else {
this._snackBarController.reverse().Then(() => {
D.assert(this.mounted);
if (!completer.isCompleted) {
completer.Resolve(reason);
}
});
}
this._snackBarTimer?.cancel();
this._snackBarTimer = null;
}
readonly List<_PersistentBottomSheet> _dismissedBottomSheets = new List<_PersistentBottomSheet>();
PersistentBottomSheetController<object> _currentBottomSheet;
void _maybeBuildCurrentBottomSheet() {
if (this.widget.bottomSheet != null) {
AnimationController controller = BottomSheet.createAnimationController(this);
controller.setValue(1.0f);
this._currentBottomSheet = this._buildBottomSheet<object>(
(BuildContext context) => this.widget.bottomSheet,
controller,
false);
}
}
void _closeCurrentBottomSheet() {
if (this._currentBottomSheet != null) {
this._currentBottomSheet.close();
D.assert(this._currentBottomSheet == null);
}
}
PersistentBottomSheetController<T> _buildBottomSheet<T>(WidgetBuilder builder, AnimationController controller,
bool isLocalHistoryEntry) {
Promise<T> completer = new Promise<T>();
GlobalKey<_PersistentBottomSheetState> bottomSheetKey = GlobalKey<_PersistentBottomSheetState>.key();
_PersistentBottomSheet bottomSheet = null;
void _removeCurrentBottomSheet() {
D.assert(this._currentBottomSheet._widget == bottomSheet);
D.assert(bottomSheetKey.currentState != null);
bottomSheetKey.currentState.close();
if (controller.status != AnimationStatus.dismissed) {
this._dismissedBottomSheets.Add(bottomSheet);
}
this.setState(() => { this._currentBottomSheet = null; });
completer.Done();
}
LocalHistoryEntry entry = isLocalHistoryEntry
? new LocalHistoryEntry(onRemove: _removeCurrentBottomSheet)
: null;
bottomSheet = new _PersistentBottomSheet(
key: bottomSheetKey,
animationController: controller,
enableDrag: isLocalHistoryEntry,
onClosing: () => {
D.assert(this._currentBottomSheet._widget == bottomSheet);
if (isLocalHistoryEntry) {
entry.remove();
}
else {
_removeCurrentBottomSheet();
}
},
onDismissed: () => {
if (this._dismissedBottomSheets.Contains(bottomSheet)) {
bottomSheet.animationController.dispose();
this.setState(() => { this._dismissedBottomSheets.Remove(bottomSheet); });
}
},
builder: builder);
if (isLocalHistoryEntry) {
ModalRoute.of(this.context).addLocalHistoryEntry(entry);
}
return new PersistentBottomSheetController<T>(
bottomSheet,
completer,
isLocalHistoryEntry ? (VoidCallback) entry.remove : _removeCurrentBottomSheet,
(VoidCallback fn) => { bottomSheetKey.currentState?.setState(fn); },
isLocalHistoryEntry);
}
PersistentBottomSheetController<object> showBottomSheet(WidgetBuilder builder) {
this._closeCurrentBottomSheet();
AnimationController controller = BottomSheet.createAnimationController(this);
controller.forward();
this.setState(() => {
this._currentBottomSheet = this._buildBottomSheet<object>(builder, controller, true);
});
return this._currentBottomSheet;
}
AnimationController _floatingActionButtonMoveController;
FloatingActionButtonAnimator _floatingActionButtonAnimator;
FloatingActionButtonLocation _previousFloatingActionButtonLocation;
FloatingActionButtonLocation _floatingActionButtonLocation;
void _moveFloatingActionButton(FloatingActionButtonLocation newLocation) {
FloatingActionButtonLocation previousLocation = this._floatingActionButtonLocation;
float restartAnimationFrom = 0.0f;
if (this._floatingActionButtonMoveController.isAnimating) {
previousLocation = new _TransitionSnapshotFabLocation(this._previousFloatingActionButtonLocation,
this._floatingActionButtonLocation,
this._floatingActionButtonAnimator,
this._floatingActionButtonMoveController.value);
restartAnimationFrom =
this._floatingActionButtonAnimator.getAnimationRestart(this._floatingActionButtonMoveController
.value);
}
this.setState(() => {
this._previousFloatingActionButtonLocation = previousLocation;
this._floatingActionButtonLocation = newLocation;
});
this._floatingActionButtonMoveController.forward(from: restartAnimationFrom);
}
ScrollController _primaryScrollController = new ScrollController();
void _handleStatusBarTap() {
if (this._primaryScrollController.hasClients) {
this._primaryScrollController.animateTo(
to: 0.0f,
duration: new TimeSpan(0, 0, 0, 0, 300),
curve: Curves.linear);
}
}
_ScaffoldGeometryNotifier _geometryNotifier;
public override void initState() {
base.initState();
this._geometryNotifier = new _ScaffoldGeometryNotifier(new ScaffoldGeometry(), this.context);
this._floatingActionButtonLocation = this.widget.floatingActionButtonLocation ??
ScaffoldUtils._kDefaultFloatingActionButtonLocation;
this._floatingActionButtonAnimator = this.widget.floatingActionButtonAnimator ??
ScaffoldUtils._kDefaultFloatingActionButtonAnimator;
this._previousFloatingActionButtonLocation = this._floatingActionButtonLocation;
this._floatingActionButtonMoveController = new AnimationController(
vsync: this,
lowerBound: 0.0f,
upperBound: 1.0f,
value: 1.0f,
duration: FloatingActionButtonLocationUtils.kFloatingActionButtonSegue +
FloatingActionButtonLocationUtils.kFloatingActionButtonSegue
);
this._maybeBuildCurrentBottomSheet();
}
public override void didUpdateWidget(StatefulWidget oldWidget) {
Scaffold _oldWidget = (Scaffold) oldWidget;
if (this.widget.floatingActionButtonAnimator != _oldWidget.floatingActionButtonAnimator) {
this._floatingActionButtonAnimator = this.widget.floatingActionButtonAnimator ??
ScaffoldUtils._kDefaultFloatingActionButtonAnimator;
}
if (this.widget.floatingActionButtonLocation != _oldWidget.floatingActionButtonLocation) {
this._moveFloatingActionButton(this.widget.floatingActionButtonLocation ??
ScaffoldUtils._kDefaultFloatingActionButtonLocation);
}
if (this.widget.bottomSheet != _oldWidget.bottomSheet) {
D.assert(() => {
if (this.widget.bottomSheet != null && this._currentBottomSheet?._isLocalHistoryEntry == true) {
throw new UIWidgetsError(
"Scaffold.bottomSheet cannot be specified while a bottom sheet displayed " +
"with showBottomSheet() is still visible.\n Use the PersistentBottomSheetController " +
"returned by showBottomSheet() to close the old bottom sheet before creating " +
"a Scaffold with a (non null) bottomSheet.");
}
return true;
});
this._closeCurrentBottomSheet();
this._maybeBuildCurrentBottomSheet();
}
base.didUpdateWidget(oldWidget);
}
public override void didChangeDependencies() {
MediaQueryData mediaQuery = MediaQuery.of(this.context);
if (this._accessibleNavigation
&& !mediaQuery.accessibleNavigation
&& this._snackBarTimer != null) {
this.hideCurrentSnackBar(reason: SnackBarClosedReason.timeout);
}
this._accessibleNavigation = mediaQuery.accessibleNavigation;
base.didChangeDependencies();
}
public override void dispose() {
this._snackBarController?.dispose();
this._snackBarTimer?.cancel();
this._snackBarTimer = null;
this._geometryNotifier.dispose();
foreach (_PersistentBottomSheet bottomSheet in this._dismissedBottomSheets) {
bottomSheet.animationController.dispose();
}
if (this._currentBottomSheet != null) {
this._currentBottomSheet._widget.animationController.dispose();
}
this._floatingActionButtonMoveController.dispose();
base.dispose();
}
void _addIfNonNull(List<LayoutId> children, Widget child, object childId,
bool removeLeftPadding,
bool removeTopPadding,
bool removeRightPadding,
bool removeBottomPadding
) {
if (child != null) {
children.Add(
new LayoutId(
id: childId,
child: MediaQuery.removePadding(
context: this.context,
removeLeft: removeLeftPadding,
removeTop: removeTopPadding,
removeRight: removeRightPadding,
removeBottom: removeBottomPadding,
child: child
)
)
);
}
}
void _buildEndDrawer(List<LayoutId> children) {
if (this.widget.endDrawer != null) {
D.assert(this.hasEndDrawer);
this._addIfNonNull(
children: children,
new DrawerController(
key: this._endDrawerKey,
alignment: DrawerAlignment.end,
child: this.widget.endDrawer,
drawerCallback: this._endDrawerOpenedCallback
),
childId: _ScaffoldSlot.endDrawer,
removeLeftPadding: true,
removeTopPadding: false,
removeRightPadding: false,
removeBottomPadding: false
);
}
}
void _buildDrawer(List<LayoutId> children) {
if (this.widget.drawer != null) {
D.assert(this.hasDrawer);
this._addIfNonNull(
children: children,
new DrawerController(
key: this._drawerKey,
alignment: DrawerAlignment.start,
child: this.widget.drawer,
drawerCallback: this._drawerOpenedCallback
),
childId: _ScaffoldSlot.drawer,
removeLeftPadding: false,
removeTopPadding: false,
removeRightPadding: true,
removeBottomPadding: false
);
}
}
public override Widget build(BuildContext context) {
MediaQueryData mediaQuery = MediaQuery.of(context);
ThemeData themeData = Theme.of(context);
this._accessibleNavigation = mediaQuery.accessibleNavigation;
if (this._snackBars.isNotEmpty()) {
ModalRoute route = ModalRoute.of(context);
if (route == null || route.isCurrent) {
if (this._snackBarController.isCompleted && this._snackBarTimer == null) {
SnackBar snackBar = this._snackBars.First()._widget;
this._snackBarTimer = Window.instance.run(snackBar.duration, () => {
D.assert(this._snackBarController.status == AnimationStatus.forward ||
this._snackBarController.status == AnimationStatus.completed);
MediaQueryData subMediaQuery = MediaQuery.of(context);
if (subMediaQuery.accessibleNavigation && snackBar.action != null) {
return;
}
this.hideCurrentSnackBar(reason: SnackBarClosedReason.timeout);
});
}
}
else {
this._snackBarTimer?.cancel();
this._snackBarTimer = null;
}
}
List<LayoutId> children = new List<LayoutId>();
this._addIfNonNull(
children: children,
child: this.widget.body,
childId: _ScaffoldSlot.body,
removeLeftPadding: false,
removeTopPadding: this.widget.appBar != null,
removeRightPadding: false,
removeBottomPadding: this.widget.bottomNavigationBar != null ||
this.widget.persistentFooterButtons != null
);
if (this.widget.appBar != null) {
float topPadding = this.widget.primary ? mediaQuery.padding.top : 0.0f;
float extent = this.widget.appBar.preferredSize.height + topPadding;
D.assert(extent >= 0.0f && extent.isFinite());
this._addIfNonNull(
children: children,
new ConstrainedBox(
constraints: new BoxConstraints(maxHeight: extent),
child: FlexibleSpaceBar.createSettings(
currentExtent: extent,
child: this.widget.appBar
)
),
childId: _ScaffoldSlot.appBar,
removeLeftPadding: false,
removeTopPadding: false,
removeRightPadding: false,
removeBottomPadding: true
);
}
if (this._snackBars.isNotEmpty()) {
bool removeBottomPadding = this.widget.persistentFooterButtons != null ||
this.widget.bottomNavigationBar != null;
this._addIfNonNull(
children: children,
child: this._snackBars.First()._widget,
childId: _ScaffoldSlot.snackBar,
removeLeftPadding: false,
removeTopPadding: true,
removeRightPadding: false,
removeBottomPadding: removeBottomPadding
);
}
if (this.widget.persistentFooterButtons != null) {
this._addIfNonNull(
children: children,
new Container(
decoration: new BoxDecoration(
border: new Border(
top: Divider.createBorderSide(context, width: 1.0f)
)
),
child: new SafeArea(
child: ButtonTheme.bar(
child: new SafeArea(
top: false,
child: new ButtonBar(
children: this.widget.persistentFooterButtons
)
)
)
)
),
childId: _ScaffoldSlot.persistentFooter,
removeLeftPadding: false,
removeTopPadding: true,
removeRightPadding: false,
removeBottomPadding: false
);
}
if (this.widget.bottomNavigationBar != null) {
this._addIfNonNull(
children: children,
child: this.widget.bottomNavigationBar,
childId: _ScaffoldSlot.bottomNavigationBar,
removeLeftPadding: false,
removeTopPadding: true,
removeRightPadding: false,
removeBottomPadding: false
);
}
if (this._currentBottomSheet != null || this._dismissedBottomSheets.isNotEmpty()) {
List<Widget> bottomSheets = new List<Widget>();
if (this._dismissedBottomSheets.isNotEmpty()) {
bottomSheets.AddRange(this._dismissedBottomSheets);
}
if (this._currentBottomSheet != null) {
bottomSheets.Add(this._currentBottomSheet._widget);
}
Widget stack = new Stack(
children: bottomSheets,
alignment: Alignment.bottomCenter
);
this._addIfNonNull(
children: children,
child: stack,
childId: _ScaffoldSlot.bottomSheet,
removeLeftPadding: false,
removeTopPadding: true,
removeRightPadding: false,
removeBottomPadding: this.widget.resizeToAvoidBottomPadding
);
}
this._addIfNonNull(
children: children,
new _FloatingActionButtonTransition(
child: this.widget.floatingActionButton,
fabMoveAnimation: this._floatingActionButtonMoveController,
fabMotionAnimator: this._floatingActionButtonAnimator,
geometryNotifier: this._geometryNotifier
),
childId: _ScaffoldSlot.floatingActionButton,
removeLeftPadding: true,
removeTopPadding: true,
removeRightPadding: true,
removeBottomPadding: true
);
if (themeData.platform == RuntimePlatform.IPhonePlayer) {
this._addIfNonNull(
children: children,
new GestureDetector(
behavior: HitTestBehavior.opaque,
onTap: this._handleStatusBarTap
),
childId: _ScaffoldSlot.statusBar,
removeLeftPadding: false,
removeTopPadding: true,
removeRightPadding: false,
removeBottomPadding: true
);
}
if (this._endDrawerOpened) {
this._buildDrawer(children);
this._buildEndDrawer(children);
}
else {
this._buildEndDrawer(children);
this._buildDrawer(children);
}
EdgeInsets minInsets = mediaQuery.padding.copyWith(
bottom: this.widget.resizeToAvoidBottomPadding ? mediaQuery.viewInsets.bottom : 0.0f
);
return new _ScaffoldScope(
hasDrawer: this.hasDrawer,
geometryNotifier: this._geometryNotifier,
child: new PrimaryScrollController(
controller: this._primaryScrollController,
child: new Material(
color: this.widget.backgroundColor ?? themeData.scaffoldBackgroundColor,
child: new AnimatedBuilder(animation: this._floatingActionButtonMoveController,
builder: (BuildContext subContext, Widget child) => {
return new CustomMultiChildLayout(
children: new List<Widget>(children),
layoutDelegate: new _ScaffoldLayout(
minInsets: minInsets,
currentFloatingActionButtonLocation: this._floatingActionButtonLocation,
floatingActionButtonMoveAnimationProgress: this
._floatingActionButtonMoveController.value,
floatingActionButtonMotionAnimator: this._floatingActionButtonAnimator,
geometryNotifier: this._geometryNotifier,
previousFloatingActionButtonLocation: this._previousFloatingActionButtonLocation
)
);
}
)
)
)
);
}
}
class ScaffoldFeatureController<T, U> where T : Widget {
public ScaffoldFeatureController(
T _widget,
Promise<U> _completer,
VoidCallback close,
StateSetter setState) {
this._widget = _widget;
this._completer = _completer;
this.close = close;
this.setState = setState;
}
public readonly T _widget;
public readonly Promise<U> _completer;
IPromise<U> closed {
get { return this._completer; }
}
public readonly VoidCallback close;
public readonly StateSetter setState;
}
class _PersistentBottomSheet : StatefulWidget {
public _PersistentBottomSheet(
Key key = null,
AnimationController animationController = null,
bool enableDrag = true,
VoidCallback onClosing = null,
VoidCallback onDismissed = null,
WidgetBuilder builder = null
) : base(key: key) {
this.animationController = animationController;
this.enableDrag = enableDrag;
this.onClosing = onClosing;
this.onDismissed = onDismissed;
this.builder = builder;
}
public readonly AnimationController animationController;
public readonly bool enableDrag;
public readonly VoidCallback onClosing;
public readonly VoidCallback onDismissed;
public readonly WidgetBuilder builder;
public override State createState() {
return new _PersistentBottomSheetState();
}
class _PersistentBottomSheetState : State<_PersistentBottomSheet> {
public override void initState() {
base.initState();
D.assert(this.widget.animationController.status == AnimationStatus.forward
|| this.widget.animationController.status == AnimationStatus.completed);
this.widget.animationController.addStatusListener(this._handleStatusChange);
}
public override void didUpdateWidget(StatefulWidget oldWidget) {
base.didUpdateWidget(oldWidget);
_PersistentBottomSheet _oldWidget = (_PersistentBottomSheet) oldWidget;
D.assert(this.widget.animationController == _oldWidget.animationController);
}
public void close() {
this.widget.animationController.reverse();
}
void _handleStatusChange(AnimationStatus status) {
if (status == AnimationStatus.dismissed && this.widget.onDismissed != null) {
this.widget.onDismissed();
}
}
public override Widget build(BuildContext context) {
return new AnimatedBuilder(
animation: this.widget.animationController,
builder: (BuildContext subContext, Widget child) => {
return new Align(
alignment: Alignment.topLeft,
heightFactor: this.widget.animationController.value,
child: child);
},
child: new BottomSheet(
animationController: this.widget.animationController,
enableDrag: this.widget.enableDrag,
onClosing: this.widget.onClosing,
builder: this.widget.builder));
}
}
class PersistentBottomSheetController<T> : ScaffoldFeatureController<_PersistentBottomSheet, T> {
public PersistentBottomSheetController(
_PersistentBottomSheet widget,
Promise<T> completer,
VoidCallback close,
StateSetter setState,
bool _isLocalHistoryEntry
) : base(widget, completer, close, setState) {
this._isLocalHistoryEntry = _isLocalHistoryEntry;
}
public readonly bool _isLocalHistoryEntry;
}
class _ScaffoldScope : InheritedWidget {
public _ScaffoldScope(
bool? hasDrawer = null,

_ScaffoldScope _oldWidget = (_ScaffoldScope) oldWidget;
return this.hasDrawer != _oldWidget.hasDrawer;
}
}
}

93
Runtime/material/snack_bar.cs


using Unity.UIWidgets.foundation;
using Unity.UIWidgets.painting;
using Unity.UIWidgets.rendering;
using Unity.UIWidgets.scheduler;
public static Color _kSnackBackground = new Color(0xFF323232);
public static TimeSpan _kSnackBarTransitionDuration = new TimeSpan(0, 0, 0, 0, 250);
public static TimeSpan _kSnackBarDisplayDuration = new TimeSpan(0, 0, 0, 0, 4000);
public static Curve _snackBarHeightCurve = Curves.fastOutSlowIn;
public static Curve _snackBarFadeCurve = new Interval(0.72f, 1.0f, curve: Curves.fastOutSlowIn);
public static readonly Color _kSnackBackground = new Color(0xFF323232);
public static readonly TimeSpan _kSnackBarTransitionDuration = new TimeSpan(0, 0, 0, 0, 250);
public static readonly TimeSpan _kSnackBarDisplayDuration = new TimeSpan(0, 0, 0, 0, 4000);
public static readonly Curve _snackBarHeightCurve = Curves.fastOutSlowIn;
public static readonly Curve _snackBarFadeCurve = new Interval(0.72f, 1.0f, curve: Curves.fastOutSlowIn);
}
public enum SnackBarClosedReason {

Color disabledTextColor = null,
string label = null,
VoidCallback onPressed = null
) : base(key: key) {
) : base(key: key) {
D.assert(label != null);
D.assert(onPressed != null);
this.textColor = textColor;

class _SnackBarActionState : State<SnackBarAction> {
bool _haveTriggeredAction = false;
this.setState(() => {
this._haveTriggeredAction = true;
});
this.setState(() => { this._haveTriggeredAction = true; });
this.widget.onPressed();
Scaffold.of(this.context).hideCurrentSnackBar(reason: SnackBarClosedReason.action);
}

onPressed: this._haveTriggeredAction ? (VoidCallback)null : this._handlePressed,
onPressed: this._haveTriggeredAction ? (VoidCallback) null : this._handlePressed,
child: new Text(this.widget.label),
textColor: this.widget.textColor,
disabledTextColor: this.widget.disabledTextColor

padding: EdgeInsets.symmetric(horizontal: SnackBarUtils._kSnackBarPadding),
textTheme: ButtonTextTheme.accent,
child: this.action
));
));
CurvedAnimation heightAnimation = new CurvedAnimation(parent: this.animation, curve: SnackBarUtils._snackBarHeightCurve);
CurvedAnimation fadeAnimation = new CurvedAnimation(parent: this.animation, curve: SnackBarUtils._snackBarFadeCurve, reverseCurve: new Threshold(0.0f));
CurvedAnimation heightAnimation =
new CurvedAnimation(parent: this.animation, curve: SnackBarUtils._snackBarHeightCurve);
CurvedAnimation fadeAnimation = new CurvedAnimation(parent: this.animation,
curve: SnackBarUtils._snackBarFadeCurve, reverseCurve: new Threshold(0.0f));
Widget snackbar = new SafeArea(
top: false,
child: new Row(

);
snackbar = new Dismissible(
key: Key.key("dismissible"),
direction: DismissDirection.down,
resizeDuration: null,
onDismissed: (DismissDirection? direction) => {
Scaffold.of(context).removeCurrentSnackBar(reason: SnackBarClosedReason.swipe);
},
child: new Material(
elevation: 6.0f,
color: this.backgroundColor ?? SnackBarUtils._kSnackBackground,
child: new Theme(
data: darkTheme,
child: mediaQueryData.accessibleNavigation
? snackbar
: new FadeTransition(
opacity: fadeAnimation,
child: snackbar
)
)
)
);
return new ClipRect(
child: mediaQueryData.accessibleNavigation
? snackbar
: new AnimatedBuilder(
animation: heightAnimation,
builder: (BuildContext subContext, Widget child) => {
return new Align(
alignment: Alignment.topLeft,
heightFactor: heightAnimation.value,
child: child
);
},
child: snackbar
)
);
}
public static AnimationController createAnimationController(TickerProvider vsync) {
return new AnimationController(
duration: SnackBarUtils._kSnackBarTransitionDuration,
debugLabel: "SnackBar",
vsync: vsync
);
}
public SnackBar withAnimation(Animation<float> newAnimation, Key fallbackKey = null) {
return new SnackBar(
key: this.key ?? fallbackKey,
content: this.content,
backgroundColor: this.backgroundColor,
action: this.action,
duration: this.duration,
animation: newAnimation
);
}
}

2
Runtime/material/bottom_sheet.cs.meta


fileFormatVersion: 2
guid: e86f2ad5f24fd47cf9154c2b99ab5abb
guid: 5219593daa853417ebb5f7835c74a969
MonoImporter:
externalObjects: {}
serializedVersion: 2

2
Runtime/widgets/framework.cs


public virtual void didUpdateWidget(StatefulWidget oldWidget) {
}
protected void setState(VoidCallback fn = null) {
public void setState(VoidCallback fn = null) {
D.assert(() => {
if (this._debugLifecycleState == _StateLifecycle.defunct) {
throw new UIWidgetsError(

124
Runtime/material/bottom_sheet.cs


using System;
using Unity.UIWidgets.animation;
using Unity.UIWidgets.foundation;
using Unity.UIWidgets.gestures;
using Unity.UIWidgets.rendering;
using Unity.UIWidgets.scheduler;
using Unity.UIWidgets.ui;
using Unity.UIWidgets.widgets;
namespace Unity.UIWidgets.material {
static class BottomSheetUtils {
public static TimeSpan _kBottomSheetDuration = new TimeSpan(0, 0, 0, 0, 200);
public const float _kMinFlingVelocity = 700.0f;
public const float _kCloseProgressThreshold = 0.5f;
}
public class BottomSheet : StatefulWidget {
public BottomSheet(
Key key = null,
AnimationController animationController = null,
bool enableDrag = true,
float elevation = 0.0f,
VoidCallback onClosing = null,
WidgetBuilder builder = null
) : base(key: key) {
D.assert(onClosing != null);
D.assert(builder != null);
this.animationController = animationController;
this.enableDrag = enableDrag;
this.elevation = elevation;
this.onClosing = onClosing;
this.builder = builder;
}
public readonly AnimationController animationController;
public readonly VoidCallback onClosing;
public readonly WidgetBuilder builder;
public readonly bool enableDrag;
public readonly float elevation;
public override State createState() {
return new _BottomSheetState();
}
public static AnimationController createAnimationController(TickerProvider vsync) {
return new AnimationController(
duration: BottomSheetUtils._kBottomSheetDuration,
debugLabel: "BottomSheet",
vsync: vsync
);
}
}
class _BottomSheetState : State<BottomSheet> {
public readonly GlobalKey _childKey = GlobalKey.key(debugLabel: "BottomSheet child");
float? _childHeight {
get {
RenderBox renderBox = (RenderBox)this._childKey.currentContext.findRenderObject();
return renderBox.size.height;
}
}
bool _dismissUnderway {
get { return this.widget.animationController.status == AnimationStatus.reverse; }
}
void _handleDragUpdate(DragUpdateDetails details) {
if (this._dismissUnderway) {
return;
}
this.widget.animationController.setValue(
this.widget.animationController.value - details.primaryDelta.Value / (this._childHeight ?? details.primaryDelta.Value));
}
void _handleDragEnd(DragEndDetails details) {
if (this._dismissUnderway) {
return;
}
if (details.velocity.pixelsPerSecond.dy > BottomSheetUtils._kMinFlingVelocity) {
float flingVelocity = -details.velocity.pixelsPerSecond.dy / this._childHeight.Value;
if (this.widget.animationController.value > 0.0f) {
this.widget.animationController.fling(velocity: flingVelocity);
}
if (flingVelocity < 0.0f) {
this.widget.onClosing();
}
else if (this.widget.animationController.value < BottomSheetUtils._kCloseProgressThreshold) {
if (this.widget.animationController.value > 0.0f) {
this.widget.animationController.fling(velocity: -1.0f);
}
this.widget.onClosing();
}
else {
this.widget.animationController.forward();
}
}
}
public override Widget build(BuildContext context) {
Widget bottomSheet = new Material(
key: this._childKey,
elevation: this.widget.elevation,
child: this.widget.builder(context)
);
return !this.widget.enableDrag ? bottomSheet : new GestureDetector(
onVerticalDragUpdate: this._handleDragUpdate,
onVerticalDragEnd: this._handleDragEnd,
child: bottomSheet
);
}
}
}

5
Runtime/material/bottom_app_bar.cs


namespace Unity.UIWidgets.material {
public class bottom_app_bar {
}
}

/Runtime/material/bottom_app_bar.cs.meta → /Runtime/material/bottom_sheet.cs.meta

正在加载...
取消
保存