Yuncong
5 年前
当前提交
17e5c5fa
共有 57 个文件被更改,包括 8216 次插入 和 370 次删除
-
8Runtime/cupertino/app.cs
-
2Runtime/cupertino/text_theme.cs
-
14Runtime/cupertino/theme.cs
-
2Runtime/material/text_selection.cs
-
25Runtime/ui/text.cs
-
43Runtime/widgets/transitions.cs
-
5Samples/UIWidgetsGallery/Editor/GalleryMainEditor.cs
-
5Samples/UIWidgetsGallery/GalleryMain.cs
-
30Samples/UIWidgetsGallery/gallery/demo.cs
-
681Samples/UIWidgetsGallery/gallery/demos.cs
-
202Runtime/cupertino/bottom_app_bar.cs
-
11Runtime/cupertino/bottom_app_bar.cs.meta
-
1001Runtime/cupertino/nav_bar.cs
-
11Runtime/cupertino/nav_bar.cs.meta
-
145Runtime/cupertino/page_scaffold.cs
-
11Runtime/cupertino/page_scaffold.cs.meta
-
120Runtime/cupertino/scrollbar.cs
-
11Runtime/cupertino/scrollbar.cs.meta
-
380Runtime/cupertino/slider.cs
-
11Runtime/cupertino/slider.cs.meta
-
503Runtime/cupertino/switch.cs
-
11Runtime/cupertino/switch.cs.meta
-
214Runtime/cupertino/tab_scaffold.cs
-
11Runtime/cupertino/tab_scaffold.cs.meta
-
141Runtime/cupertino/tab_view.cs
-
11Runtime/cupertino/tab_view.cs.meta
-
574Runtime/cupertino/text_field.cs
-
11Runtime/cupertino/text_field.cs.meta
-
315Runtime/cupertino/text_selection.cs
-
11Runtime/cupertino/text_selection.cs.meta
-
42Runtime/cupertino/thumb_painter.cs
-
11Runtime/cupertino/thumb_painter.cs.meta
-
63Runtime/widgets/value_listenable_builder.cs
-
11Runtime/widgets/value_listenable_builder.cs.meta
-
66Samples/UIWidgetSample/Editor/CupertinoSampleWidget.cs
-
3Samples/UIWidgetSample/Editor/CupertinoSampleWidget.cs.meta
-
8Samples/UIWidgetsGallery/demo/cupertino.meta
-
1001Tests/Resources/SF-Pro-Text-Bold.otf
-
24Tests/Resources/SF-Pro-Text-Bold.otf.meta
-
1001Tests/Resources/SF-Pro-Text-Regular.otf
-
22Tests/Resources/SF-Pro-Text-Regular.otf.meta
-
1001Tests/Resources/SF-Pro-Text-Semibold.otf
-
23Tests/Resources/SF-Pro-Text-Semibold.otf.meta
-
11Samples/UIWidgetsGallery/demo/cupertino/cupertino_buttons_demo.cs.meta
-
24Samples/UIWidgetsGallery/demo/cupertino/cupertino_activity_indicator_demo.cs
-
11Samples/UIWidgetsGallery/demo/cupertino/cupertino_activity_indicator_demo.cs.meta
-
273Samples/UIWidgetsGallery/demo/cupertino/cupertino_alert_demo.cs
-
11Samples/UIWidgetsGallery/demo/cupertino/cupertino_alert_demo.cs.meta
-
86Samples/UIWidgetsGallery/demo/cupertino/cupertino_buttons_demo.cs
-
5Samples/UIWidgetsGallery/demo/cupertino/cupertino_navigation_demo.cs
-
71Samples/UIWidgetsGallery/demo/cupertino/cupertino_slider_demo.cs
-
11Samples/UIWidgetsGallery/demo/cupertino/cupertino_slider_demo.cs.meta
-
73Samples/UIWidgetsGallery/demo/cupertino/cupertino_switch_demo.cs
-
11Samples/UIWidgetsGallery/demo/cupertino/cupertino_switch_demo.cs.meta
-
192Samples/UIWidgetsGallery/demo/cupertino/cupertino_text_field_demo.cs
-
11Samples/UIWidgetsGallery/demo/cupertino/cupertino_text_field_demo.cs.meta
|
|||
using System.Collections.Generic; |
|||
using Unity.UIWidgets.foundation; |
|||
using Unity.UIWidgets.gestures; |
|||
using Unity.UIWidgets.painting; |
|||
using Unity.UIWidgets.rendering; |
|||
using Unity.UIWidgets.ui; |
|||
using Unity.UIWidgets.widgets; |
|||
using TextStyle = Unity.UIWidgets.painting.TextStyle; |
|||
|
|||
namespace Unity.UIWidgets.cupertino { |
|||
class BottomAppBarUtils { |
|||
public const float _kTabBarHeight = 50.0f; |
|||
public static readonly Color _kDefaultTabBarBorderColor = new Color(0x4C000000); |
|||
} |
|||
|
|||
|
|||
public class CupertinoTabBar : StatelessWidget { |
|||
public CupertinoTabBar( |
|||
Key key = null, |
|||
List<BottomNavigationBarItem> items = null, |
|||
ValueChanged<int> onTap = null, |
|||
int currentIndex = 0, |
|||
Color backgroundColor = null, |
|||
Color activeColor = null, |
|||
Color inactiveColor = null, |
|||
float iconSize = 30.0f, |
|||
Border border = null |
|||
) : base(key: key) { |
|||
D.assert(items != null); |
|||
D.assert(items.Count >= 2, |
|||
() => "Tabs need at least 2 items to conform to Apple's HIG" |
|||
); |
|||
D.assert(0 <= currentIndex && currentIndex < items.Count); |
|||
D.assert(inactiveColor != null); |
|||
this.items = items; |
|||
this.onTap = onTap; |
|||
this.currentIndex = currentIndex; |
|||
|
|||
this.backgroundColor = backgroundColor; |
|||
this.activeColor = activeColor; |
|||
this.inactiveColor = inactiveColor ?? CupertinoColors.inactiveGray; |
|||
this.iconSize = iconSize; |
|||
this.border = border ?? new Border( |
|||
top: new BorderSide( |
|||
color: BottomAppBarUtils._kDefaultTabBarBorderColor, |
|||
width: 0.0f, // One physical pixel.
|
|||
style: BorderStyle.solid |
|||
) |
|||
); |
|||
} |
|||
|
|||
public readonly List<BottomNavigationBarItem> items; |
|||
|
|||
public readonly ValueChanged<int> onTap; |
|||
|
|||
public readonly int currentIndex; |
|||
|
|||
public readonly Color backgroundColor; |
|||
|
|||
public readonly Color activeColor; |
|||
|
|||
public readonly Color inactiveColor; |
|||
|
|||
public readonly float iconSize; |
|||
|
|||
public readonly Border border; |
|||
|
|||
public Size preferredSize { |
|||
get { return Size.fromHeight(BottomAppBarUtils._kTabBarHeight); } |
|||
} |
|||
|
|||
public bool opaque(BuildContext context) { |
|||
Color backgroundColor = |
|||
this.backgroundColor ?? CupertinoTheme.of(context).barBackgroundColor; |
|||
return backgroundColor.alpha == 0xFF; |
|||
} |
|||
|
|||
public override Widget build(BuildContext context) { |
|||
float bottomPadding = MediaQuery.of(context).padding.bottom; |
|||
|
|||
Widget result = new DecoratedBox( |
|||
decoration: new BoxDecoration( |
|||
border: this.border, |
|||
color: this.backgroundColor ?? CupertinoTheme.of(context).barBackgroundColor |
|||
), |
|||
child: new SizedBox( |
|||
height: BottomAppBarUtils._kTabBarHeight + bottomPadding, |
|||
child: IconTheme.merge( // Default with the inactive state.
|
|||
data: new IconThemeData( |
|||
color: this.inactiveColor, |
|||
size: this.iconSize |
|||
), |
|||
child: new DefaultTextStyle( // Default with the inactive state.
|
|||
style: CupertinoTheme.of(context).textTheme.tabLabelTextStyle |
|||
.copyWith(color: this.inactiveColor), |
|||
child: new Padding( |
|||
padding: EdgeInsets.only(bottom: bottomPadding), |
|||
child: new Row( |
|||
crossAxisAlignment: CrossAxisAlignment.end, |
|||
children: this._buildTabItems(context) |
|||
) |
|||
) |
|||
) |
|||
) |
|||
) |
|||
); |
|||
|
|||
if (!this.opaque(context)) { |
|||
result = new ClipRect( |
|||
child: new BackdropFilter( |
|||
filter: ImageFilter.blur(sigmaX: 10.0f, sigmaY: 10.0f), |
|||
child: result |
|||
) |
|||
); |
|||
} |
|||
|
|||
return result; |
|||
} |
|||
|
|||
List<Widget> _buildTabItems(BuildContext context) { |
|||
List<Widget> result = new List<Widget> { }; |
|||
|
|||
for (int index = 0; index < this.items.Count; index += 1) { |
|||
bool active = index == this.currentIndex; |
|||
result.Add( |
|||
this._wrapActiveItem( |
|||
context, |
|||
new Expanded( |
|||
child: new GestureDetector( |
|||
behavior: HitTestBehavior.opaque, |
|||
onTap: this.onTap == null ? null : (GestureTapCallback) (() => { this.onTap(index); }), |
|||
child: new Padding( |
|||
padding: EdgeInsets.only(bottom: 4.0f), |
|||
child: new Column( |
|||
mainAxisAlignment: MainAxisAlignment.end, |
|||
children: this._buildSingleTabItem(this.items[index], active) |
|||
) |
|||
) |
|||
) |
|||
), |
|||
active: active |
|||
) |
|||
); |
|||
} |
|||
|
|||
return result; |
|||
} |
|||
|
|||
List<Widget> _buildSingleTabItem(BottomNavigationBarItem item, bool active) { |
|||
List<Widget> components = new List<Widget> { |
|||
new Expanded( |
|||
child: new Center(child: active ? item.activeIcon : item.icon) |
|||
) |
|||
}; |
|||
|
|||
if (item.title != null) { |
|||
components.Add(item.title); |
|||
} |
|||
|
|||
return components; |
|||
} |
|||
|
|||
Widget _wrapActiveItem(BuildContext context, Widget item, bool active) { |
|||
if (!active) { |
|||
return item; |
|||
} |
|||
|
|||
Color activeColor = this.activeColor ?? CupertinoTheme.of(context).primaryColor; |
|||
return IconTheme.merge( |
|||
data: new IconThemeData(color: activeColor), |
|||
child: DefaultTextStyle.merge( |
|||
style: new TextStyle(color: activeColor), |
|||
child: item |
|||
) |
|||
); |
|||
} |
|||
|
|||
public CupertinoTabBar copyWith( |
|||
Key key = null, |
|||
List<BottomNavigationBarItem> items = null, |
|||
Color backgroundColor = null, |
|||
Color activeColor = null, |
|||
Color inactiveColor = null, |
|||
float? iconSize = null, |
|||
Border border = null, |
|||
int? currentIndex = null, |
|||
ValueChanged<int> onTap = null |
|||
) { |
|||
return new CupertinoTabBar( |
|||
key: key ?? this.key, |
|||
items: items ?? this.items, |
|||
backgroundColor: backgroundColor ?? this.backgroundColor, |
|||
activeColor: activeColor ?? this.activeColor, |
|||
inactiveColor: inactiveColor ?? this.inactiveColor, |
|||
iconSize: iconSize ?? this.iconSize, |
|||
border: border ?? this.border, |
|||
currentIndex: currentIndex ?? this.currentIndex, |
|||
onTap: onTap ?? this.onTap |
|||
); |
|||
} |
|||
} |
|||
} |
|
|||
fileFormatVersion: 2 |
|||
guid: a4d68e50e84368e42b995ebca3727675 |
|||
MonoImporter: |
|||
externalObjects: {} |
|||
serializedVersion: 2 |
|||
defaultReferences: [] |
|||
executionOrder: 0 |
|||
icon: {instanceID: 0} |
|||
userData: |
|||
assetBundleName: |
|||
assetBundleVariant: |
1001
Runtime/cupertino/nav_bar.cs
文件差异内容过多而无法显示
查看文件
文件差异内容过多而无法显示
查看文件
|
|||
fileFormatVersion: 2 |
|||
guid: 3b784deecd91aef4085ba0796eea3324 |
|||
MonoImporter: |
|||
externalObjects: {} |
|||
serializedVersion: 2 |
|||
defaultReferences: [] |
|||
executionOrder: 0 |
|||
icon: {instanceID: 0} |
|||
userData: |
|||
assetBundleName: |
|||
assetBundleVariant: |
|
|||
using System; |
|||
using System.Collections.Generic; |
|||
using Unity.UIWidgets.animation; |
|||
using Unity.UIWidgets.foundation; |
|||
using Unity.UIWidgets.painting; |
|||
using Unity.UIWidgets.ui; |
|||
using Unity.UIWidgets.widgets; |
|||
|
|||
namespace Unity.UIWidgets.cupertino { |
|||
public class CupertinoPageScaffold : StatefulWidget { |
|||
/// Creates a layout for pages with a navigation bar at the top.
|
|||
public CupertinoPageScaffold( |
|||
Widget child, |
|||
Key key = null, |
|||
ObstructingPreferredSizeWidget navigationBar = null, |
|||
Color backgroundColor = null, |
|||
bool resizeToAvoidBottomInset = true |
|||
) : base(key: key) { |
|||
D.assert(child != null); |
|||
D.assert(resizeToAvoidBottomInset != null); |
|||
|
|||
this.child = child; |
|||
this.navigationBar = navigationBar; |
|||
this.backgroundColor = backgroundColor; |
|||
this.resizeToAvoidBottomInset = resizeToAvoidBottomInset; |
|||
} |
|||
|
|||
public readonly ObstructingPreferredSizeWidget navigationBar; |
|||
public readonly Widget child; |
|||
public readonly Color backgroundColor; |
|||
public readonly bool resizeToAvoidBottomInset; |
|||
|
|||
|
|||
public override State createState() { |
|||
return new _CupertinoPageScaffoldState(); |
|||
} |
|||
} |
|||
|
|||
class _CupertinoPageScaffoldState : State<CupertinoPageScaffold> { |
|||
public readonly ScrollController _primaryScrollController = new ScrollController(); |
|||
|
|||
void _handleStatusBarTap() { |
|||
// Only act on the scroll controller if it has any attached scroll positions.
|
|||
if (this._primaryScrollController.hasClients) { |
|||
this._primaryScrollController.animateTo( |
|||
0.0f, |
|||
duration: new TimeSpan(0, 0, 0, 0, 500), |
|||
curve: Curves.linearToEaseOut |
|||
); |
|||
} |
|||
} |
|||
|
|||
public override Widget build(BuildContext context) { |
|||
List<Widget> stacked = new List<Widget>(); |
|||
|
|||
Widget paddedContent = this.widget.child; |
|||
|
|||
MediaQueryData existingMediaQuery = MediaQuery.of(context); |
|||
if (this.widget.navigationBar != null) { |
|||
float topPadding = this.widget.navigationBar.preferredSize.height + existingMediaQuery.padding.top; |
|||
|
|||
float bottomPadding = this.widget.resizeToAvoidBottomInset |
|||
? existingMediaQuery.viewInsets.bottom |
|||
: 0.0f; |
|||
|
|||
EdgeInsets newViewInsets = this.widget.resizeToAvoidBottomInset |
|||
? existingMediaQuery.viewInsets.copyWith(bottom: 0.0f) |
|||
: existingMediaQuery.viewInsets; |
|||
|
|||
bool? fullObstruction = |
|||
this.widget.navigationBar.fullObstruction == false |
|||
? CupertinoTheme.of(context).barBackgroundColor.alpha == 0xFF |
|||
: this.widget.navigationBar.fullObstruction; |
|||
|
|||
if (fullObstruction == true) { |
|||
paddedContent = new MediaQuery( |
|||
data: existingMediaQuery |
|||
.removePadding(removeTop: true) |
|||
.copyWith( |
|||
viewInsets: newViewInsets |
|||
), |
|||
child: new Padding( |
|||
padding: EdgeInsets.only(top: topPadding, bottom: bottomPadding), |
|||
child: paddedContent |
|||
) |
|||
); |
|||
} |
|||
else { |
|||
paddedContent = new MediaQuery( |
|||
data: existingMediaQuery.copyWith( |
|||
padding: existingMediaQuery.padding.copyWith( |
|||
top: topPadding |
|||
), |
|||
viewInsets: newViewInsets |
|||
), |
|||
child: new Padding( |
|||
padding: EdgeInsets.only(bottom: bottomPadding), |
|||
child: paddedContent |
|||
) |
|||
); |
|||
} |
|||
} |
|||
|
|||
stacked.Add(new PrimaryScrollController( |
|||
controller: this._primaryScrollController, |
|||
child: paddedContent |
|||
)); |
|||
|
|||
if (this.widget.navigationBar != null) { |
|||
stacked.Add(new Positioned( |
|||
top: 0.0f, |
|||
left: 0.0f, |
|||
right: 0.0f, |
|||
child: this.widget.navigationBar |
|||
)); |
|||
} |
|||
|
|||
stacked.Add(new Positioned( |
|||
top: 0.0f, |
|||
left: 0.0f, |
|||
right: 0.0f, |
|||
height: existingMediaQuery.padding.top, |
|||
child: new GestureDetector( |
|||
onTap: this._handleStatusBarTap |
|||
) |
|||
) |
|||
); |
|||
|
|||
return new DecoratedBox( |
|||
decoration: new BoxDecoration( |
|||
color: this.widget.backgroundColor ?? CupertinoTheme.of(context).scaffoldBackgroundColor |
|||
), |
|||
child: new Stack( |
|||
children: stacked |
|||
) |
|||
); |
|||
} |
|||
} |
|||
|
|||
public abstract class ObstructingPreferredSizeWidget : PreferredSizeWidget { |
|||
|
|||
protected ObstructingPreferredSizeWidget(Key key = null) : base(key: key) {} |
|||
public virtual bool? fullObstruction { get; } |
|||
} |
|||
} |
|
|||
fileFormatVersion: 2 |
|||
guid: c8f7baea91a434b17b549b70613e6976 |
|||
MonoImporter: |
|||
externalObjects: {} |
|||
serializedVersion: 2 |
|||
defaultReferences: [] |
|||
executionOrder: 0 |
|||
icon: {instanceID: 0} |
|||
userData: |
|||
assetBundleName: |
|||
assetBundleVariant: |
|
|||
using System; |
|||
using Unity.UIWidgets.animation; |
|||
using Unity.UIWidgets.async; |
|||
using Unity.UIWidgets.foundation; |
|||
using Unity.UIWidgets.ui; |
|||
using Unity.UIWidgets.widgets; |
|||
|
|||
namespace Unity.UIWidgets.cupertino { |
|||
class CupertinoScrollbarUtils { |
|||
public static Color _kScrollbarColor = new Color(0x99777777); |
|||
public const float _kScrollbarThickness = 2.5f; |
|||
public const float _kScrollbarMainAxisMargin = 4.0f; |
|||
public const float _kScrollbarCrossAxisMargin = 2.5f; |
|||
public const float _kScrollbarMinLength = 36.0f; |
|||
public const float _kScrollbarMinOverscrollLength = 8.0f; |
|||
public static Radius _kScrollbarRadius = Radius.circular(1.25f); |
|||
public static TimeSpan _kScrollbarTimeToFade = new TimeSpan(0, 0, 0, 0, 50); |
|||
public static TimeSpan _kScrollbarFadeDuration = new TimeSpan(0, 0, 0, 0, 250); |
|||
} |
|||
|
|||
public class CupertinoScrollbar : StatefulWidget { |
|||
public CupertinoScrollbar( |
|||
Widget child, |
|||
Key key = null |
|||
) : base(key: key) { |
|||
this.child = child; |
|||
} |
|||
|
|||
public readonly Widget child; |
|||
|
|||
public override State createState() { |
|||
return new _CupertinoScrollbarState(); |
|||
} |
|||
} |
|||
|
|||
class _CupertinoScrollbarState : TickerProviderStateMixin<CupertinoScrollbar> { |
|||
ScrollbarPainter _painter; |
|||
TextDirection _textDirection; |
|||
AnimationController _fadeoutAnimationController; |
|||
Animation<float> _fadeoutOpacityAnimation; |
|||
Timer _fadeoutTimer; |
|||
|
|||
public override void initState() { |
|||
base.initState(); |
|||
this._fadeoutAnimationController = new AnimationController( |
|||
vsync: this, |
|||
duration: CupertinoScrollbarUtils._kScrollbarFadeDuration |
|||
); |
|||
this._fadeoutOpacityAnimation = new CurvedAnimation( |
|||
parent: this._fadeoutAnimationController, |
|||
curve: Curves.fastOutSlowIn |
|||
); |
|||
} |
|||
|
|||
|
|||
public override void didChangeDependencies() { |
|||
base.didChangeDependencies(); |
|||
this._textDirection = Directionality.of(this.context); |
|||
this._painter = this._buildCupertinoScrollbarPainter(); |
|||
} |
|||
|
|||
ScrollbarPainter _buildCupertinoScrollbarPainter() { |
|||
return new ScrollbarPainter( |
|||
color: CupertinoScrollbarUtils._kScrollbarColor, |
|||
textDirection: this._textDirection, |
|||
thickness: CupertinoScrollbarUtils._kScrollbarThickness, |
|||
fadeoutOpacityAnimation: this._fadeoutOpacityAnimation, |
|||
mainAxisMargin: CupertinoScrollbarUtils._kScrollbarMainAxisMargin, |
|||
crossAxisMargin: CupertinoScrollbarUtils._kScrollbarCrossAxisMargin, |
|||
radius: CupertinoScrollbarUtils._kScrollbarRadius, |
|||
minLength: CupertinoScrollbarUtils._kScrollbarMinLength, |
|||
minOverscrollLength: CupertinoScrollbarUtils._kScrollbarMinOverscrollLength |
|||
); |
|||
} |
|||
|
|||
bool _handleScrollNotification(ScrollNotification notification) { |
|||
if (notification is ScrollUpdateNotification || |
|||
notification is OverscrollNotification) { |
|||
if (this._fadeoutAnimationController.status != AnimationStatus.forward) { |
|||
this._fadeoutAnimationController.forward(); |
|||
} |
|||
|
|||
this._fadeoutTimer?.cancel(); |
|||
this._painter.update(notification.metrics, notification.metrics.axisDirection); |
|||
} |
|||
else if (notification is ScrollEndNotification) { |
|||
this._fadeoutTimer?.cancel(); |
|||
this._fadeoutTimer = Window.instance.run(CupertinoScrollbarUtils._kScrollbarTimeToFade, () => { |
|||
this._fadeoutAnimationController.reverse(); |
|||
this._fadeoutTimer = null; |
|||
}); |
|||
} |
|||
|
|||
return false; |
|||
} |
|||
|
|||
|
|||
public override void dispose() { |
|||
this._fadeoutAnimationController.dispose(); |
|||
this._fadeoutTimer?.cancel(); |
|||
this._painter.dispose(); |
|||
base.dispose(); |
|||
} |
|||
|
|||
|
|||
public override Widget build(BuildContext context) { |
|||
return new NotificationListener<ScrollNotification>( |
|||
onNotification: this._handleScrollNotification, |
|||
child: new RepaintBoundary( |
|||
child: new CustomPaint( |
|||
foregroundPainter: this._painter, |
|||
child: new RepaintBoundary( |
|||
child: this.widget.child |
|||
) |
|||
) |
|||
) |
|||
); |
|||
} |
|||
} |
|||
} |
|
|||
fileFormatVersion: 2 |
|||
guid: cd3dad8c870d149cf8c5cbe1b4d1b285 |
|||
MonoImporter: |
|||
externalObjects: {} |
|||
serializedVersion: 2 |
|||
defaultReferences: [] |
|||
executionOrder: 0 |
|||
icon: {instanceID: 0} |
|||
userData: |
|||
assetBundleName: |
|||
assetBundleVariant: |
|
|||
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; |
|||
using UnityEngine; |
|||
using Canvas = Unity.UIWidgets.ui.Canvas; |
|||
using Color = Unity.UIWidgets.ui.Color; |
|||
using Rect = Unity.UIWidgets.ui.Rect; |
|||
|
|||
namespace Unity.UIWidgets.cupertino { |
|||
class SliderUtils { |
|||
public const float _kPadding = 8.0f; |
|||
public static readonly Color _kTrackColor = new Color(0xFFB5B5B5); |
|||
public const float _kSliderHeight = 2.0f * (CupertinoThumbPainter.radius + _kPadding); |
|||
public const float _kSliderWidth = 176.0f; // Matches Material Design slider.
|
|||
public static readonly TimeSpan _kDiscreteTransitionDuration = new TimeSpan(0, 0, 0, 0, 500); |
|||
public const float _kAdjustmentUnit = 0.1f; // Matches iOS implementation of material slider.
|
|||
} |
|||
|
|||
public class CupertinoSlider : StatefulWidget { |
|||
public CupertinoSlider( |
|||
Key key = null, |
|||
float? value = null, |
|||
ValueChanged<float> onChanged = null, |
|||
ValueChanged<float> onChangeStart = null, |
|||
ValueChanged<float> onChangeEnd = null, |
|||
float min = 0.0f, |
|||
float max = 1.0f, |
|||
int? divisions = null, |
|||
Color activeColor = null |
|||
) : base(key: key) { |
|||
D.assert(value != null); |
|||
D.assert(onChanged != null); |
|||
D.assert(min != null); |
|||
D.assert(max != null); |
|||
D.assert(value >= min && value <= max); |
|||
D.assert(divisions == null || divisions > 0); |
|||
this.value = value.Value; |
|||
this.onChanged = onChanged; |
|||
this.onChangeStart = onChangeStart; |
|||
this.onChangeEnd = onChangeEnd; |
|||
this.min = min; |
|||
this.max = max; |
|||
this.divisions = divisions; |
|||
this.activeColor = activeColor; |
|||
} |
|||
|
|||
public readonly float value; |
|||
|
|||
public readonly ValueChanged<float> onChanged; |
|||
|
|||
public readonly ValueChanged<float> onChangeStart; |
|||
|
|||
public readonly ValueChanged<float> onChangeEnd; |
|||
|
|||
public readonly float min; |
|||
|
|||
public readonly float max; |
|||
|
|||
public readonly int? divisions; |
|||
|
|||
public readonly Color activeColor; |
|||
|
|||
public override State createState() { |
|||
return new _CupertinoSliderState(); |
|||
} |
|||
|
|||
public override void debugFillProperties(DiagnosticPropertiesBuilder properties) { |
|||
base.debugFillProperties(properties); |
|||
properties.add(new FloatProperty("value", this.value)); |
|||
properties.add(new FloatProperty("min", this.min)); |
|||
properties.add(new FloatProperty("max", this.max)); |
|||
} |
|||
} |
|||
|
|||
class _CupertinoSliderState : TickerProviderStateMixin<CupertinoSlider> { |
|||
void _handleChanged(float value) { |
|||
D.assert(this.widget.onChanged != null); |
|||
float lerpValue = MathUtils.lerpFloat(this.widget.min, this.widget.max, value); |
|||
if (lerpValue != this.widget.value) { |
|||
this.widget.onChanged(lerpValue); |
|||
} |
|||
} |
|||
|
|||
void _handleDragStart(float value) { |
|||
D.assert(this.widget.onChangeStart != null); |
|||
this.widget.onChangeStart(MathUtils.lerpFloat(this.widget.min, this.widget.max, value)); |
|||
} |
|||
|
|||
void _handleDragEnd(float value) { |
|||
D.assert(this.widget.onChangeEnd != null); |
|||
this.widget.onChangeEnd(MathUtils.lerpFloat(this.widget.min, this.widget.max, value)); |
|||
} |
|||
|
|||
public override Widget build(BuildContext context) { |
|||
return new _CupertinoSliderRenderObjectWidget( |
|||
value: (this.widget.value - this.widget.min) / (this.widget.max - this.widget.min), |
|||
divisions: this.widget.divisions, |
|||
activeColor: this.widget.activeColor ?? CupertinoTheme.of(context).primaryColor, |
|||
onChanged: this.widget.onChanged != null ? (ValueChanged<float>) this._handleChanged : null, |
|||
onChangeStart: this.widget.onChangeStart != null ? (ValueChanged<float>) this._handleDragStart : null, |
|||
onChangeEnd: this.widget.onChangeEnd != null ? (ValueChanged<float>) this._handleDragEnd : null, |
|||
vsync: this |
|||
); |
|||
} |
|||
} |
|||
|
|||
class _CupertinoSliderRenderObjectWidget : LeafRenderObjectWidget { |
|||
public _CupertinoSliderRenderObjectWidget( |
|||
Key key = null, |
|||
float? value = null, |
|||
int? divisions = null, |
|||
Color activeColor = null, |
|||
ValueChanged<float> onChanged = null, |
|||
ValueChanged<float> onChangeStart = null, |
|||
ValueChanged<float> onChangeEnd = null, |
|||
TickerProvider vsync = null |
|||
) : base(key: key) { |
|||
this.value = value; |
|||
this.divisions = divisions; |
|||
this.activeColor = activeColor; |
|||
this.onChanged = onChanged; |
|||
this.onChangeStart = onChangeStart; |
|||
this.onChangeEnd = onChangeEnd; |
|||
this.vsync = vsync; |
|||
} |
|||
|
|||
public readonly float? value; |
|||
public readonly int? divisions; |
|||
public readonly Color activeColor; |
|||
public readonly ValueChanged<float> onChanged; |
|||
public readonly ValueChanged<float> onChangeStart; |
|||
public readonly ValueChanged<float> onChangeEnd; |
|||
public readonly TickerProvider vsync; |
|||
|
|||
public override RenderObject createRenderObject(BuildContext context) { |
|||
return new _RenderCupertinoSlider( |
|||
value: this.value ?? 0.0f, |
|||
divisions: this.divisions, |
|||
activeColor: this.activeColor, |
|||
onChanged: this.onChanged, |
|||
onChangeStart: this.onChangeStart, |
|||
onChangeEnd: this.onChangeEnd, |
|||
vsync: this.vsync |
|||
); |
|||
} |
|||
|
|||
public override void updateRenderObject(BuildContext context, RenderObject _renderObject) { |
|||
_RenderCupertinoSlider renderObject = _renderObject as _RenderCupertinoSlider; |
|||
renderObject.value = this.value ?? 0.0f; |
|||
renderObject.divisions = this.divisions ?? 0; |
|||
renderObject.activeColor = this.activeColor; |
|||
renderObject.onChanged = this.onChanged; |
|||
renderObject.onChangeStart = this.onChangeStart; |
|||
renderObject.onChangeEnd = this.onChangeEnd; |
|||
} |
|||
} |
|||
|
|||
class _RenderCupertinoSlider : RenderConstrainedBox { |
|||
public _RenderCupertinoSlider( |
|||
float value, |
|||
int? divisions = null, |
|||
Color activeColor = null, |
|||
ValueChanged<float> onChanged = null, |
|||
ValueChanged<float> onChangeStart = null, |
|||
ValueChanged<float> onChangeEnd = null, |
|||
TickerProvider vsync = null |
|||
) : base(additionalConstraints: BoxConstraints.tightFor(width: SliderUtils._kSliderWidth, |
|||
height: SliderUtils._kSliderHeight)) { |
|||
D.assert(value != null && value >= 0.0f && value <= 1.0f); |
|||
this._value = value; |
|||
this._divisions = divisions; |
|||
this._activeColor = activeColor; |
|||
this._onChanged = onChanged; |
|||
this._drag = new HorizontalDragGestureRecognizer(); |
|||
this._drag.onStart = this._handleDragStart; |
|||
this._drag.onUpdate = this._handleDragUpdate; |
|||
this._drag.onEnd = this._handleDragEnd; |
|||
this._position = new AnimationController( |
|||
value: value, |
|||
duration: SliderUtils._kDiscreteTransitionDuration, |
|||
vsync: vsync |
|||
); |
|||
this._position.addListener(this.markNeedsPaint); |
|||
} |
|||
|
|||
public float value { |
|||
get { return this._value; } |
|||
set { |
|||
D.assert(value != null && value >= 0.0f && value <= 1.0f); |
|||
if (value == this._value) { |
|||
return; |
|||
} |
|||
|
|||
this._value = value; |
|||
if (this.divisions != null) { |
|||
this._position.animateTo(value, curve: Curves.fastOutSlowIn); |
|||
} |
|||
else { |
|||
this._position.setValue(value); |
|||
} |
|||
} |
|||
} |
|||
|
|||
float _value; |
|||
|
|||
public int? divisions { |
|||
get { return this._divisions; } |
|||
set { |
|||
if (value == this._divisions) { |
|||
return; |
|||
} |
|||
|
|||
this._divisions = value; |
|||
this.markNeedsPaint(); |
|||
} |
|||
} |
|||
|
|||
int? _divisions; |
|||
|
|||
public Color activeColor { |
|||
get { return this._activeColor; } |
|||
set { |
|||
if (value == this._activeColor) { |
|||
return; |
|||
} |
|||
|
|||
this._activeColor = value; |
|||
this.markNeedsPaint(); |
|||
} |
|||
} |
|||
|
|||
Color _activeColor; |
|||
|
|||
public ValueChanged<float> onChanged { |
|||
get { return this._onChanged; } |
|||
set { |
|||
if (value == this._onChanged) { |
|||
return; |
|||
} |
|||
|
|||
this._onChanged = value; |
|||
} |
|||
} |
|||
|
|||
ValueChanged<float> _onChanged; |
|||
|
|||
public ValueChanged<float> onChangeStart; |
|||
public ValueChanged<float> onChangeEnd; |
|||
|
|||
|
|||
AnimationController _position; |
|||
|
|||
HorizontalDragGestureRecognizer _drag; |
|||
float _currentDragValue = 0.0f; |
|||
|
|||
float _discretizedCurrentDragValue { |
|||
get { |
|||
float dragValue = this._currentDragValue.clamp(0.0f, 1.0f); |
|||
if (this.divisions != null) { |
|||
dragValue = Mathf.Round(dragValue * this.divisions.Value) / this.divisions.Value; |
|||
} |
|||
|
|||
return dragValue; |
|||
} |
|||
} |
|||
|
|||
public float _trackLeft { |
|||
get { return SliderUtils._kPadding; } |
|||
} |
|||
|
|||
public float _trackRight { |
|||
get { return this.size.width - SliderUtils._kPadding; } |
|||
} |
|||
|
|||
float _thumbCenter { |
|||
get { |
|||
float visualPosition = this._value; |
|||
|
|||
return MathUtils.lerpFloat(this._trackLeft + CupertinoThumbPainter.radius, |
|||
this._trackRight - CupertinoThumbPainter.radius, |
|||
visualPosition); |
|||
} |
|||
} |
|||
|
|||
public bool isInteractive { |
|||
get { return this.onChanged != null; } |
|||
} |
|||
|
|||
void _handleDragStart(DragStartDetails details) { |
|||
this._startInteraction(details.globalPosition); |
|||
} |
|||
|
|||
void _handleDragUpdate(DragUpdateDetails details) { |
|||
if (this.isInteractive) { |
|||
float extent = Mathf.Max(SliderUtils._kPadding, |
|||
this.size.width - 2.0f * (SliderUtils._kPadding + CupertinoThumbPainter.radius)); |
|||
float? valueDelta = details.primaryDelta / extent; |
|||
this._currentDragValue += valueDelta ?? 0.0f; |
|||
|
|||
this.onChanged(this._discretizedCurrentDragValue); |
|||
} |
|||
} |
|||
|
|||
void _handleDragEnd(DragEndDetails details) { |
|||
this._endInteraction(); |
|||
} |
|||
|
|||
void _startInteraction(Offset globalPosition) { |
|||
if (this.isInteractive) { |
|||
if (this.onChangeStart != null) { |
|||
this.onChangeStart(this._discretizedCurrentDragValue); |
|||
} |
|||
|
|||
this._currentDragValue = this._value; |
|||
this.onChanged(this._discretizedCurrentDragValue); |
|||
} |
|||
} |
|||
|
|||
void _endInteraction() { |
|||
if (this.onChangeEnd != null) { |
|||
this.onChangeEnd(this._discretizedCurrentDragValue); |
|||
} |
|||
|
|||
this._currentDragValue = 0.0f; |
|||
} |
|||
|
|||
protected override bool hitTestSelf(Offset position) { |
|||
return (position.dx - this._thumbCenter).abs() < CupertinoThumbPainter.radius + SliderUtils._kPadding; |
|||
} |
|||
|
|||
public override void handleEvent(PointerEvent e, HitTestEntry entry) { |
|||
D.assert(this.debugHandleEvent(e, entry)); |
|||
if (e is PointerDownEvent pointerDownEvent && this.isInteractive) { |
|||
this._drag.addPointer(pointerDownEvent); |
|||
} |
|||
} |
|||
|
|||
CupertinoThumbPainter _thumbPainter = new CupertinoThumbPainter(); |
|||
|
|||
public override |
|||
void paint(PaintingContext context, Offset offset) { |
|||
float visualPosition; |
|||
Color leftColor; |
|||
Color rightColor; |
|||
visualPosition = this._position.value; |
|||
leftColor = SliderUtils._kTrackColor; |
|||
rightColor = this._activeColor; |
|||
|
|||
float trackCenter = offset.dy + this.size.height / 2.0f; |
|||
float trackLeft = offset.dx + this._trackLeft; |
|||
float trackTop = trackCenter - 1.0f; |
|||
float trackBottom = trackCenter + 1.0f; |
|||
float trackRight = offset.dx + this._trackRight; |
|||
float trackActive = offset.dx + this._thumbCenter; |
|||
|
|||
Canvas canvas = context.canvas; |
|||
|
|||
if (visualPosition > 0.0f) { |
|||
Paint paint = new Paint(); |
|||
paint.color = rightColor; |
|||
canvas.drawRRect(RRect.fromLTRBXY(trackLeft, trackTop, trackActive, trackBottom, 1.0f, 1.0f), paint); |
|||
} |
|||
|
|||
if (visualPosition < 1.0f) { |
|||
Paint paint = new Paint(); |
|||
paint.color = leftColor; |
|||
canvas.drawRRect(RRect.fromLTRBXY(trackActive, trackTop, trackRight, trackBottom, 1.0f, 1.0f), paint); |
|||
} |
|||
|
|||
Offset thumbCenter = new Offset(trackActive, trackCenter); |
|||
this._thumbPainter.paint(canvas, |
|||
Rect.fromCircle(center: thumbCenter, radius: CupertinoThumbPainter.radius)); |
|||
} |
|||
} |
|||
} |
|
|||
fileFormatVersion: 2 |
|||
guid: 9d6aaa856d879be40833f2ae7ec103ac |
|||
MonoImporter: |
|||
externalObjects: {} |
|||
serializedVersion: 2 |
|||
defaultReferences: [] |
|||
executionOrder: 0 |
|||
icon: {instanceID: 0} |
|||
userData: |
|||
assetBundleName: |
|||
assetBundleVariant: |
|
|||
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; |
|||
using UnityEngine; |
|||
using Canvas = Unity.UIWidgets.ui.Canvas; |
|||
using Color = Unity.UIWidgets.ui.Color; |
|||
using Rect = Unity.UIWidgets.ui.Rect; |
|||
|
|||
namespace Unity.UIWidgets.cupertino { |
|||
class CupertinoSwitchUtils { |
|||
public const float _kTrackWidth = 51.0f; |
|||
public const float _kTrackHeight = 31.0f; |
|||
public const float _kTrackRadius = _kTrackHeight / 2.0f; |
|||
public const float _kTrackInnerStart = _kTrackHeight / 2.0f; |
|||
public const float _kTrackInnerEnd = _kTrackWidth - _kTrackInnerStart; |
|||
public const float _kTrackInnerLength = _kTrackInnerEnd - _kTrackInnerStart; |
|||
public const float _kSwitchWidth = 59.0f; |
|||
public const float _kSwitchHeight = 39.0f; |
|||
public const float _kCupertinoSwitchDisabledOpacity = 0.5f; |
|||
public static Color _kTrackColor = CupertinoColors.lightBackgroundGray; |
|||
public static TimeSpan _kReactionDuration = new TimeSpan(0, 0, 0, 0, 300); |
|||
public static TimeSpan _kToggleDuration = new TimeSpan(0, 0, 0, 0, 200); |
|||
} |
|||
|
|||
public class CupertinoSwitch : StatefulWidget { |
|||
public CupertinoSwitch( |
|||
bool value, |
|||
ValueChanged<bool> onChanged, |
|||
Key key = null, |
|||
Color activeColor = null, |
|||
DragStartBehavior dragStartBehavior = DragStartBehavior.start |
|||
) : |
|||
base(key: key) { |
|||
D.assert(value != null); |
|||
D.assert(dragStartBehavior != null); |
|||
|
|||
this.value = value; |
|||
this.onChanged = onChanged; |
|||
this.activeColor = activeColor; |
|||
this.dragStartBehavior = dragStartBehavior; |
|||
} |
|||
|
|||
public readonly bool value; |
|||
|
|||
public readonly ValueChanged<bool> onChanged; |
|||
|
|||
public readonly Color activeColor; |
|||
|
|||
public readonly DragStartBehavior dragStartBehavior; |
|||
|
|||
public override State createState() { |
|||
return new _CupertinoSwitchState(); |
|||
} |
|||
|
|||
public override void debugFillProperties(DiagnosticPropertiesBuilder properties) { |
|||
base.debugFillProperties(properties); |
|||
properties.add(new FlagProperty("value", value: this.value, ifTrue: "on", ifFalse: "off", showName: true)); |
|||
properties.add(new ObjectFlagProperty<ValueChanged<bool>>("onChanged", this.onChanged, ifNull: "disabled")); |
|||
} |
|||
} |
|||
|
|||
class _CupertinoSwitchState : TickerProviderStateMixin<CupertinoSwitch> { |
|||
public override Widget build(BuildContext context) { |
|||
return new Opacity( |
|||
opacity: this.widget.onChanged == null ? CupertinoSwitchUtils._kCupertinoSwitchDisabledOpacity : 1.0f, |
|||
child: new _CupertinoSwitchRenderObjectWidget( |
|||
value: this.widget.value, |
|||
activeColor: this.widget.activeColor ?? CupertinoColors.activeGreen, |
|||
onChanged: this.widget.onChanged, |
|||
vsync: this, |
|||
dragStartBehavior: this.widget.dragStartBehavior |
|||
) |
|||
); |
|||
} |
|||
} |
|||
|
|||
class _CupertinoSwitchRenderObjectWidget : LeafRenderObjectWidget { |
|||
public _CupertinoSwitchRenderObjectWidget( |
|||
Key key = null, |
|||
bool value = false, |
|||
Color activeColor = null, |
|||
ValueChanged<bool> onChanged = null, |
|||
TickerProvider vsync = null, |
|||
DragStartBehavior dragStartBehavior = DragStartBehavior.start |
|||
) : base(key: key) { |
|||
this.value = value; |
|||
this.activeColor = activeColor; |
|||
this.onChanged = onChanged; |
|||
this.vsync = vsync; |
|||
this.dragStartBehavior = dragStartBehavior; |
|||
} |
|||
|
|||
public readonly bool value; |
|||
public readonly Color activeColor; |
|||
public readonly ValueChanged<bool> onChanged; |
|||
public readonly TickerProvider vsync; |
|||
public readonly DragStartBehavior dragStartBehavior; |
|||
|
|||
public override RenderObject createRenderObject(BuildContext context) { |
|||
return new _RenderCupertinoSwitch( |
|||
value: this.value, |
|||
activeColor: this.activeColor, |
|||
onChanged: this.onChanged, |
|||
textDirection: Directionality.of(context), |
|||
vsync: this.vsync, |
|||
dragStartBehavior: this.dragStartBehavior |
|||
); |
|||
} |
|||
|
|||
public override void updateRenderObject(BuildContext context, RenderObject renderObject) { |
|||
var _renderObject = renderObject as _RenderCupertinoSwitch; |
|||
_renderObject.value = this.value; |
|||
_renderObject.activeColor = this.activeColor; |
|||
_renderObject.onChanged = this.onChanged; |
|||
_renderObject.textDirection = Directionality.of(context); |
|||
_renderObject.vsync = this.vsync; |
|||
_renderObject.dragStartBehavior = this.dragStartBehavior; |
|||
} |
|||
} |
|||
|
|||
|
|||
class _RenderCupertinoSwitch : RenderConstrainedBox { |
|||
public _RenderCupertinoSwitch( |
|||
bool value, |
|||
Color activeColor, |
|||
TextDirection textDirection, |
|||
TickerProvider vsync, |
|||
ValueChanged<bool> onChanged = null, |
|||
DragStartBehavior dragStartBehavior = DragStartBehavior.start |
|||
) : base(additionalConstraints: BoxConstraints.tightFor( |
|||
width: CupertinoSwitchUtils._kSwitchWidth, |
|||
height: CupertinoSwitchUtils._kSwitchHeight) |
|||
) { |
|||
D.assert(value != null); |
|||
D.assert(activeColor != null); |
|||
D.assert(vsync != null); |
|||
this._value = value; |
|||
this._activeColor = activeColor; |
|||
this._onChanged = onChanged; |
|||
this._textDirection = textDirection; |
|||
this._vsync = vsync; |
|||
|
|||
this._tap = new TapGestureRecognizer() { |
|||
onTapDown = this._handleTapDown, |
|||
onTap = this._handleTap, |
|||
onTapUp = this._handleTapUp, |
|||
onTapCancel = this._handleTapCancel, |
|||
}; |
|||
|
|||
this._drag = new HorizontalDragGestureRecognizer() { |
|||
onStart = this._handleDragStart, |
|||
onUpdate = this._handleDragUpdate, |
|||
onEnd = this._handleDragEnd, |
|||
dragStartBehavior = dragStartBehavior |
|||
}; |
|||
|
|||
this._positionController = new AnimationController( |
|||
duration: CupertinoSwitchUtils._kToggleDuration, |
|||
value: value ? 1.0f : 0.0f, |
|||
vsync: vsync |
|||
); |
|||
this._position = new CurvedAnimation( |
|||
parent: this._positionController, |
|||
curve: Curves.linear |
|||
); |
|||
this._position.addListener(this.markNeedsPaint); |
|||
this._position.addStatusListener(this._handlePositionStateChanged); |
|||
|
|||
this._reactionController = new AnimationController( |
|||
duration: CupertinoSwitchUtils._kReactionDuration, |
|||
vsync: vsync |
|||
); |
|||
this._reaction = new CurvedAnimation( |
|||
parent: this._reactionController, |
|||
curve: Curves.ease |
|||
); |
|||
this._reaction.addListener(this.markNeedsPaint); |
|||
} |
|||
|
|||
AnimationController _positionController; |
|||
CurvedAnimation _position; |
|||
AnimationController _reactionController; |
|||
Animation<float> _reaction; |
|||
|
|||
public bool value { |
|||
get { return this._value; } |
|||
set { |
|||
D.assert(value != null); |
|||
if (value == this._value) { |
|||
return; |
|||
} |
|||
|
|||
this._value = value; |
|||
// this.markNeedsSemanticsUpdate();
|
|||
this._position.curve = Curves.ease; |
|||
this._position.reverseCurve = Curves.ease.flipped; |
|||
if (value) { |
|||
this._positionController.forward(); |
|||
} |
|||
else { |
|||
this._positionController.reverse(); |
|||
} |
|||
} |
|||
} |
|||
|
|||
bool _value; |
|||
|
|||
public TickerProvider vsync { |
|||
get { return this._vsync; } |
|||
set { |
|||
D.assert(value != null); |
|||
if (value == this._vsync) { |
|||
return; |
|||
} |
|||
|
|||
this._vsync = value; |
|||
this._positionController.resync(this.vsync); |
|||
this._reactionController.resync(this.vsync); |
|||
} |
|||
} |
|||
|
|||
TickerProvider _vsync; |
|||
|
|||
public Color activeColor { |
|||
get { return this._activeColor; } |
|||
set { |
|||
D.assert(value != null); |
|||
if (value == this._activeColor) { |
|||
return; |
|||
} |
|||
|
|||
this._activeColor = value; |
|||
this.markNeedsPaint(); |
|||
} |
|||
} |
|||
|
|||
Color _activeColor; |
|||
|
|||
public ValueChanged<bool> onChanged { |
|||
get { return this._onChanged; } |
|||
set { |
|||
if (value == this._onChanged) { |
|||
return; |
|||
} |
|||
|
|||
bool wasInteractive = this.isInteractive; |
|||
this._onChanged = value; |
|||
if (wasInteractive != this.isInteractive) { |
|||
this.markNeedsPaint(); |
|||
} |
|||
} |
|||
} |
|||
|
|||
ValueChanged<bool> _onChanged; |
|||
|
|||
public TextDirection textDirection { |
|||
get { return this._textDirection; } |
|||
set { |
|||
D.assert(value != null); |
|||
if (this._textDirection == value) { |
|||
return; |
|||
} |
|||
|
|||
this._textDirection = value; |
|||
this.markNeedsPaint(); |
|||
} |
|||
} |
|||
|
|||
TextDirection _textDirection; |
|||
|
|||
|
|||
public DragStartBehavior dragStartBehavior { |
|||
get { return this._drag.dragStartBehavior; } |
|||
set { |
|||
D.assert(value != null); |
|||
if (this._drag.dragStartBehavior == value) { |
|||
return; |
|||
} |
|||
|
|||
this._drag.dragStartBehavior = value; |
|||
} |
|||
} |
|||
|
|||
public bool isInteractive { |
|||
get { return this.onChanged != null; } |
|||
} |
|||
|
|||
TapGestureRecognizer _tap; |
|||
HorizontalDragGestureRecognizer _drag; |
|||
|
|||
public override void attach(object _owner) { |
|||
base.attach(_owner); |
|||
if (this.value) { |
|||
this._positionController.forward(); |
|||
} |
|||
else { |
|||
this._positionController.reverse(); |
|||
} |
|||
|
|||
if (this.isInteractive) { |
|||
switch (this._reactionController.status) { |
|||
case AnimationStatus.forward: |
|||
this._reactionController.forward(); |
|||
break; |
|||
case AnimationStatus.reverse: |
|||
this._reactionController.reverse(); |
|||
break; |
|||
case AnimationStatus.dismissed: |
|||
case AnimationStatus.completed: |
|||
break; |
|||
} |
|||
} |
|||
} |
|||
|
|||
public override void detach() { |
|||
this._positionController.stop(); |
|||
this._reactionController.stop(); |
|||
base.detach(); |
|||
} |
|||
|
|||
void _handlePositionStateChanged(AnimationStatus status) { |
|||
if (this.isInteractive) { |
|||
if (status == AnimationStatus.completed && !this._value) { |
|||
this.onChanged(true); |
|||
} |
|||
else if (status == AnimationStatus.dismissed && this._value) { |
|||
this.onChanged(false); |
|||
} |
|||
} |
|||
} |
|||
|
|||
void _handleTapDown(TapDownDetails details) { |
|||
if (this.isInteractive) { |
|||
this._reactionController.forward(); |
|||
} |
|||
} |
|||
|
|||
void _handleTap() { |
|||
if (this.isInteractive) { |
|||
this.onChanged(!this._value); |
|||
this._emitVibration(); |
|||
} |
|||
} |
|||
|
|||
void _handleTapUp(TapUpDetails details) { |
|||
if (this.isInteractive) { |
|||
this._reactionController.reverse(); |
|||
} |
|||
} |
|||
|
|||
void _handleTapCancel() { |
|||
if (this.isInteractive) { |
|||
this._reactionController.reverse(); |
|||
} |
|||
} |
|||
|
|||
void _handleDragStart(DragStartDetails details) { |
|||
if (this.isInteractive) { |
|||
this._reactionController.forward(); |
|||
this._emitVibration(); |
|||
} |
|||
} |
|||
|
|||
void _handleDragUpdate(DragUpdateDetails details) { |
|||
if (this.isInteractive) { |
|||
this._position.curve = null; |
|||
this._position.reverseCurve = null; |
|||
float delta = details.primaryDelta / CupertinoSwitchUtils._kTrackInnerLength ?? 0f; |
|||
|
|||
this._positionController.setValue(this._positionController.value + delta); |
|||
|
|||
// switch (this.textDirection) {
|
|||
// case TextDirection.rtl:
|
|||
// this._positionController.setValue(this._positionController.value - delta);
|
|||
// break;
|
|||
// case TextDirection.ltr:
|
|||
// this._positionController.setValue(this._positionController.value + delta);
|
|||
// break;
|
|||
// }
|
|||
} |
|||
} |
|||
|
|||
void _handleDragEnd(DragEndDetails details) { |
|||
if (this._position.value >= 0.5) { |
|||
this._positionController.forward(); |
|||
} |
|||
else { |
|||
this._positionController.reverse(); |
|||
} |
|||
|
|||
this._reactionController.reverse(); |
|||
} |
|||
|
|||
void _emitVibration() { |
|||
// switch (Platform defaultTargetPlatform) {
|
|||
// case TargetPlatform.iOS:
|
|||
// HapticFeedback.lightImpact();
|
|||
// break;
|
|||
// case TargetPlatform.fuchsia:
|
|||
// case TargetPlatform.android:
|
|||
// break;
|
|||
// }
|
|||
return; |
|||
} |
|||
|
|||
protected override bool hitTestSelf(Offset position) { |
|||
return true; |
|||
} |
|||
|
|||
public override void handleEvent(PointerEvent evt, HitTestEntry entry) { |
|||
D.assert(this.debugHandleEvent(evt, entry)); |
|||
if (evt is PointerDownEvent && this.isInteractive) { |
|||
this._drag.addPointer(evt as PointerDownEvent); |
|||
this._tap.addPointer(evt as PointerDownEvent); |
|||
} |
|||
} |
|||
|
|||
// public override void describeSemanticsConfiguration(SemanticsConfiguration config) {
|
|||
// base.describeSemanticsConfiguration(config);
|
|||
//
|
|||
// if (isInteractive)
|
|||
// config.onTap = _handleTap;
|
|||
//
|
|||
// config.isEnabled = isInteractive;
|
|||
// config.isToggled = _value;
|
|||
// }
|
|||
|
|||
public readonly CupertinoThumbPainter _thumbPainter = new CupertinoThumbPainter(); |
|||
|
|||
public override void paint(PaintingContext context, Offset offset) { |
|||
Canvas canvas = context.canvas; |
|||
|
|||
float currentValue = this._position.value; |
|||
float currentReactionValue = this._reaction.value; |
|||
|
|||
float visualPosition = 0f; |
|||
switch (this.textDirection) { |
|||
case TextDirection.rtl: |
|||
visualPosition = 1.0f - currentValue; |
|||
break; |
|||
case TextDirection.ltr: |
|||
visualPosition = currentValue; |
|||
break; |
|||
} |
|||
|
|||
Color trackColor = this._value ? this.activeColor : CupertinoSwitchUtils._kTrackColor; |
|||
float borderThickness = |
|||
1.5f + (CupertinoSwitchUtils._kTrackRadius - 1.5f) * Mathf.Max(currentReactionValue, currentValue); |
|||
|
|||
Paint paint = new Paint(); |
|||
paint.color = trackColor; |
|||
|
|||
Rect trackRect = Rect.fromLTWH( |
|||
offset.dx + (this.size.width - CupertinoSwitchUtils._kTrackWidth) / 2.0f, |
|||
offset.dy + (this.size.height - CupertinoSwitchUtils._kTrackHeight) / 2.0f, |
|||
CupertinoSwitchUtils._kTrackWidth, |
|||
CupertinoSwitchUtils._kTrackHeight |
|||
); |
|||
RRect outerRRect = RRect.fromRectAndRadius(trackRect, Radius.circular(CupertinoSwitchUtils |
|||
._kTrackRadius)); |
|||
RRect innerRRect = RRect.fromRectAndRadius(trackRect.deflate(borderThickness), Radius.circular |
|||
(CupertinoSwitchUtils._kTrackRadius)); |
|||
canvas.drawDRRect(outerRRect, innerRRect, paint); |
|||
|
|||
float currentThumbExtension = CupertinoThumbPainter.extension * currentReactionValue; |
|||
float thumbLeft = MathUtils.lerpFloat( |
|||
trackRect.left + CupertinoSwitchUtils._kTrackInnerStart - CupertinoThumbPainter.radius, |
|||
trackRect.left + CupertinoSwitchUtils._kTrackInnerEnd - CupertinoThumbPainter.radius - |
|||
currentThumbExtension, |
|||
visualPosition |
|||
); |
|||
float thumbRight = MathUtils.lerpFloat( |
|||
trackRect.left + CupertinoSwitchUtils._kTrackInnerStart + CupertinoThumbPainter.radius + |
|||
currentThumbExtension, |
|||
trackRect.left + CupertinoSwitchUtils._kTrackInnerEnd + CupertinoThumbPainter.radius, |
|||
visualPosition |
|||
); |
|||
float thumbCenterY = offset.dy + this.size.height / 2.0f; |
|||
|
|||
this._thumbPainter.paint(canvas, Rect.fromLTRB( |
|||
thumbLeft, |
|||
thumbCenterY - CupertinoThumbPainter.radius, |
|||
thumbRight, |
|||
thumbCenterY + CupertinoThumbPainter.radius |
|||
)); |
|||
} |
|||
|
|||
|
|||
public override void debugFillProperties(DiagnosticPropertiesBuilder description) { |
|||
base.debugFillProperties(description); |
|||
description.add( |
|||
new FlagProperty("value", value: this.value, ifTrue: "checked", ifFalse: "unchecked", showName: true)); |
|||
description.add(new FlagProperty("isInteractive", value: this.isInteractive, ifTrue: "enabled", |
|||
ifFalse: "disabled", |
|||
showName: true, defaultValue: true)); |
|||
} |
|||
} |
|||
} |
|
|||
fileFormatVersion: 2 |
|||
guid: 4eec4759a3c0145a88e1cff304d7400b |
|||
MonoImporter: |
|||
externalObjects: {} |
|||
serializedVersion: 2 |
|||
defaultReferences: [] |
|||
executionOrder: 0 |
|||
icon: {instanceID: 0} |
|||
userData: |
|||
assetBundleName: |
|||
assetBundleVariant: |
|
|||
using System.Collections.Generic; |
|||
using System.Linq; |
|||
using Unity.UIWidgets.foundation; |
|||
using Unity.UIWidgets.painting; |
|||
using Unity.UIWidgets.rendering; |
|||
using Unity.UIWidgets.ui; |
|||
using Unity.UIWidgets.widgets; |
|||
|
|||
namespace Unity.UIWidgets.cupertino { |
|||
public class CupertinoTabScaffold : StatefulWidget { |
|||
public CupertinoTabScaffold( |
|||
Key key = null, |
|||
CupertinoTabBar tabBar = null, |
|||
IndexedWidgetBuilder tabBuilder = null, |
|||
Color backgroundColor = null, |
|||
bool resizeToAvoidBottomInset = true |
|||
) : base(key: key) { |
|||
D.assert(tabBar != null); |
|||
D.assert(tabBuilder != null); |
|||
this.tabBar = tabBar; |
|||
this.tabBuilder = tabBuilder; |
|||
this.backgroundColor = backgroundColor; |
|||
this.resizeToAvoidBottomInset = resizeToAvoidBottomInset; |
|||
} |
|||
|
|||
|
|||
public readonly CupertinoTabBar tabBar; |
|||
|
|||
public readonly IndexedWidgetBuilder tabBuilder; |
|||
|
|||
public readonly Color backgroundColor; |
|||
|
|||
public readonly bool resizeToAvoidBottomInset; |
|||
|
|||
public override State createState() { |
|||
return new _CupertinoTabScaffoldState(); |
|||
} |
|||
} |
|||
|
|||
class _CupertinoTabScaffoldState : State<CupertinoTabScaffold> { |
|||
int _currentPage; |
|||
|
|||
public override void initState() { |
|||
base.initState(); |
|||
this._currentPage = this.widget.tabBar.currentIndex; |
|||
} |
|||
|
|||
public override void didUpdateWidget(StatefulWidget _oldWidget) { |
|||
CupertinoTabScaffold oldWidget = _oldWidget as CupertinoTabScaffold; |
|||
base.didUpdateWidget(oldWidget); |
|||
if (this._currentPage >= this.widget.tabBar.items.Count) { |
|||
this._currentPage = this.widget.tabBar.items.Count - 1; |
|||
D.assert(this._currentPage >= 0, |
|||
() => "CupertinoTabBar is expected to keep at least 2 tabs after updating" |
|||
); |
|||
} |
|||
|
|||
if (this.widget.tabBar.currentIndex != oldWidget.tabBar.currentIndex) { |
|||
this._currentPage = this.widget.tabBar.currentIndex; |
|||
} |
|||
} |
|||
|
|||
public override Widget build(BuildContext context) { |
|||
List<Widget> stacked = new List<Widget> { }; |
|||
|
|||
MediaQueryData existingMediaQuery = MediaQuery.of(context); |
|||
MediaQueryData newMediaQuery = MediaQuery.of(context); |
|||
|
|||
Widget content = new _TabSwitchingView( |
|||
currentTabIndex: this._currentPage, |
|||
tabNumber: this.widget.tabBar.items.Count, |
|||
tabBuilder: this.widget.tabBuilder |
|||
); |
|||
EdgeInsets contentPadding = EdgeInsets.zero; |
|||
|
|||
if (this.widget.resizeToAvoidBottomInset) { |
|||
newMediaQuery = newMediaQuery.removeViewInsets(removeBottom: true); |
|||
contentPadding = EdgeInsets.only(bottom: existingMediaQuery.viewInsets.bottom); |
|||
} |
|||
|
|||
if (this.widget.tabBar != null && |
|||
(!this.widget.resizeToAvoidBottomInset || |
|||
this.widget.tabBar.preferredSize.height > existingMediaQuery.viewInsets.bottom)) { |
|||
float bottomPadding = this.widget.tabBar.preferredSize.height + existingMediaQuery.padding.bottom; |
|||
|
|||
if (this.widget.tabBar.opaque(context)) { |
|||
contentPadding = EdgeInsets.only(bottom: bottomPadding); |
|||
} |
|||
else { |
|||
newMediaQuery = newMediaQuery.copyWith( |
|||
padding: newMediaQuery.padding.copyWith( |
|||
bottom: bottomPadding |
|||
) |
|||
); |
|||
} |
|||
} |
|||
|
|||
content = new MediaQuery( |
|||
data: newMediaQuery, |
|||
child: new Padding( |
|||
padding: contentPadding, |
|||
child: content |
|||
) |
|||
); |
|||
|
|||
stacked.Add(content); |
|||
|
|||
if (this.widget.tabBar != null) { |
|||
stacked.Add(new Align( |
|||
alignment: Alignment.bottomCenter, |
|||
child: this.widget.tabBar.copyWith( |
|||
currentIndex: this._currentPage, |
|||
onTap: (int newIndex) => { |
|||
this.setState(() => { this._currentPage = newIndex; }); |
|||
if (this.widget.tabBar.onTap != null) { |
|||
this.widget.tabBar.onTap(newIndex); |
|||
} |
|||
} |
|||
) |
|||
)); |
|||
} |
|||
|
|||
return new DecoratedBox( |
|||
decoration: new BoxDecoration( |
|||
color: this.widget.backgroundColor ?? CupertinoTheme.of(context).scaffoldBackgroundColor |
|||
), |
|||
child: new Stack( |
|||
children: stacked |
|||
) |
|||
); |
|||
} |
|||
} |
|||
|
|||
class _TabSwitchingView : StatefulWidget { |
|||
public _TabSwitchingView( |
|||
int currentTabIndex, |
|||
int tabNumber, |
|||
IndexedWidgetBuilder tabBuilder |
|||
) { |
|||
D.assert(currentTabIndex != null); |
|||
D.assert(tabNumber != null && tabNumber > 0); |
|||
D.assert(tabBuilder != null); |
|||
} |
|||
|
|||
public readonly int currentTabIndex; |
|||
public readonly int tabNumber; |
|||
public readonly IndexedWidgetBuilder tabBuilder; |
|||
|
|||
public override State createState() { |
|||
return new _TabSwitchingViewState(); |
|||
} |
|||
} |
|||
|
|||
class _TabSwitchingViewState : State<_TabSwitchingView> { |
|||
List<Widget> tabs; |
|||
List<FocusScopeNode> tabFocusNodes; |
|||
|
|||
public override void initState() { |
|||
base.initState(); |
|||
this.tabs = new List<Widget>(this.widget.tabNumber); |
|||
this.tabFocusNodes = Enumerable.Repeat(new FocusScopeNode(), this.widget.tabNumber).ToList(); |
|||
} |
|||
|
|||
public override void didChangeDependencies() { |
|||
base.didChangeDependencies(); |
|||
this._focusActiveTab(); |
|||
} |
|||
|
|||
public override void didUpdateWidget(StatefulWidget _oldWidget) { |
|||
_TabSwitchingView oldWidget = _oldWidget as _TabSwitchingView; |
|||
base.didUpdateWidget(oldWidget); |
|||
this._focusActiveTab(); |
|||
} |
|||
|
|||
void _focusActiveTab() { |
|||
FocusScope.of(this.context).setFirstFocus(this.tabFocusNodes[this.widget.currentTabIndex]); |
|||
} |
|||
|
|||
public override void dispose() { |
|||
foreach (FocusScopeNode focusScopeNode in this.tabFocusNodes) { |
|||
focusScopeNode.detach(); |
|||
} |
|||
|
|||
base.dispose(); |
|||
} |
|||
|
|||
public override Widget build(BuildContext context) { |
|||
List<Widget> children = new List<Widget>(); |
|||
for (int index = 0; index < this.widget.tabNumber; index++) { |
|||
bool active = index == this.widget.currentTabIndex; |
|||
|
|||
if (active || this.tabs[index] != null) { |
|||
this.tabs[index] = this.widget.tabBuilder(context, index); |
|||
} |
|||
|
|||
children.Add(new Offstage( |
|||
offstage: !active, |
|||
child: new TickerMode( |
|||
enabled: active, |
|||
child: new FocusScope( |
|||
node: this.tabFocusNodes[index], |
|||
child: this.tabs[index] ?? new Container() |
|||
) |
|||
) |
|||
)); |
|||
} |
|||
|
|||
return new Stack( |
|||
fit: StackFit.expand, |
|||
children: children |
|||
); |
|||
} |
|||
} |
|||
} |
|
|||
fileFormatVersion: 2 |
|||
guid: dd65a2bea05bed8409d301489cf20864 |
|||
MonoImporter: |
|||
externalObjects: {} |
|||
serializedVersion: 2 |
|||
defaultReferences: [] |
|||
executionOrder: 0 |
|||
icon: {instanceID: 0} |
|||
userData: |
|||
assetBundleName: |
|||
assetBundleVariant: |
|
|||
using System.Collections.Generic; |
|||
using Unity.UIWidgets.foundation; |
|||
using Unity.UIWidgets.widgets; |
|||
|
|||
namespace Unity.UIWidgets.cupertino { |
|||
public class CupertinoTabView : StatefulWidget { |
|||
public CupertinoTabView( |
|||
Key key = null, |
|||
WidgetBuilder builder = null, |
|||
GlobalKey<NavigatorState> navigatorKey = null, |
|||
string defaultTitle = null, |
|||
Dictionary<string, WidgetBuilder> routes = null, |
|||
RouteFactory onGenerateRoute = null, |
|||
RouteFactory onUnknownRoute = null, |
|||
List<NavigatorObserver> navigatorObservers = null |
|||
) : base(key: key) { |
|||
this.builder = builder; |
|||
this.navigatorKey = navigatorKey; |
|||
this.defaultTitle = defaultTitle; |
|||
this.routes = routes; |
|||
this.onGenerateRoute = onGenerateRoute; |
|||
this.onUnknownRoute = onUnknownRoute; |
|||
this.navigatorObservers = navigatorObservers ?? new List<NavigatorObserver>(); |
|||
} |
|||
|
|||
public readonly WidgetBuilder builder; |
|||
|
|||
public readonly GlobalKey<NavigatorState> navigatorKey; |
|||
|
|||
public readonly string defaultTitle; |
|||
|
|||
public readonly Dictionary<string, WidgetBuilder> routes; |
|||
|
|||
public readonly RouteFactory onGenerateRoute; |
|||
|
|||
public readonly RouteFactory onUnknownRoute; |
|||
|
|||
public readonly List<NavigatorObserver> navigatorObservers; |
|||
|
|||
public override State createState() { |
|||
return new _CupertinoTabViewState(); |
|||
} |
|||
} |
|||
|
|||
class _CupertinoTabViewState : State<CupertinoTabView> { |
|||
HeroController _heroController; |
|||
List<NavigatorObserver> _navigatorObservers; |
|||
|
|||
public override void initState() { |
|||
base.initState(); |
|||
this._heroController = CupertinoApp.createCupertinoHeroController(); |
|||
this._updateObservers(); |
|||
} |
|||
|
|||
public override void didUpdateWidget(StatefulWidget oldWidget) { |
|||
base.didUpdateWidget(oldWidget); |
|||
CupertinoTabView _oldWidget = (CupertinoTabView) oldWidget; |
|||
if (this.widget.navigatorKey != _oldWidget.navigatorKey |
|||
|| this.widget.navigatorObservers != _oldWidget.navigatorObservers) { |
|||
this._updateObservers(); |
|||
} |
|||
} |
|||
|
|||
void _updateObservers() { |
|||
this._navigatorObservers = |
|||
new List<NavigatorObserver>(this.widget.navigatorObservers); |
|||
this._navigatorObservers.Add(this._heroController); |
|||
} |
|||
|
|||
public override Widget build(BuildContext context) { |
|||
return new Navigator( |
|||
key: this.widget.navigatorKey, |
|||
onGenerateRoute: this._onGenerateRoute, |
|||
onUnknownRoute: this._onUnknownRoute, |
|||
observers: this._navigatorObservers |
|||
); |
|||
} |
|||
|
|||
Route _onGenerateRoute(RouteSettings settings) { |
|||
string name = settings.name; |
|||
WidgetBuilder routeBuilder = null; |
|||
string title = null; |
|||
if (name == Navigator.defaultRouteName && this.widget.builder != null) { |
|||
routeBuilder = this.widget.builder; |
|||
title = this.widget.defaultTitle; |
|||
} |
|||
else if (this.widget.routes != null) { |
|||
routeBuilder = this.widget.routes[name]; |
|||
} |
|||
|
|||
if (routeBuilder != null) { |
|||
return new CupertinoPageRoute( |
|||
builder: routeBuilder, |
|||
title: title, |
|||
settings: settings |
|||
); |
|||
} |
|||
|
|||
if (this.widget.onGenerateRoute != null) { |
|||
return this.widget.onGenerateRoute(settings); |
|||
} |
|||
|
|||
return null; |
|||
} |
|||
|
|||
Route _onUnknownRoute(RouteSettings settings) { |
|||
D.assert(() => { |
|||
if (this.widget.onUnknownRoute == null) { |
|||
throw new UIWidgetsError( |
|||
$"Could not find a generator for route {settings} in the {this.GetType()}.\n" + |
|||
"Generators for routes are searched for in the following order:\n" + |
|||
" 1. For the \"/\" route, the \"builder\" property, if non-null, is used.\n" + |
|||
" 2. Otherwise, the \"routes\" table is used, if it has an entry for " + |
|||
"the route.\n" + |
|||
" 3. Otherwise, onGenerateRoute is called. It should return a " + |
|||
"non-null value for any valid route not handled by \"builder\" and \"routes\".\n" + |
|||
" 4. Finally if all else fails onUnknownRoute is called.\n" + |
|||
"Unfortunately, onUnknownRoute was not set." |
|||
); |
|||
} |
|||
|
|||
return true; |
|||
}); |
|||
|
|||
Route result = this.widget.onUnknownRoute(settings); |
|||
D.assert(() => { |
|||
if (result == null) { |
|||
throw new UIWidgetsError( |
|||
"The onUnknownRoute callback returned null.\n" + |
|||
$"When the {this.GetType()} requested the route {settings} from its " + |
|||
"onUnknownRoute callback, the callback returned null. Such callbacks " + |
|||
"must never return null." |
|||
); |
|||
} |
|||
|
|||
return true; |
|||
}); |
|||
return result; |
|||
} |
|||
} |
|||
} |
|
|||
fileFormatVersion: 2 |
|||
guid: 6a23c29fee52d4274be319d1f5df98c4 |
|||
MonoImporter: |
|||
externalObjects: {} |
|||
serializedVersion: 2 |
|||
defaultReferences: [] |
|||
executionOrder: 0 |
|||
icon: {instanceID: 0} |
|||
userData: |
|||
assetBundleName: |
|||
assetBundleVariant: |
|
|||
using System.Collections.Generic; |
|||
using Unity.UIWidgets.foundation; |
|||
using Unity.UIWidgets.gestures; |
|||
using Unity.UIWidgets.painting; |
|||
using Unity.UIWidgets.rendering; |
|||
using Unity.UIWidgets.service; |
|||
using Unity.UIWidgets.ui; |
|||
using Unity.UIWidgets.widgets; |
|||
using TextStyle = Unity.UIWidgets.painting.TextStyle; |
|||
|
|||
namespace Unity.UIWidgets.cupertino { |
|||
class CupertinoTextFieldUtils { |
|||
public static readonly BorderSide _kDefaultRoundedBorderSide = new BorderSide( |
|||
color: CupertinoColors.lightBackgroundGray, |
|||
style: BorderStyle.solid, |
|||
width: 0.0f |
|||
); |
|||
|
|||
public static readonly Border _kDefaultRoundedBorder = new Border( |
|||
top: _kDefaultRoundedBorderSide, |
|||
bottom: _kDefaultRoundedBorderSide, |
|||
left: _kDefaultRoundedBorderSide, |
|||
right: _kDefaultRoundedBorderSide |
|||
); |
|||
|
|||
public static readonly BoxDecoration _kDefaultRoundedBorderDecoration = new BoxDecoration( |
|||
border: _kDefaultRoundedBorder, |
|||
borderRadius: BorderRadius.all(Radius.circular(4.0f)) |
|||
); |
|||
|
|||
public static readonly Color _kSelectionHighlightColor = new Color(0x667FAACF); |
|||
|
|||
public static readonly Color _kInactiveTextColor = new Color(0xFFC2C2C2); |
|||
|
|||
public static readonly Color _kDisabledBackground = new Color(0xFFFAFAFA); |
|||
|
|||
public const int _iOSHorizontalCursorOffsetPixels = -2; |
|||
} |
|||
|
|||
public enum OverlayVisibilityMode { |
|||
never, |
|||
editing, |
|||
notEditing, |
|||
always |
|||
} |
|||
|
|||
public class CupertinoTextField : StatefulWidget { |
|||
public CupertinoTextField( |
|||
Key key = null, |
|||
TextEditingController controller = null, |
|||
FocusNode focusNode = null, |
|||
BoxDecoration decoration = null, |
|||
EdgeInsets padding = null, |
|||
string placeholder = null, |
|||
TextStyle placeholderStyle = null, |
|||
Widget prefix = null, |
|||
OverlayVisibilityMode prefixMode = OverlayVisibilityMode.always, |
|||
Widget suffix = null, |
|||
OverlayVisibilityMode suffixMode = OverlayVisibilityMode.always, |
|||
OverlayVisibilityMode clearButtonMode = OverlayVisibilityMode.never, |
|||
TextInputType keyboardType = null, |
|||
TextInputAction? textInputAction = null, |
|||
TextCapitalization textCapitalization = TextCapitalization.none, |
|||
TextStyle style = null, |
|||
StrutStyle strutStyle = null, |
|||
TextAlign textAlign = TextAlign.left, |
|||
bool autofocus = false, |
|||
bool obscureText = false, |
|||
bool autocorrect = true, |
|||
int? maxLines = 1, |
|||
int? minLines = null, |
|||
bool expands = false, |
|||
int? maxLength = null, |
|||
bool maxLengthEnforced = true, |
|||
ValueChanged<string> onChanged = null, |
|||
VoidCallback onEditingComplete = null, |
|||
ValueChanged<string> onSubmitted = null, |
|||
List<TextInputFormatter> inputFormatters = null, |
|||
bool? enabled = null, |
|||
float cursorWidth = 2.0f, |
|||
Radius cursorRadius = null, |
|||
Color cursorColor = null, |
|||
Brightness? keyboardAppearance = null, |
|||
EdgeInsets scrollPadding = null, |
|||
DragStartBehavior dragStartBehavior = DragStartBehavior.start, |
|||
ScrollPhysics scrollPhysics = null) : base(key: key) { |
|||
D.assert(maxLines == null || maxLines > 0); |
|||
D.assert(minLines == null || minLines > 0); |
|||
D.assert(maxLines == null || minLines == null || maxLines >= minLines, |
|||
() => "minLines can't be greater than maxLines"); |
|||
D.assert(!expands || (maxLines == null && minLines == null), |
|||
() => "minLines and maxLines must be null when expands is true."); |
|||
D.assert(maxLength == null || maxLength > 0); |
|||
|
|||
this.controller = controller; |
|||
this.focusNode = focusNode; |
|||
this.decoration = decoration ?? CupertinoTextFieldUtils._kDefaultRoundedBorderDecoration; |
|||
this.padding = padding ?? EdgeInsets.all(6.0f); |
|||
this.placeholder = placeholder; |
|||
this.placeholderStyle = placeholderStyle ?? new TextStyle( |
|||
fontWeight: FontWeight.w300, |
|||
color: CupertinoTextFieldUtils._kInactiveTextColor |
|||
); |
|||
this.prefix = prefix; |
|||
this.prefixMode = prefixMode; |
|||
this.suffix = suffix; |
|||
this.suffixMode = suffixMode; |
|||
this.clearButtonMode = clearButtonMode; |
|||
this.textInputAction = textInputAction; |
|||
this.textCapitalization = textCapitalization; |
|||
this.style = style; |
|||
this.strutStyle = strutStyle; |
|||
this.textAlign = textAlign; |
|||
this.autofocus = autofocus; |
|||
this.obscureText = obscureText; |
|||
this.autocorrect = autocorrect; |
|||
this.maxLines = maxLines; |
|||
this.minLines = minLines; |
|||
this.expands = expands; |
|||
this.maxLength = maxLength; |
|||
this.maxLengthEnforced = maxLengthEnforced; |
|||
this.onChanged = onChanged; |
|||
this.onEditingComplete = onEditingComplete; |
|||
this.onSubmitted = onSubmitted; |
|||
this.inputFormatters = inputFormatters; |
|||
this.enabled = enabled; |
|||
this.cursorWidth = cursorWidth; |
|||
this.cursorRadius = cursorRadius ?? Radius.circular(2.0f); |
|||
this.cursorColor = cursorColor; |
|||
this.keyboardAppearance = keyboardAppearance; |
|||
this.scrollPadding = scrollPadding ?? EdgeInsets.all(20.0f); |
|||
this.dragStartBehavior = dragStartBehavior; |
|||
this.scrollPhysics = scrollPhysics; |
|||
this.keyboardType = keyboardType ?? (maxLines == 1 ? TextInputType.text : TextInputType.multiline); |
|||
} |
|||
|
|||
public readonly TextEditingController controller; |
|||
|
|||
public readonly FocusNode focusNode; |
|||
|
|||
public readonly BoxDecoration decoration; |
|||
|
|||
public readonly EdgeInsets padding; |
|||
|
|||
public readonly string placeholder; |
|||
|
|||
public readonly TextStyle placeholderStyle; |
|||
|
|||
public readonly Widget prefix; |
|||
|
|||
public readonly OverlayVisibilityMode prefixMode; |
|||
|
|||
public readonly Widget suffix; |
|||
|
|||
public readonly OverlayVisibilityMode suffixMode; |
|||
|
|||
public readonly OverlayVisibilityMode clearButtonMode; |
|||
|
|||
public readonly TextInputType keyboardType; |
|||
|
|||
public readonly TextInputAction? textInputAction; |
|||
|
|||
public readonly TextCapitalization textCapitalization; |
|||
|
|||
public readonly TextStyle style; |
|||
|
|||
public readonly StrutStyle strutStyle; |
|||
|
|||
public readonly TextAlign textAlign; |
|||
|
|||
public readonly bool autofocus; |
|||
|
|||
public readonly bool obscureText; |
|||
|
|||
public readonly bool autocorrect; |
|||
|
|||
public readonly int? maxLines; |
|||
|
|||
public readonly int? minLines; |
|||
|
|||
public readonly bool expands; |
|||
|
|||
public readonly int? maxLength; |
|||
|
|||
public readonly bool maxLengthEnforced; |
|||
|
|||
public readonly ValueChanged<string> onChanged; |
|||
|
|||
public readonly VoidCallback onEditingComplete; |
|||
|
|||
public readonly ValueChanged<string> onSubmitted; |
|||
|
|||
public readonly List<TextInputFormatter> inputFormatters; |
|||
|
|||
public readonly bool? enabled; |
|||
|
|||
public readonly float cursorWidth; |
|||
|
|||
public readonly Radius cursorRadius; |
|||
|
|||
public readonly Color cursorColor; |
|||
|
|||
public readonly Brightness? keyboardAppearance; |
|||
|
|||
public readonly EdgeInsets scrollPadding; |
|||
|
|||
public readonly DragStartBehavior dragStartBehavior; |
|||
|
|||
public readonly ScrollPhysics scrollPhysics; |
|||
|
|||
public override State createState() { |
|||
return new _CupertinoTextFieldState(); |
|||
} |
|||
|
|||
public override void debugFillProperties(DiagnosticPropertiesBuilder properties) { |
|||
base.debugFillProperties(properties); |
|||
|
|||
properties.add( |
|||
new DiagnosticsProperty<TextEditingController>("controller", this.controller, defaultValue: null)); |
|||
properties.add(new DiagnosticsProperty<FocusNode>("focusNode", this.focusNode, defaultValue: null)); |
|||
properties.add(new DiagnosticsProperty<BoxDecoration>("decoration", this.decoration)); |
|||
properties.add(new DiagnosticsProperty<EdgeInsets>("padding", this.padding)); |
|||
properties.add(new StringProperty("placeholder", this.placeholder)); |
|||
properties.add(new DiagnosticsProperty<TextStyle>("placeholderStyle", this.placeholderStyle)); |
|||
properties.add(new DiagnosticsProperty<OverlayVisibilityMode>("prefix", |
|||
this.prefix == null ? OverlayVisibilityMode.never : this.prefixMode)); |
|||
properties.add(new DiagnosticsProperty<OverlayVisibilityMode>("suffix", |
|||
this.suffix == null ? OverlayVisibilityMode.never : this.suffixMode)); |
|||
properties.add(new DiagnosticsProperty<OverlayVisibilityMode>("clearButtonMode", this.clearButtonMode)); |
|||
properties.add(new DiagnosticsProperty<TextInputType>("keyboardType", this.keyboardType, |
|||
defaultValue: TextInputType.text)); |
|||
properties.add(new DiagnosticsProperty<TextStyle>("style", this.style, defaultValue: null)); |
|||
properties.add(new DiagnosticsProperty<bool>("autofocus", this.autofocus, defaultValue: false)); |
|||
properties.add(new DiagnosticsProperty<bool>("obscureText", this.obscureText, defaultValue: false)); |
|||
properties.add(new DiagnosticsProperty<bool>("autocorrect", this.autocorrect, defaultValue: false)); |
|||
properties.add(new IntProperty("maxLines", this.maxLines, defaultValue: 1)); |
|||
properties.add(new IntProperty("minLines", this.minLines, defaultValue: null)); |
|||
properties.add(new DiagnosticsProperty<bool>("expands", this.expands, defaultValue: false)); |
|||
properties.add(new IntProperty("maxLength", this.maxLength, defaultValue: null)); |
|||
properties.add(new FlagProperty("maxLengthEnforced", value: this.maxLengthEnforced, |
|||
ifTrue: "max length enforced")); |
|||
properties.add(new DiagnosticsProperty<Color>("cursorColor", this.cursorColor, defaultValue: null)); |
|||
properties.add( |
|||
new DiagnosticsProperty<ScrollPhysics>("scrollPhysics", this.scrollPhysics, defaultValue: null)); |
|||
} |
|||
} |
|||
|
|||
class _CupertinoTextFieldState : AutomaticKeepAliveClientMixin<CupertinoTextField> { |
|||
GlobalKey<EditableTextState> _editableTextKey = GlobalKey<EditableTextState>.key(); |
|||
|
|||
TextEditingController _controller; |
|||
|
|||
TextEditingController _effectiveController { |
|||
get { return this.widget.controller ?? this._controller; } |
|||
} |
|||
|
|||
FocusNode _focusNode; |
|||
|
|||
FocusNode _effectiveFocusNode { |
|||
get { return this.widget.focusNode ?? this._focusNode ?? (this._focusNode = new FocusNode()); } |
|||
} |
|||
|
|||
public override void initState() { |
|||
base.initState(); |
|||
if (this.widget.controller == null) { |
|||
this._controller = new TextEditingController(); |
|||
this._controller.addListener(this.updateKeepAlive); |
|||
} |
|||
} |
|||
|
|||
public override void didUpdateWidget(StatefulWidget oldWidget) { |
|||
base.didUpdateWidget(oldWidget); |
|||
CupertinoTextField _oldWidget = (CupertinoTextField) oldWidget; |
|||
|
|||
if (this.widget.controller == null && _oldWidget.controller != null) { |
|||
this._controller = TextEditingController.fromValue(_oldWidget.controller.value); |
|||
this._controller.addListener(this.updateKeepAlive); |
|||
} |
|||
else if (this.widget.controller != null && _oldWidget.controller == null) { |
|||
this._controller = null; |
|||
} |
|||
|
|||
bool isEnabled = this.widget.enabled ?? true; |
|||
bool wasEnabled = _oldWidget.enabled ?? true; |
|||
|
|||
if (wasEnabled && !isEnabled) { |
|||
this._effectiveFocusNode.unfocus(); |
|||
} |
|||
} |
|||
|
|||
public override void dispose() { |
|||
this._focusNode?.dispose(); |
|||
this._controller?.removeListener(this.updateKeepAlive); |
|||
base.dispose(); |
|||
} |
|||
|
|||
void _requestKeyboard() { |
|||
this._editableTextKey.currentState?.requestKeyboard(); |
|||
} |
|||
|
|||
RenderEditable _renderEditable { |
|||
get { return this._editableTextKey.currentState.renderEditable; } |
|||
} |
|||
|
|||
void _handleTapDown(TapDownDetails details) { |
|||
this._renderEditable.handleTapDown(details); |
|||
} |
|||
|
|||
|
|||
void _handleSingleTapUp(TapUpDetails details) { |
|||
this._renderEditable.selectWordEdge(cause: SelectionChangedCause.tap); |
|||
this._requestKeyboard(); |
|||
} |
|||
|
|||
void _handleSingleLongTapStart(LongPressStartDetails details) { |
|||
this._renderEditable.selectPositionAt( |
|||
from: details.globalPosition, |
|||
cause: SelectionChangedCause.longPress |
|||
); |
|||
} |
|||
|
|||
void _handleSingleLongTapMoveUpdate(LongPressMoveUpdateDetails details) { |
|||
this._renderEditable.selectPositionAt( |
|||
from: details.globalPosition, |
|||
cause: SelectionChangedCause.longPress |
|||
); |
|||
} |
|||
|
|||
void _handleSingleLongTapEnd(LongPressEndDetails details) { |
|||
this._editableTextKey.currentState.showToolbar(); |
|||
} |
|||
|
|||
void _handleDoubleTapDown(TapDownDetails details) { |
|||
this._renderEditable.selectWord(cause: SelectionChangedCause.tap); |
|||
this._editableTextKey.currentState.showToolbar(); |
|||
} |
|||
|
|||
void _handleMouseDragSelectionStart(DragStartDetails details) { |
|||
this._renderEditable.selectPositionAt( |
|||
from: details.globalPosition, |
|||
cause: SelectionChangedCause.drag |
|||
); |
|||
} |
|||
|
|||
void _handleMouseDragSelectionUpdate( |
|||
DragStartDetails startDetails, |
|||
DragUpdateDetails updateDetails |
|||
) { |
|||
this._renderEditable.selectPositionAt( |
|||
from: startDetails.globalPosition, |
|||
to: updateDetails.globalPosition, |
|||
cause: SelectionChangedCause.drag |
|||
); |
|||
} |
|||
|
|||
void _handleMouseDragSelectionEnd(DragEndDetails details) { |
|||
this._requestKeyboard(); |
|||
} |
|||
|
|||
void _handleSelectionChanged(TextSelection selection, SelectionChangedCause cause) { |
|||
if (cause == SelectionChangedCause.longPress) { |
|||
this._editableTextKey.currentState?.bringIntoView(selection.basePos); |
|||
} |
|||
} |
|||
|
|||
protected override bool wantKeepAlive { |
|||
get { return this._controller?.text?.isNotEmpty() == true; } |
|||
} |
|||
|
|||
bool _shouldShowAttachment( |
|||
OverlayVisibilityMode attachment, |
|||
bool hasText |
|||
) { |
|||
switch (attachment) { |
|||
case OverlayVisibilityMode.never: |
|||
return false; |
|||
case OverlayVisibilityMode.always: |
|||
return true; |
|||
case OverlayVisibilityMode.editing: |
|||
return hasText; |
|||
case OverlayVisibilityMode.notEditing: |
|||
return !hasText; |
|||
} |
|||
|
|||
D.assert(false); |
|||
return false; |
|||
} |
|||
|
|||
bool _showPrefixWidget(TextEditingValue text) { |
|||
return this.widget.prefix != null && this._shouldShowAttachment( |
|||
attachment: this.widget.prefixMode, |
|||
hasText: text.text.isNotEmpty() |
|||
); |
|||
} |
|||
|
|||
bool _showSuffixWidget(TextEditingValue text) { |
|||
return this.widget.suffix != null && this._shouldShowAttachment( |
|||
attachment: this.widget.suffixMode, |
|||
hasText: text.text.isNotEmpty() |
|||
); |
|||
} |
|||
|
|||
bool _showClearButton(TextEditingValue text) { |
|||
return this._shouldShowAttachment( |
|||
attachment: this.widget.clearButtonMode, |
|||
hasText: text.text.isNotEmpty() |
|||
); |
|||
} |
|||
|
|||
Widget _addTextDependentAttachments(Widget editableText, TextStyle textStyle, TextStyle placeholderStyle) { |
|||
D.assert(editableText != null); |
|||
D.assert(textStyle != null); |
|||
D.assert(placeholderStyle != null); |
|||
|
|||
if (this.widget.placeholder == null && |
|||
this.widget.clearButtonMode == OverlayVisibilityMode.never && |
|||
this.widget.prefix == null && |
|||
this.widget.suffix == null) { |
|||
return editableText; |
|||
} |
|||
|
|||
return new ValueListenableBuilder<TextEditingValue>( |
|||
valueListenable: this._effectiveController, |
|||
child: editableText, |
|||
builder: (BuildContext context, TextEditingValue text, Widget child) => { |
|||
List<Widget> rowChildren = new List<Widget>(); |
|||
|
|||
if (this._showPrefixWidget(text)) { |
|||
rowChildren.Add(this.widget.prefix); |
|||
} |
|||
|
|||
List<Widget> stackChildren = new List<Widget>(); |
|||
if (this.widget.placeholder != null && text.text.isEmpty()) { |
|||
stackChildren.Add( |
|||
new Padding( |
|||
padding: this.widget.padding, |
|||
child: new Text( |
|||
this.widget.placeholder, |
|||
maxLines: 1, |
|||
overflow: TextOverflow.ellipsis, |
|||
style: placeholderStyle |
|||
) |
|||
) |
|||
); |
|||
} |
|||
|
|||
stackChildren.Add(child); |
|||
rowChildren.Add( |
|||
new Expanded |
|||
(child: new Stack |
|||
(children: stackChildren))); |
|||
|
|||
if (this._showSuffixWidget(text)) { |
|||
rowChildren.Add(this.widget.suffix); |
|||
} |
|||
else if (this._showClearButton(text)) { |
|||
rowChildren.Add( |
|||
new GestureDetector( |
|||
onTap: this.widget.enabled ?? true |
|||
? () => { |
|||
bool textChanged = this._effectiveController.text.isNotEmpty(); |
|||
this._effectiveController.clear(); |
|||
if (this.widget.onChanged != null && textChanged) { |
|||
this.widget.onChanged(this._effectiveController.text); |
|||
} |
|||
} |
|||
: (GestureTapCallback) null, |
|||
child: new Padding( |
|||
padding: EdgeInsets.symmetric(horizontal: 6.0f), |
|||
child: new Icon( |
|||
CupertinoIcons.clear_thick_circled, |
|||
size: 18.0f, |
|||
color: CupertinoTextFieldUtils._kInactiveTextColor |
|||
) |
|||
) |
|||
) |
|||
); |
|||
} |
|||
|
|||
return new Row(children: rowChildren); |
|||
} |
|||
); |
|||
} |
|||
|
|||
public override Widget build(BuildContext context) { |
|||
base.build(context); |
|||
TextEditingController controller = this._effectiveController; |
|||
List<TextInputFormatter> formatters = this.widget.inputFormatters ?? new List<TextInputFormatter>(); |
|||
bool enabled = this.widget.enabled ?? true; |
|||
Offset cursorOffset = |
|||
new Offset( |
|||
CupertinoTextFieldUtils._iOSHorizontalCursorOffsetPixels / MediaQuery.of(context).devicePixelRatio, |
|||
0); |
|||
if (this.widget.maxLength != null && this.widget.maxLengthEnforced) { |
|||
formatters.Add(new LengthLimitingTextInputFormatter(this.widget.maxLength)); |
|||
} |
|||
|
|||
CupertinoThemeData themeData = CupertinoTheme.of(context); |
|||
TextStyle textStyle = themeData.textTheme.textStyle.merge(this.widget.style); |
|||
TextStyle placeholderStyle = textStyle.merge(this.widget.placeholderStyle); |
|||
Brightness keyboardAppearance = this.widget.keyboardAppearance ?? themeData.brightness; |
|||
Color cursorColor = this.widget.cursorColor ?? themeData.primaryColor; |
|||
|
|||
Widget paddedEditable = new Padding( |
|||
padding: this.widget.padding, |
|||
child: new RepaintBoundary( |
|||
child: new EditableText( |
|||
key: this._editableTextKey, |
|||
controller: controller, |
|||
focusNode: this._effectiveFocusNode, |
|||
keyboardType: this.widget.keyboardType, |
|||
textInputAction: this.widget.textInputAction, |
|||
textCapitalization: this.widget.textCapitalization, |
|||
style: textStyle, |
|||
strutStyle: this.widget.strutStyle, |
|||
textAlign: this.widget.textAlign, |
|||
autofocus: this.widget.autofocus, |
|||
obscureText: this.widget.obscureText, |
|||
autocorrect: this.widget.autocorrect, |
|||
maxLines: this.widget.maxLines, |
|||
minLines: this.widget.minLines, |
|||
expands: this.widget.expands, |
|||
selectionColor: CupertinoTextFieldUtils._kSelectionHighlightColor, |
|||
selectionControls: CupertinoTextSelectionUtils.cupertinoTextSelectionControls, |
|||
onChanged: this.widget.onChanged, |
|||
onSelectionChanged: this._handleSelectionChanged, |
|||
onEditingComplete: this.widget.onEditingComplete, |
|||
onSubmitted: this.widget.onSubmitted, |
|||
inputFormatters: formatters, |
|||
rendererIgnoresPointer: true, |
|||
cursorWidth: this.widget.cursorWidth, |
|||
cursorRadius: this.widget.cursorRadius, |
|||
cursorColor: cursorColor, |
|||
cursorOpacityAnimates: true, |
|||
cursorOffset: cursorOffset, |
|||
paintCursorAboveText: true, |
|||
backgroundCursorColor: CupertinoColors.inactiveGray, |
|||
scrollPadding: this.widget.scrollPadding, |
|||
keyboardAppearance: keyboardAppearance, |
|||
dragStartBehavior: this.widget.dragStartBehavior, |
|||
scrollPhysics: this.widget.scrollPhysics |
|||
) |
|||
) |
|||
); |
|||
|
|||
return new IgnorePointer( |
|||
ignoring: !enabled, |
|||
child: new Container( |
|||
decoration: this.widget.decoration, |
|||
child: new Container( |
|||
color: enabled |
|||
? null |
|||
: CupertinoTheme.of(context).brightness == Brightness.light |
|||
? CupertinoTextFieldUtils._kDisabledBackground |
|||
: CupertinoColors.darkBackgroundGray, |
|||
child: new TextSelectionGestureDetector( |
|||
onTapDown: this._handleTapDown, |
|||
onSingleTapUp: this._handleSingleTapUp, |
|||
onSingleLongTapStart: this._handleSingleLongTapStart, |
|||
onSingleLongTapMoveUpdate: this._handleSingleLongTapMoveUpdate, |
|||
onSingleLongTapEnd: this._handleSingleLongTapEnd, |
|||
onDoubleTapDown: this._handleDoubleTapDown, |
|||
onDragSelectionStart: this._handleMouseDragSelectionStart, |
|||
onDragSelectionUpdate: this._handleMouseDragSelectionUpdate, |
|||
onDragSelectionEnd: this._handleMouseDragSelectionEnd, |
|||
behavior: HitTestBehavior.translucent, |
|||
child: this._addTextDependentAttachments(paddedEditable, textStyle, placeholderStyle) |
|||
) |
|||
) |
|||
) |
|||
); |
|||
} |
|||
} |
|||
} |
|
|||
fileFormatVersion: 2 |
|||
guid: a300f388a142347fab65f219e2843698 |
|||
MonoImporter: |
|||
externalObjects: {} |
|||
serializedVersion: 2 |
|||
defaultReferences: [] |
|||
executionOrder: 0 |
|||
icon: {instanceID: 0} |
|||
userData: |
|||
assetBundleName: |
|||
assetBundleVariant: |
|
|||
using System.Collections.Generic; |
|||
using Unity.UIWidgets.foundation; |
|||
using Unity.UIWidgets.painting; |
|||
using Unity.UIWidgets.rendering; |
|||
using Unity.UIWidgets.service; |
|||
using Unity.UIWidgets.ui; |
|||
using Unity.UIWidgets.widgets; |
|||
using UnityEngine; |
|||
using Canvas = Unity.UIWidgets.ui.Canvas; |
|||
using Color = Unity.UIWidgets.ui.Color; |
|||
using Rect = Unity.UIWidgets.ui.Rect; |
|||
using TextStyle = Unity.UIWidgets.painting.TextStyle; |
|||
using Transform = Unity.UIWidgets.widgets.Transform; |
|||
|
|||
namespace Unity.UIWidgets.cupertino { |
|||
public static class CupertinoTextSelectionUtils { |
|||
public static TextSelectionControls cupertinoTextSelectionControls = new _CupertinoTextSelectionControls(); |
|||
|
|||
public const float _kHandlesPadding = 18.0f; |
|||
|
|||
public const float _kToolbarScreenPadding = 8.0f; |
|||
|
|||
public const float _kToolbarHeight = 36.0f; |
|||
|
|||
public static readonly Color _kToolbarBackgroundColor = new Color(0xFF2E2E2E); |
|||
|
|||
public static readonly Color _kToolbarDividerColor = new Color(0xFFB9B9B9); |
|||
|
|||
public static readonly Color _kHandlesColor = new Color(0xFF136FE0); |
|||
|
|||
public static readonly Size _kSelectionOffset = new Size(20.0f, 30.0f); |
|||
|
|||
public static readonly Size _kToolbarTriangleSize = new Size(18.0f, 9.0f); |
|||
|
|||
public static readonly EdgeInsets _kToolbarButtonPadding = |
|||
EdgeInsets.symmetric(vertical: 10.0f, horizontal: 18.0f); |
|||
|
|||
public static readonly BorderRadius _kToolbarBorderRadius = BorderRadius.all(Radius.circular(7.5f)); |
|||
|
|||
public static readonly TextStyle _kToolbarButtonFontStyle = new TextStyle( |
|||
fontSize: 14.0f, |
|||
letterSpacing: -0.11f, |
|||
fontWeight: FontWeight.w300, |
|||
color: CupertinoColors.white |
|||
); |
|||
} |
|||
|
|||
class _TextSelectionToolbarNotchPainter : AbstractCustomPainter { |
|||
public override void paint(Canvas canvas, Size size) { |
|||
Paint paint = new Paint(); |
|||
paint.color = CupertinoTextSelectionUtils._kToolbarBackgroundColor; |
|||
paint.style = PaintingStyle.fill; |
|||
|
|||
Path triangle = new Path(); |
|||
triangle.lineTo(CupertinoTextSelectionUtils._kToolbarTriangleSize.width / 2, 0.0f); |
|||
triangle.lineTo(0.0f, CupertinoTextSelectionUtils._kToolbarTriangleSize.height); |
|||
triangle.lineTo(-(CupertinoTextSelectionUtils._kToolbarTriangleSize.width / 2), 0.0f); |
|||
triangle.close(); |
|||
canvas.drawPath(triangle, paint); |
|||
} |
|||
|
|||
public override bool shouldRepaint(CustomPainter oldPainter) { |
|||
return false; |
|||
} |
|||
} |
|||
|
|||
class _TextSelectionToolbar : StatelessWidget { |
|||
public _TextSelectionToolbar( |
|||
Key key = null, |
|||
VoidCallback handleCut = null, |
|||
VoidCallback handleCopy = null, |
|||
VoidCallback handlePaste = null, |
|||
VoidCallback handleSelectAll = null |
|||
) : base(key: key) { |
|||
this.handleCut = handleCut; |
|||
this.handleCopy = handleCopy; |
|||
this.handlePaste = handlePaste; |
|||
this.handleSelectAll = handleSelectAll; |
|||
} |
|||
|
|||
readonly VoidCallback handleCut; |
|||
|
|||
readonly VoidCallback handleCopy; |
|||
|
|||
readonly VoidCallback handlePaste; |
|||
|
|||
readonly VoidCallback handleSelectAll; |
|||
|
|||
|
|||
public override Widget build(BuildContext context) { |
|||
List<Widget> items = new List<Widget>(); |
|||
Widget onePhysicalPixelVerticalDivider = |
|||
new SizedBox(width: 1.0f / MediaQuery.of(context).devicePixelRatio); |
|||
CupertinoLocalizations localizations = CupertinoLocalizations.of(context); |
|||
|
|||
if (this.handleCut != null) { |
|||
items.Add(this._buildToolbarButton(localizations.cutButtonLabel, this.handleCut)); |
|||
} |
|||
|
|||
if (this.handleCopy != null) { |
|||
if (items.isNotEmpty()) { |
|||
items.Add(onePhysicalPixelVerticalDivider); |
|||
} |
|||
|
|||
items.Add(this._buildToolbarButton(localizations.copyButtonLabel, this.handleCopy)); |
|||
} |
|||
|
|||
if (this.handlePaste != null) { |
|||
if (items.isNotEmpty()) { |
|||
items.Add(onePhysicalPixelVerticalDivider); |
|||
} |
|||
|
|||
items.Add(this._buildToolbarButton(localizations.pasteButtonLabel, this.handlePaste)); |
|||
} |
|||
|
|||
if (this.handleSelectAll != null) { |
|||
if (items.isNotEmpty()) { |
|||
items.Add(onePhysicalPixelVerticalDivider); |
|||
} |
|||
|
|||
items.Add(this._buildToolbarButton(localizations.selectAllButtonLabel, this.handleSelectAll)); |
|||
} |
|||
|
|||
Widget triangle = SizedBox.fromSize( |
|||
size: CupertinoTextSelectionUtils._kToolbarTriangleSize, |
|||
child: new CustomPaint( |
|||
painter: new _TextSelectionToolbarNotchPainter() |
|||
) |
|||
); |
|||
|
|||
return new Column( |
|||
mainAxisSize: MainAxisSize.min, |
|||
children: new List<Widget> { |
|||
new ClipRRect( |
|||
borderRadius: CupertinoTextSelectionUtils._kToolbarBorderRadius, |
|||
child: new DecoratedBox( |
|||
decoration: new BoxDecoration( |
|||
color: CupertinoTextSelectionUtils._kToolbarDividerColor, |
|||
borderRadius: CupertinoTextSelectionUtils._kToolbarBorderRadius, |
|||
border: Border.all(color: CupertinoTextSelectionUtils._kToolbarBackgroundColor, |
|||
width: 0) |
|||
), |
|||
child: new Row(mainAxisSize: MainAxisSize.min, children: items) |
|||
) |
|||
), |
|||
triangle, |
|||
new Padding(padding: EdgeInsets.only(bottom: 10.0f)) |
|||
} |
|||
); |
|||
} |
|||
|
|||
CupertinoButton _buildToolbarButton(string text, VoidCallback onPressed) { |
|||
return new CupertinoButton( |
|||
child: new Text(text, style: CupertinoTextSelectionUtils._kToolbarButtonFontStyle), |
|||
color: CupertinoTextSelectionUtils._kToolbarBackgroundColor, |
|||
minSize: CupertinoTextSelectionUtils._kToolbarHeight, |
|||
padding: CupertinoTextSelectionUtils._kToolbarButtonPadding, |
|||
borderRadius: null, |
|||
pressedOpacity: 0.7f, |
|||
onPressed: onPressed |
|||
); |
|||
} |
|||
} |
|||
|
|||
class _TextSelectionToolbarLayout : SingleChildLayoutDelegate { |
|||
public _TextSelectionToolbarLayout( |
|||
Size screenSize, |
|||
Rect globalEditableRegion, |
|||
Offset position) { |
|||
this.screenSize = screenSize; |
|||
this.globalEditableRegion = globalEditableRegion; |
|||
this.position = position; |
|||
} |
|||
|
|||
readonly Size screenSize; |
|||
|
|||
readonly Rect globalEditableRegion; |
|||
|
|||
readonly Offset position; |
|||
|
|||
public override BoxConstraints getConstraintsForChild(BoxConstraints constraints) { |
|||
return constraints.loosen(); |
|||
} |
|||
|
|||
public override Offset getPositionForChild(Size size, Size childSize) { |
|||
Offset globalPosition = this.globalEditableRegion.topLeft + this.position; |
|||
|
|||
float x = globalPosition.dx - childSize.width / 2.0f; |
|||
float y = globalPosition.dy - childSize.height; |
|||
|
|||
if (x < CupertinoTextSelectionUtils._kToolbarScreenPadding) { |
|||
x = CupertinoTextSelectionUtils._kToolbarScreenPadding; |
|||
} |
|||
else if (x + childSize.width > this.screenSize.width - CupertinoTextSelectionUtils._kToolbarScreenPadding) { |
|||
x = this.screenSize.width - childSize.width - CupertinoTextSelectionUtils._kToolbarScreenPadding; |
|||
} |
|||
|
|||
if (y < CupertinoTextSelectionUtils._kToolbarScreenPadding) { |
|||
y = CupertinoTextSelectionUtils._kToolbarScreenPadding; |
|||
} |
|||
else if (y + childSize.height > |
|||
this.screenSize.height - CupertinoTextSelectionUtils._kToolbarScreenPadding) { |
|||
y = this.screenSize.height - childSize.height - CupertinoTextSelectionUtils._kToolbarScreenPadding; |
|||
} |
|||
|
|||
return new Offset(x, y); |
|||
} |
|||
|
|||
public override bool shouldRelayout(SingleChildLayoutDelegate oldDelegate) { |
|||
_TextSelectionToolbarLayout _oldDelegate = (_TextSelectionToolbarLayout) oldDelegate; |
|||
return this.screenSize != _oldDelegate.screenSize |
|||
|| this.globalEditableRegion != _oldDelegate.globalEditableRegion |
|||
|| this.position != _oldDelegate.position; |
|||
} |
|||
} |
|||
|
|||
class _TextSelectionHandlePainter : AbstractCustomPainter { |
|||
public _TextSelectionHandlePainter(Offset origin) { |
|||
this.origin = origin; |
|||
} |
|||
|
|||
readonly Offset origin; |
|||
|
|||
|
|||
public override void paint(Canvas canvas, Size size) { |
|||
Paint paint = new Paint(); |
|||
paint.color = CupertinoTextSelectionUtils._kHandlesColor; |
|||
paint.strokeWidth = 2.0f; |
|||
|
|||
canvas.drawCircle(this.origin.translate(0.0f, 4.0f), 5.5f, paint); |
|||
canvas.drawLine( |
|||
this.origin, |
|||
this.origin.translate( |
|||
0.0f, |
|||
-(size.height - 2.0f * CupertinoTextSelectionUtils._kHandlesPadding) |
|||
), |
|||
paint |
|||
); |
|||
} |
|||
|
|||
public override bool shouldRepaint(CustomPainter oldPainter) { |
|||
_TextSelectionHandlePainter _oldPainter = (_TextSelectionHandlePainter) oldPainter; |
|||
return this.origin != _oldPainter.origin; |
|||
} |
|||
} |
|||
|
|||
class _CupertinoTextSelectionControls : TextSelectionControls { |
|||
public override Size handleSize { |
|||
get { return CupertinoTextSelectionUtils._kSelectionOffset; } |
|||
} |
|||
|
|||
public override Widget buildToolbar(BuildContext context, Rect globalEditableRegion, Offset position, |
|||
TextSelectionDelegate del) { |
|||
D.assert(WidgetsD.debugCheckHasMediaQuery(context)); |
|||
return new ConstrainedBox( |
|||
constraints: BoxConstraints.tight(globalEditableRegion.size), |
|||
child: new CustomSingleChildLayout( |
|||
layoutDelegate: new _TextSelectionToolbarLayout( |
|||
MediaQuery.of(context).size, |
|||
globalEditableRegion, |
|||
position |
|||
), |
|||
child: new _TextSelectionToolbar( |
|||
handleCut: this.canCut(del) ? () => this.handleCut(del) : (VoidCallback) null, |
|||
handleCopy: this.canCopy(del) ? () => this.handleCopy(del) : (VoidCallback) null, |
|||
handlePaste: this.canPaste(del) ? () => this.handlePaste(del) : (VoidCallback) null, |
|||
handleSelectAll: this.canSelectAll(del) ? () => this.handleSelectAll(del) : (VoidCallback) null |
|||
) |
|||
) |
|||
); |
|||
} |
|||
|
|||
|
|||
public override Widget buildHandle(BuildContext context, TextSelectionHandleType type, float textLineHeight) { |
|||
Size desiredSize = new Size( |
|||
2.0f * CupertinoTextSelectionUtils._kHandlesPadding, |
|||
textLineHeight + 2.0f * CupertinoTextSelectionUtils._kHandlesPadding |
|||
); |
|||
|
|||
Widget handle = SizedBox.fromSize( |
|||
size: desiredSize, |
|||
child: new CustomPaint( |
|||
painter: new _TextSelectionHandlePainter( |
|||
origin: new Offset(CupertinoTextSelectionUtils._kHandlesPadding, |
|||
textLineHeight + CupertinoTextSelectionUtils._kHandlesPadding) |
|||
) |
|||
) |
|||
); |
|||
|
|||
switch (type) { |
|||
case TextSelectionHandleType.left: |
|||
Matrix3 matrix = Matrix3.makeRotate(Mathf.PI); |
|||
matrix.preTranslate(-CupertinoTextSelectionUtils._kHandlesPadding, |
|||
-CupertinoTextSelectionUtils._kHandlesPadding); |
|||
|
|||
return new Transform( |
|||
transform: matrix, |
|||
child: handle |
|||
); |
|||
case TextSelectionHandleType.right: |
|||
return new Transform( |
|||
transform: Matrix3.makeTrans( |
|||
-CupertinoTextSelectionUtils._kHandlesPadding, |
|||
-(textLineHeight + CupertinoTextSelectionUtils._kHandlesPadding) |
|||
), |
|||
child: handle |
|||
); |
|||
case TextSelectionHandleType.collapsed: |
|||
return new Container(); |
|||
} |
|||
|
|||
return null; |
|||
} |
|||
} |
|||
} |
|
|||
fileFormatVersion: 2 |
|||
guid: 2afc9187fdd8b4f7abbb404a4cb3cf71 |
|||
MonoImporter: |
|||
externalObjects: {} |
|||
serializedVersion: 2 |
|||
defaultReferences: [] |
|||
executionOrder: 0 |
|||
icon: {instanceID: 0} |
|||
userData: |
|||
assetBundleName: |
|||
assetBundleVariant: |
|
|||
using Unity.UIWidgets.painting; |
|||
using Unity.UIWidgets.ui; |
|||
|
|||
namespace Unity.UIWidgets.cupertino { |
|||
public class CupertinoThumbPainter { |
|||
public CupertinoThumbPainter( |
|||
Color color = null, |
|||
Color shadowColor = null |
|||
) { |
|||
this._shadowPaint = new BoxShadow( |
|||
color: shadowColor, |
|||
blurRadius: 1.0f |
|||
).toPaint(); |
|||
|
|||
this.color = color ?? CupertinoColors.white; |
|||
this.shadowColor = shadowColor ?? new Color(0x2C000000); |
|||
} |
|||
|
|||
public readonly Color color; |
|||
|
|||
public readonly Color shadowColor; |
|||
|
|||
public readonly Paint _shadowPaint; |
|||
|
|||
public const float radius = 14.0f; |
|||
|
|||
public const float extension = 7.0f; |
|||
|
|||
public void paint(Canvas canvas, Rect rect) { |
|||
RRect rrect = RRect.fromRectAndRadius( |
|||
rect, |
|||
Radius.circular(rect.shortestSide / 2.0f) |
|||
); |
|||
|
|||
canvas.drawRRect(rrect, this._shadowPaint); |
|||
canvas.drawRRect(rrect.shift(new Offset(0.0f, 3.0f)), this._shadowPaint); |
|||
var _paint = new Paint(); |
|||
_paint.color = this.color; |
|||
canvas.drawRRect(rrect, _paint); |
|||
} |
|||
} |
|||
} |
|
|||
fileFormatVersion: 2 |
|||
guid: 47bbdd4359daa489bb16dfd37b505cb7 |
|||
MonoImporter: |
|||
externalObjects: {} |
|||
serializedVersion: 2 |
|||
defaultReferences: [] |
|||
executionOrder: 0 |
|||
icon: {instanceID: 0} |
|||
userData: |
|||
assetBundleName: |
|||
assetBundleVariant: |
|
|||
using Unity.UIWidgets.foundation; |
|||
|
|||
namespace Unity.UIWidgets.widgets { |
|||
public delegate Widget ValueWidgetBuilder<T>(BuildContext context, T value, Widget child); |
|||
|
|||
public class ValueListenableBuilder<T> : StatefulWidget { |
|||
public ValueListenableBuilder( |
|||
ValueListenable<T> valueListenable, |
|||
ValueWidgetBuilder<T> builder, |
|||
Widget child = null |
|||
) { |
|||
D.assert(valueListenable != null); |
|||
D.assert(builder != null); |
|||
this.valueListenable = valueListenable; |
|||
this.builder = builder; |
|||
this.child = child; |
|||
} |
|||
|
|||
public readonly ValueListenable<T> valueListenable; |
|||
|
|||
public readonly ValueWidgetBuilder<T> builder; |
|||
|
|||
public readonly Widget child; |
|||
|
|||
public override State createState() { |
|||
return new _ValueListenableBuilderState<T>(); |
|||
} |
|||
} |
|||
|
|||
class _ValueListenableBuilderState<T> : State<ValueListenableBuilder<T>> { |
|||
T value; |
|||
|
|||
public override void initState() { |
|||
base.initState(); |
|||
this.value = this.widget.valueListenable.value; |
|||
this.widget.valueListenable.addListener(this._valueChanged); |
|||
} |
|||
|
|||
public override void didUpdateWidget(StatefulWidget _oldWidget) { |
|||
ValueListenableBuilder<T> oldWidget = _oldWidget as ValueListenableBuilder<T>; |
|||
if (oldWidget.valueListenable != this.widget.valueListenable) { |
|||
oldWidget.valueListenable.removeListener(this._valueChanged); |
|||
this.value = this.widget.valueListenable.value; |
|||
this.widget.valueListenable.addListener(this._valueChanged); |
|||
} |
|||
|
|||
base.didUpdateWidget(oldWidget); |
|||
} |
|||
|
|||
public override void dispose() { |
|||
this.widget.valueListenable.removeListener(this._valueChanged); |
|||
base.dispose(); |
|||
} |
|||
|
|||
void _valueChanged() { |
|||
this.setState(() => { this.value = this.widget.valueListenable.value; }); |
|||
} |
|||
|
|||
public override Widget build(BuildContext context) { |
|||
return this.widget.builder(context, this.value, this.widget.child); |
|||
} |
|||
} |
|||
} |
|
|||
fileFormatVersion: 2 |
|||
guid: c4b7ae22b588cdf4093501087a4ecadb |
|||
MonoImporter: |
|||
externalObjects: {} |
|||
serializedVersion: 2 |
|||
defaultReferences: [] |
|||
executionOrder: 0 |
|||
icon: {instanceID: 0} |
|||
userData: |
|||
assetBundleName: |
|||
assetBundleVariant: |
|
|||
using Unity.UIWidgets.animation; |
|||
using Unity.UIWidgets.cupertino; |
|||
using Unity.UIWidgets.editor; |
|||
using Unity.UIWidgets.foundation; |
|||
using Unity.UIWidgets.painting; |
|||
using Unity.UIWidgets.ui; |
|||
using Unity.UIWidgets.widgets; |
|||
using UnityEditor; |
|||
using UnityEngine; |
|||
using Rect = UnityEngine.Rect; |
|||
|
|||
namespace UIWidgetsSample { |
|||
public class CupertinoSample : UIWidgetsEditorWindow { |
|||
[MenuItem("UIWidgetsTests/CupertinoSample")] |
|||
public static void gallery() { |
|||
GetWindow<CupertinoSample>(); |
|||
} |
|||
|
|||
protected override void OnEnable() { |
|||
FontManager.instance.addFont(Resources.Load<Font>("CupertinoIcons"), "CupertinoIcons"); |
|||
base.OnEnable(); |
|||
} |
|||
|
|||
protected override Widget createWidget() { |
|||
Debug.Log("[Cupertino Sample] Created"); |
|||
return new CupertinoSampleApp(); |
|||
} |
|||
} |
|||
|
|||
|
|||
public class CupertinoSampleApp : StatelessWidget { |
|||
public override Widget build(BuildContext context) { |
|||
return new CupertinoApp( |
|||
theme: new CupertinoThemeData( |
|||
textTheme: new CupertinoTextThemeData( |
|||
navLargeTitleTextStyle: new TextStyle( |
|||
fontWeight: FontWeight.bold, |
|||
fontSize: 70f, |
|||
color: CupertinoColors.activeBlue |
|||
) |
|||
)), |
|||
home: new CupertinoSampleWidget() |
|||
); |
|||
} |
|||
} |
|||
|
|||
public class CupertinoSampleWidget : StatefulWidget { |
|||
public CupertinoSampleWidget(Key key = null) : base(key) { } |
|||
|
|||
public override State createState() { |
|||
return new CupertinoSampleWidgetState(); |
|||
} |
|||
} |
|||
|
|||
public class CupertinoSampleWidgetState : State<CupertinoSampleWidget> { |
|||
public override Widget build(BuildContext context) { |
|||
return new CupertinoPageScaffold( |
|||
child: new Center( |
|||
child: new Text("Hello Cupertino", |
|||
style: CupertinoTheme.of(context).textTheme.navLargeTitleTextStyle |
|||
) |
|||
) |
|||
); |
|||
} |
|||
} |
|||
} |
|
|||
fileFormatVersion: 2 |
|||
guid: 92aa3442134248a38d03c2a24a8a9962 |
|||
timeCreated: 1566545424 |
|
|||
fileFormatVersion: 2 |
|||
guid: b971f24af9c984210a511bd0e81945a3 |
|||
folderAsset: yes |
|||
DefaultImporter: |
|||
externalObjects: {} |
|||
userData: |
|||
assetBundleName: |
|||
assetBundleVariant: |
1001
Tests/Resources/SF-Pro-Text-Bold.otf
文件差异内容过多而无法显示
查看文件
文件差异内容过多而无法显示
查看文件
|
|||
fileFormatVersion: 2 |
|||
guid: fe4433873da2c44a58194766452da171 |
|||
TrueTypeFontImporter: |
|||
externalObjects: {} |
|||
serializedVersion: 4 |
|||
fontSize: 16 |
|||
forceTextureCase: -2 |
|||
characterSpacing: 0 |
|||
characterPadding: 1 |
|||
includeFontData: 1 |
|||
fontName: SF Pro Text |
|||
fontNames: |
|||
- SF Pro Text |
|||
fallbackFontReferences: |
|||
- {fileID: 12800000, guid: d59013752e4e844828a89a2b96cfa704, type: 3} |
|||
- {fileID: 12800000, guid: a7b8140888514456bb2e63f86338624a, type: 3} |
|||
customCharacters: |
|||
fontRenderingMode: 0 |
|||
ascentCalculationMode: 1 |
|||
useLegacyBoundsCalculation: 0 |
|||
shouldRoundAdvanceValue: 1 |
|||
userData: |
|||
assetBundleName: |
|||
assetBundleVariant: |
1001
Tests/Resources/SF-Pro-Text-Regular.otf
文件差异内容过多而无法显示
查看文件
文件差异内容过多而无法显示
查看文件
|
|||
fileFormatVersion: 2 |
|||
guid: a7b8140888514456bb2e63f86338624a |
|||
TrueTypeFontImporter: |
|||
externalObjects: {} |
|||
serializedVersion: 4 |
|||
fontSize: 16 |
|||
forceTextureCase: -2 |
|||
characterSpacing: 0 |
|||
characterPadding: 1 |
|||
includeFontData: 1 |
|||
fontName: SF Pro Text |
|||
fontNames: |
|||
- SF Pro Text |
|||
fallbackFontReferences: [] |
|||
customCharacters: |
|||
fontRenderingMode: 0 |
|||
ascentCalculationMode: 1 |
|||
useLegacyBoundsCalculation: 0 |
|||
shouldRoundAdvanceValue: 1 |
|||
userData: |
|||
assetBundleName: |
|||
assetBundleVariant: |
1001
Tests/Resources/SF-Pro-Text-Semibold.otf
文件差异内容过多而无法显示
查看文件
文件差异内容过多而无法显示
查看文件
|
|||
fileFormatVersion: 2 |
|||
guid: d59013752e4e844828a89a2b96cfa704 |
|||
TrueTypeFontImporter: |
|||
externalObjects: {} |
|||
serializedVersion: 4 |
|||
fontSize: 16 |
|||
forceTextureCase: -2 |
|||
characterSpacing: 0 |
|||
characterPadding: 1 |
|||
includeFontData: 1 |
|||
fontName: SF Pro Text |
|||
fontNames: |
|||
- SF Pro Text |
|||
fallbackFontReferences: |
|||
- {fileID: 12800000, guid: a7b8140888514456bb2e63f86338624a, type: 3} |
|||
customCharacters: |
|||
fontRenderingMode: 0 |
|||
ascentCalculationMode: 1 |
|||
useLegacyBoundsCalculation: 0 |
|||
shouldRoundAdvanceValue: 1 |
|||
userData: |
|||
assetBundleName: |
|||
assetBundleVariant: |
|
|||
fileFormatVersion: 2 |
|||
guid: 00dd97e6ab3004c7485beababbe548ab |
|||
MonoImporter: |
|||
externalObjects: {} |
|||
serializedVersion: 2 |
|||
defaultReferences: [] |
|||
executionOrder: 0 |
|||
icon: {instanceID: 0} |
|||
userData: |
|||
assetBundleName: |
|||
assetBundleVariant: |
|
|||
using Unity.UIWidgets.cupertino; |
|||
using Unity.UIWidgets.widgets; |
|||
|
|||
namespace UIWidgetsGallery.gallery { |
|||
/* |
|||
class CupertinoProgressIndicatorDemo : StatelessWidget { |
|||
public static string routeName = "/cupertino/progress_indicator"; |
|||
|
|||
public override |
|||
Widget build(BuildContext context) { |
|||
return new CupertinoPageScaffold( |
|||
navigationBar: new CupertinoNavigationBar( |
|||
previousPageTitle: "Cupertino", |
|||
middle: new Text("Activity Indicator"), |
|||
trailing: new CupertinoDemoDocumentationButton(routeName) |
|||
), |
|||
child: new Center( |
|||
child: new CupertinoActivityIndicator() |
|||
) |
|||
); |
|||
} |
|||
} |
|||
*/ |
|||
} |
|
|||
fileFormatVersion: 2 |
|||
guid: cd9442c2f316e4ad1924fa656a7788a8 |
|||
MonoImporter: |
|||
externalObjects: {} |
|||
serializedVersion: 2 |
|||
defaultReferences: [] |
|||
executionOrder: 0 |
|||
icon: {instanceID: 0} |
|||
userData: |
|||
assetBundleName: |
|||
assetBundleVariant: |
|
|||
using System.Collections.Generic; |
|||
using Unity.UIWidgets.cupertino; |
|||
using Unity.UIWidgets.foundation; |
|||
using Unity.UIWidgets.painting; |
|||
using Unity.UIWidgets.widgets; |
|||
|
|||
namespace UIWidgetsGallery.gallery { |
|||
/* |
|||
class CupertinoAlertDemo : StatefulWidget { |
|||
public static string routeName = "/cupertino/alert"; |
|||
public override State createState() => new _CupertinoAlertDemoState(); |
|||
} |
|||
|
|||
class _CupertinoAlertDemoState : State<CupertinoAlertDemo> { |
|||
string lastSelectedValue; |
|||
|
|||
void showDemoDialog( |
|||
BuildContext context = null, |
|||
Widget child = null |
|||
) { |
|||
CupertinoRouteUtils.showCupertinoDialog<string>( |
|||
context: context, |
|||
builder: (BuildContext _context) => child |
|||
).Then((string value) => { |
|||
if (value != null) { |
|||
this.setState(() => { this.lastSelectedValue = value; }); |
|||
} |
|||
}); |
|||
} |
|||
|
|||
void showDemoActionSheet( |
|||
BuildContext context = null, |
|||
Widget child = null |
|||
) { |
|||
CupertinoRouteUtils.showCupertinoModalPopup<string>( |
|||
context: context, |
|||
builder: (BuildContext _context) => child |
|||
).Then((string value) => { |
|||
if (value != null) { |
|||
this.setState(() => { this.lastSelectedValue = value; }); |
|||
} |
|||
}); |
|||
} |
|||
|
|||
public override Widget build(BuildContext context) { |
|||
return new CupertinoPageScaffold( |
|||
navigationBar: new CupertinoNavigationBar( |
|||
middle: new Text("Alerts"), |
|||
previousPageTitle: "Cupertino", |
|||
trailing: new CupertinoDemoDocumentationButton(CupertinoAlertDemo.routeName) |
|||
), |
|||
child: |
|||
new DefaultTextStyle( |
|||
style: CupertinoTheme.of(context).textTheme.textStyle, |
|||
child: new Builder( |
|||
builder: (BuildContext _context) => { |
|||
List<Widget> stackChildren = new List<Widget> { |
|||
new ListView( |
|||
padding: EdgeInsets.symmetric(vertical: 24.0f, horizontal: 72.0f) |
|||
+ MediaQuery.of(_context).padding, |
|||
children: new List<Widget> { |
|||
CupertinoButton.filled( |
|||
child: new Text("Alert"), |
|||
onPressed: () => { |
|||
this.showDemoDialog( |
|||
context: _context, |
|||
child: new CupertinoAlertDialog( |
|||
title: new Text("Discard draft?"), |
|||
actions: new List<Widget> { |
|||
new CupertinoDialogAction( |
|||
child: new Text("Discard"), |
|||
isDestructiveAction: true, |
|||
onPressed: () => { Navigator.pop(_context, "Discard"); } |
|||
), |
|||
new CupertinoDialogAction( |
|||
child: new Text("Cancel"), |
|||
isDefaultAction: true, |
|||
onPressed: () => { Navigator.pop(_context, "Cancel"); } |
|||
), |
|||
} |
|||
) |
|||
); |
|||
} |
|||
), |
|||
new Padding(padding: EdgeInsets.all(8.0f)), |
|||
CupertinoButton.filled( |
|||
child: new Text("Alert with Title"), |
|||
padding: EdgeInsets.symmetric(vertical: 16.0f, horizontal: 36.0f), |
|||
onPressed: () => { |
|||
this.showDemoDialog( |
|||
context: _context, |
|||
child: new CupertinoAlertDialog( |
|||
title: new Text( |
|||
"Allow \"Maps\" to access your location while you are using the app?") |
|||
, |
|||
content: new Text( |
|||
"Your current location will be displayed on the map and used \n" + |
|||
"for directions, nearby search results, and estimated travel times.") |
|||
, |
|||
actions: new List<Widget> { |
|||
new CupertinoDialogAction( |
|||
child: new Text("Don\"t Allow"), |
|||
onPressed: () => { |
|||
Navigator.pop(_context, "Disallow"); |
|||
} |
|||
), |
|||
new CupertinoDialogAction( |
|||
child: new Text("Allow"), |
|||
onPressed: () => { Navigator.pop(_context, "Allow"); } |
|||
), |
|||
} |
|||
) |
|||
); |
|||
} |
|||
), |
|||
new Padding(padding: EdgeInsets.all(8.0f)), |
|||
CupertinoButton.filled( |
|||
child: new Text("Alert with Buttons"), |
|||
padding: EdgeInsets.symmetric(vertical: 16.0f, horizontal: 36.0f), |
|||
onPressed: () => { |
|||
this.showDemoDialog( |
|||
context: _context, |
|||
child: new CupertinoDessertDialog( |
|||
title: new Text("Select Favorite Dessert"), |
|||
content: new Text( |
|||
"Please select your favorite type of dessert from the \n" + |
|||
"list below. Your selection will be used to customize the suggested \n" + |
|||
"list of eateries in your area.") |
|||
) |
|||
); |
|||
} |
|||
), |
|||
new Padding(padding: EdgeInsets.all(8.0f)), |
|||
CupertinoButton.filled( |
|||
child: new Text("Alert Buttons Only"), |
|||
padding: EdgeInsets.symmetric(vertical: 16.0f, horizontal: 36.0f), |
|||
onPressed: () => { |
|||
this.showDemoDialog( |
|||
context: _context, |
|||
child: new CupertinoDessertDialog() |
|||
); |
|||
} |
|||
), |
|||
new Padding(padding: EdgeInsets.all(8.0f)), |
|||
CupertinoButton.filled( |
|||
child: new Text("Action Sheet"), |
|||
padding: EdgeInsets.symmetric(vertical: 16.0f, horizontal: 36.0f), |
|||
onPressed: () => { |
|||
this.showDemoActionSheet( |
|||
context: _context, |
|||
child: new CupertinoActionSheet( |
|||
title: new Text("Favorite Dessert"), |
|||
message: |
|||
new Text( |
|||
"Please select the best dessert from the options below."), |
|||
actions: |
|||
new List<Widget> { |
|||
new CupertinoActionSheetAction( |
|||
child: new Text("Profiteroles"), |
|||
onPressed: () => { |
|||
Navigator.pop(_context, "Profiteroles"); |
|||
} |
|||
), |
|||
new CupertinoActionSheetAction( |
|||
child: new Text("Cannolis"), |
|||
onPressed: () => { |
|||
Navigator.pop(_context, "Cannolis"); |
|||
} |
|||
), |
|||
new CupertinoActionSheetAction( |
|||
child: new Text("Trifle"), |
|||
onPressed: () => { Navigator.pop(_context, "Trifle"); } |
|||
), |
|||
}, |
|||
cancelButton: new CupertinoActionSheetAction( |
|||
child: new Text("Cancel"), |
|||
isDefaultAction: |
|||
true, |
|||
onPressed: |
|||
() => { Navigator.pop(_context, "Cancel"); } |
|||
) |
|||
) |
|||
); |
|||
} |
|||
) |
|||
} |
|||
) |
|||
}; |
|||
|
|||
if (this.lastSelectedValue != null) { |
|||
stackChildren.Add( |
|||
new Positioned( |
|||
bottom: 32.0f, |
|||
child: new Text("You selected: $lastSelectedValue") |
|||
) |
|||
); |
|||
} |
|||
|
|||
return new Stack( |
|||
alignment: Alignment.center, |
|||
children: stackChildren |
|||
); |
|||
} |
|||
) |
|||
) |
|||
); |
|||
} |
|||
} |
|||
|
|||
class CupertinoDessertDialog : StatelessWidget { |
|||
public CupertinoDessertDialog( |
|||
Key key = null, |
|||
Widget title = null, |
|||
Widget content = null |
|||
) : base(key: key) { |
|||
this.title = title; |
|||
this.content = content; |
|||
} |
|||
|
|||
public readonly Widget title; |
|||
public readonly Widget content; |
|||
|
|||
public override Widget build(BuildContext context) { |
|||
return new CupertinoAlertDialog( |
|||
title: title, |
|||
content: content, |
|||
actions: new List<Widget> { |
|||
new CupertinoDialogAction( |
|||
child: new Text("Cheesecake"), |
|||
onPressed: () => { Navigator.pop(context, "Cheesecake"); } |
|||
), |
|||
new CupertinoDialogAction( |
|||
child: new Text("Tiramisu"), |
|||
onPressed: () => { Navigator.pop(context, "Tiramisu"); } |
|||
), |
|||
new CupertinoDialogAction( |
|||
child: new Text("Apple Pie"), |
|||
onPressed: |
|||
() => { Navigator.pop(context, "Apple Pie"); } |
|||
), |
|||
new CupertinoDialogAction( |
|||
child: new Text("Devil\"s food cake"), |
|||
onPressed: |
|||
() => { Navigator.pop(context, "Devil\"s food cake"); } |
|||
), |
|||
new CupertinoDialogAction( |
|||
child: new Text("Banana Split"), |
|||
onPressed: |
|||
() => { Navigator.pop(context, "Banana Split"); } |
|||
), |
|||
new CupertinoDialogAction( |
|||
child: new Text("Oatmeal Cookie"), |
|||
onPressed: |
|||
() => { Navigator.pop(context, "Oatmeal Cookies"); } |
|||
), |
|||
new CupertinoDialogAction( |
|||
child: new Text("Chocolate Brownie"), |
|||
onPressed: |
|||
() => { Navigator.pop(context, "Chocolate Brownies"); } |
|||
), |
|||
new CupertinoDialogAction( |
|||
child: new Text("Cancel"), |
|||
isDestructiveAction: |
|||
true, |
|||
onPressed: |
|||
() => { Navigator.pop(context, "Cancel"); } |
|||
), |
|||
} |
|||
); |
|||
} |
|||
} |
|||
*/ |
|||
} |
|
|||
fileFormatVersion: 2 |
|||
guid: fcd454968bdd543c181c3bde5aee8651 |
|||
MonoImporter: |
|||
externalObjects: {} |
|||
serializedVersion: 2 |
|||
defaultReferences: [] |
|||
executionOrder: 0 |
|||
icon: {instanceID: 0} |
|||
userData: |
|||
assetBundleName: |
|||
assetBundleVariant: |
|
|||
using System.Collections.Generic; |
|||
using Unity.UIWidgets.cupertino; |
|||
using Unity.UIWidgets.painting; |
|||
using Unity.UIWidgets.rendering; |
|||
using Unity.UIWidgets.widgets; |
|||
|
|||
namespace UIWidgetsGallery.gallery { |
|||
class CupertinoButtonsDemo : StatefulWidget { |
|||
public static string routeName = "/cupertino/buttons"; |
|||
|
|||
public override State createState() { |
|||
return new _CupertinoButtonDemoState(); |
|||
} |
|||
} |
|||
|
|||
class _CupertinoButtonDemoState : State<CupertinoButtonsDemo> { |
|||
int _pressedCount = 0; |
|||
|
|||
|
|||
public override Widget build(BuildContext context) { |
|||
return new CupertinoPageScaffold( |
|||
navigationBar: new CupertinoNavigationBar( |
|||
middle: new Text("Buttons"), |
|||
previousPageTitle: "Cupertino", |
|||
trailing: new CupertinoDemoDocumentationButton(CupertinoButtonsDemo.routeName) |
|||
), |
|||
child: new DefaultTextStyle( |
|||
style: CupertinoTheme.of(context).textTheme.textStyle, |
|||
child: new SafeArea( |
|||
child: new Column( |
|||
children: new List<Widget> { |
|||
new Padding( |
|||
padding: EdgeInsets.all(16.0f), |
|||
child: new Text( |
|||
"iOS themed buttons are flat. They can have borders or backgrounds but only when necessary." |
|||
) |
|||
), |
|||
new Expanded( |
|||
child: new Column( |
|||
mainAxisAlignment: MainAxisAlignment.center, |
|||
children: new List<Widget> { |
|||
new Text(this._pressedCount > 0 |
|||
? $"Button pressed {this._pressedCount} time" + |
|||
(this._pressedCount == 1 ? "" : "s") |
|||
: " "), |
|||
new Padding(padding: EdgeInsets.all(12.0f)), |
|||
new Align( |
|||
alignment: new Alignment(0.0f, -0.2f), |
|||
child: |
|||
new Row( |
|||
mainAxisSize: MainAxisSize.min, |
|||
children: new List<Widget> { |
|||
new CupertinoButton( |
|||
child: new Text("Cupertino Button"), |
|||
onPressed: |
|||
() => { this.setState(() => { this._pressedCount += 1; }); } |
|||
), |
|||
new CupertinoButton( |
|||
child: new Text("Disabled"), |
|||
onPressed: null |
|||
) |
|||
} |
|||
) |
|||
), |
|||
new Padding(padding: EdgeInsets.all(12.0f)), |
|||
CupertinoButton.filled( |
|||
child: new Text("With Background"), |
|||
onPressed: |
|||
() => { this.setState(() => { this._pressedCount += 1; }); } |
|||
), |
|||
new Padding(padding: EdgeInsets.all(12.0f)), |
|||
CupertinoButton.filled( |
|||
child: new Text("Disabled"), |
|||
onPressed: null |
|||
), |
|||
} |
|||
) |
|||
) |
|||
} |
|||
) |
|||
) |
|||
) |
|||
); |
|||
} |
|||
} |
|||
} |
|
|||
namespace UIWidgetsGallery.gallery { |
|||
public class cupertino_navigation_demo { |
|||
|
|||
} |
|||
} |
|
|||
using System.Collections.Generic; |
|||
using Unity.UIWidgets.cupertino; |
|||
using Unity.UIWidgets.rendering; |
|||
using Unity.UIWidgets.widgets; |
|||
|
|||
namespace UIWidgetsGallery.gallery { |
|||
class CupertinoSliderDemo : StatefulWidget { |
|||
public static string routeName = "/cupertino/slider"; |
|||
|
|||
public override State createState() { |
|||
return new _CupertinoSliderDemoState(); |
|||
} |
|||
} |
|||
|
|||
class _CupertinoSliderDemoState : State<CupertinoSliderDemo> { |
|||
float _value = 25.0f; |
|||
float _discreteValue = 20.0f; |
|||
|
|||
public override Widget build(BuildContext context) { |
|||
return new CupertinoPageScaffold( |
|||
navigationBar: new CupertinoNavigationBar( |
|||
middle: new Text("Sliders"), |
|||
previousPageTitle: "Cupertino", |
|||
trailing: new CupertinoDemoDocumentationButton(CupertinoSliderDemo.routeName) |
|||
), |
|||
child: new DefaultTextStyle( |
|||
style: CupertinoTheme.of(context).textTheme.textStyle, |
|||
child: new SafeArea( |
|||
child: new Center( |
|||
child: new Column( |
|||
mainAxisAlignment: MainAxisAlignment.spaceAround, |
|||
children: new List<Widget> { |
|||
new Column( |
|||
mainAxisSize: MainAxisSize.min, |
|||
children: new List<Widget> { |
|||
new CupertinoSlider( |
|||
value: this._value, |
|||
min: 0.0f, |
|||
max: 100.0f, |
|||
divisions: 100, // TODO: FIX BUG
|
|||
onChanged: (float value) => { |
|||
this.setState(() => { this._value = value; }); |
|||
} |
|||
), |
|||
new Text($"Cupertino Continuous: {this._value.ToString("F1")}"), |
|||
} |
|||
), |
|||
new Column( |
|||
mainAxisSize: MainAxisSize.min, |
|||
children: new List<Widget> { |
|||
new CupertinoSlider( |
|||
value: this._discreteValue, |
|||
min: 0.0f, |
|||
max: 100.0f, |
|||
divisions: 5, |
|||
onChanged: (float value) => { |
|||
this.setState(() => { this._discreteValue = value; }); |
|||
} |
|||
), |
|||
new Text($"Cupertino Discrete: {this._discreteValue}"), |
|||
} |
|||
), |
|||
} |
|||
) |
|||
) |
|||
) |
|||
) |
|||
); |
|||
} |
|||
} |
|||
} |
|
|||
fileFormatVersion: 2 |
|||
guid: 172d1ae6d262e45d4a131a02d85ddf44 |
|||
MonoImporter: |
|||
externalObjects: {} |
|||
serializedVersion: 2 |
|||
defaultReferences: [] |
|||
executionOrder: 0 |
|||
icon: {instanceID: 0} |
|||
userData: |
|||
assetBundleName: |
|||
assetBundleVariant: |
|
|||
using System.Collections.Generic; |
|||
using Unity.UIWidgets.cupertino; |
|||
using Unity.UIWidgets.rendering; |
|||
using Unity.UIWidgets.widgets; |
|||
|
|||
namespace UIWidgetsGallery.gallery { |
|||
class CupertinoSwitchDemo : StatefulWidget { |
|||
public static string routeName = "/cupertino/switch"; |
|||
|
|||
public override State createState() => new _CupertinoSwitchDemoState(); |
|||
} |
|||
|
|||
class _CupertinoSwitchDemoState : State<CupertinoSwitchDemo> { |
|||
bool _switchValue = false; |
|||
|
|||
public override Widget build(BuildContext context) { |
|||
return new CupertinoPageScaffold( |
|||
navigationBar: new CupertinoNavigationBar( |
|||
middle: new Text("Switch"), |
|||
previousPageTitle: "Cupertino", |
|||
trailing: new CupertinoDemoDocumentationButton(CupertinoSwitchDemo.routeName) |
|||
), |
|||
child: new DefaultTextStyle( |
|||
style: CupertinoTheme.of(context).textTheme.textStyle, |
|||
child: new SafeArea( |
|||
child: new Center( |
|||
child: new Column( |
|||
mainAxisAlignment: MainAxisAlignment.spaceAround, |
|||
children: new List<Widget> { |
|||
new Column( |
|||
children: new List<Widget> { |
|||
new CupertinoSwitch( |
|||
value: this._switchValue, |
|||
onChanged: (bool value) => { |
|||
this.setState(() => { this._switchValue = value; }); |
|||
} |
|||
), |
|||
new Text( |
|||
"Enabled - " + (this._switchValue ? "On" : "Off") |
|||
), |
|||
} |
|||
), |
|||
new Column( |
|||
children: new List<Widget> { |
|||
new CupertinoSwitch( |
|||
value: true, |
|||
onChanged: null |
|||
), |
|||
new Text( |
|||
"Disabled - On" |
|||
), |
|||
} |
|||
), |
|||
new Column( |
|||
children: new List<Widget> { |
|||
new CupertinoSwitch( |
|||
value: false, |
|||
onChanged: null |
|||
), |
|||
new Text( |
|||
"Disabled - Off" |
|||
), |
|||
} |
|||
) |
|||
} |
|||
) |
|||
) |
|||
) |
|||
) |
|||
); |
|||
} |
|||
} |
|||
} |
|
|||
fileFormatVersion: 2 |
|||
guid: 6f9a95d09a56a495f8878fd15b5aed4b |
|||
MonoImporter: |
|||
externalObjects: {} |
|||
serializedVersion: 2 |
|||
defaultReferences: [] |
|||
executionOrder: 0 |
|||
icon: {instanceID: 0} |
|||
userData: |
|||
assetBundleName: |
|||
assetBundleVariant: |
|
|||
using System.Collections.Generic; |
|||
using Unity.UIWidgets.cupertino; |
|||
using Unity.UIWidgets.painting; |
|||
using Unity.UIWidgets.service; |
|||
using Unity.UIWidgets.widgets; |
|||
|
|||
namespace UIWidgetsGallery.gallery { |
|||
class CupertinoTextFieldDemo : StatefulWidget { |
|||
public const string routeName = "/cupertino/text_fields"; |
|||
|
|||
public override State createState() { |
|||
return new _CupertinoTextFieldDemoState(); |
|||
} |
|||
} |
|||
|
|||
class _CupertinoTextFieldDemoState : State<CupertinoTextFieldDemo> { |
|||
TextEditingController _chatTextController; |
|||
TextEditingController _locationTextController; |
|||
|
|||
public override void initState() { |
|||
base.initState(); |
|||
this._chatTextController = new TextEditingController(); |
|||
this._locationTextController = new TextEditingController(text: "Montreal, Canada"); |
|||
} |
|||
|
|||
Widget _buildChatTextField() { |
|||
return new CupertinoTextField( |
|||
controller: this._chatTextController, |
|||
textCapitalization: TextCapitalization.sentences, |
|||
placeholder: "Text Message", |
|||
decoration: new BoxDecoration( |
|||
border: Border.all( |
|||
width: 0.0f, |
|||
color: CupertinoColors.inactiveGray |
|||
), |
|||
borderRadius: BorderRadius.circular(15.0f) |
|||
), |
|||
maxLines: null, |
|||
keyboardType: TextInputType.multiline, |
|||
prefix: new Padding(padding: EdgeInsets.symmetric(horizontal: 4.0f)), |
|||
suffix: |
|||
new Padding( |
|||
padding: EdgeInsets.symmetric(horizontal: 4.0f), |
|||
child: new CupertinoButton( |
|||
color: CupertinoColors.activeGreen, |
|||
minSize: 0.0f, |
|||
child: new Icon( |
|||
CupertinoIcons.up_arrow, |
|||
size: 21.0f, |
|||
color: CupertinoColors.white |
|||
), |
|||
padding: EdgeInsets.all(2.0f), |
|||
borderRadius: |
|||
BorderRadius.circular(15.0f), |
|||
onPressed: () => this.setState(() => this._chatTextController.clear()) |
|||
) |
|||
), |
|||
autofocus: true, |
|||
suffixMode: OverlayVisibilityMode.editing, |
|||
onSubmitted: (string text) => this.setState(() => this._chatTextController.clear()) |
|||
); |
|||
} |
|||
|
|||
Widget _buildNameField() { |
|||
return new CupertinoTextField( |
|||
prefix: new Icon( |
|||
CupertinoIcons.person_solid, |
|||
color: CupertinoColors.lightBackgroundGray, |
|||
size: 28.0f |
|||
), |
|||
padding: EdgeInsets.symmetric(horizontal: 6.0f, vertical: 12.0f), |
|||
clearButtonMode: OverlayVisibilityMode.editing, |
|||
textCapitalization: TextCapitalization.words, |
|||
autocorrect: false, |
|||
decoration: new BoxDecoration( |
|||
border: new Border(bottom: new BorderSide(width: 0.0f, color: CupertinoColors.inactiveGray)) |
|||
), |
|||
placeholder: "Name" |
|||
); |
|||
} |
|||
|
|||
Widget _buildEmailField() { |
|||
return new CupertinoTextField( |
|||
prefix: new Icon( |
|||
CupertinoIcons.mail_solid, |
|||
color: CupertinoColors.lightBackgroundGray, |
|||
size: 28.0f |
|||
), |
|||
padding: EdgeInsets.symmetric(horizontal: 6.0f, vertical: 12.0f), |
|||
clearButtonMode: OverlayVisibilityMode.editing, |
|||
keyboardType: TextInputType.emailAddress, |
|||
autocorrect: false, |
|||
decoration: new BoxDecoration( |
|||
border: new Border(bottom: new BorderSide(width: 0.0f, color: CupertinoColors.inactiveGray)) |
|||
), |
|||
placeholder: "Email" |
|||
); |
|||
} |
|||
|
|||
Widget _buildLocationField() { |
|||
return new CupertinoTextField( |
|||
controller: this._locationTextController, |
|||
prefix: new Icon( |
|||
CupertinoIcons.location_solid, |
|||
color: CupertinoColors.lightBackgroundGray, |
|||
size: 28.0f |
|||
), |
|||
padding: EdgeInsets.symmetric(horizontal: 6.0f, vertical: 12.0f), |
|||
clearButtonMode: OverlayVisibilityMode.editing, |
|||
textCapitalization: TextCapitalization.words, |
|||
decoration: new BoxDecoration( |
|||
border: new Border(bottom: new BorderSide(width: 0.0f, color: CupertinoColors.inactiveGray)) |
|||
), |
|||
placeholder: "Location" |
|||
); |
|||
} |
|||
|
|||
Widget _buildPinField() { |
|||
return new CupertinoTextField( |
|||
prefix: new Icon( |
|||
CupertinoIcons.padlock_solid, |
|||
color: CupertinoColors.lightBackgroundGray, |
|||
size: 28.0f |
|||
), |
|||
padding: EdgeInsets.symmetric(horizontal: 6.0f, vertical: 12.0f), |
|||
clearButtonMode: OverlayVisibilityMode.editing, |
|||
keyboardType: TextInputType.number, |
|||
autocorrect: false, |
|||
obscureText: true, |
|||
decoration: new BoxDecoration( |
|||
border: new Border(bottom: new BorderSide(width: 0.0f, color: CupertinoColors.inactiveGray)) |
|||
), |
|||
placeholder: "Create a PIN" |
|||
); |
|||
} |
|||
|
|||
Widget _buildTagsField() { |
|||
return new CupertinoTextField( |
|||
controller: new TextEditingController(text: "colleague, reading club"), |
|||
prefix: new Icon( |
|||
CupertinoIcons.tags_solid, |
|||
color: CupertinoColors.lightBackgroundGray, |
|||
size: 28.0f |
|||
), |
|||
enabled: false, |
|||
padding: EdgeInsets.symmetric(horizontal: 6.0f, vertical: 12.0f), |
|||
decoration: new BoxDecoration( |
|||
border: new Border(bottom: new BorderSide(width: 0.0f, color: CupertinoColors.inactiveGray)) |
|||
) |
|||
); |
|||
} |
|||
|
|||
public override Widget build(BuildContext context) { |
|||
return new DefaultTextStyle( |
|||
style: new TextStyle( |
|||
fontFamily: ".SF Pro Text", // ".SF UI Text",
|
|||
inherit: false, |
|||
fontSize: 17.0f, |
|||
color: CupertinoColors.black |
|||
), |
|||
child: new CupertinoPageScaffold( |
|||
navigationBar: new CupertinoNavigationBar( |
|||
previousPageTitle: "Cupertino", |
|||
middle: new Text("Text Fields") |
|||
), |
|||
child: new SafeArea( |
|||
child: new ListView( |
|||
children: new List<Widget> { |
|||
new Padding( |
|||
padding: EdgeInsets.symmetric(vertical: 32.0f, horizontal: 16.0f), |
|||
child: new Column( |
|||
children: new List<Widget> { |
|||
this._buildNameField(), |
|||
this._buildEmailField(), |
|||
this._buildLocationField(), |
|||
this._buildPinField(), |
|||
this._buildTagsField(), |
|||
} |
|||
) |
|||
), |
|||
new Padding( |
|||
padding: EdgeInsets.symmetric(vertical: 32.0f, horizontal: 16.0f), |
|||
child: this._buildChatTextField() |
|||
), |
|||
} |
|||
) |
|||
) |
|||
) |
|||
); |
|||
} |
|||
} |
|||
} |
|
|||
fileFormatVersion: 2 |
|||
guid: 38c40bf70348345f5bc7e93853e451fd |
|||
MonoImporter: |
|||
externalObjects: {} |
|||
serializedVersion: 2 |
|||
defaultReferences: [] |
|||
executionOrder: 0 |
|||
icon: {instanceID: 0} |
|||
userData: |
|||
assetBundleName: |
|||
assetBundleVariant: |
撰写
预览
正在加载...
取消
保存
Reference in new issue