UIWidgets
UIWidgets copied to clipboard
Is it possible to add another package of pub.dev to use it?
I'm curious how to do it if possible. Thank you
Probably not. As the document said,this package is not another copy of flutter. It has different implementations.
Thank you for answer. By the way, I've been struggling with a Dialog issue for a week now. Could you please tell me what the problem is?
My source code
using Unity.UIWidgets.engine;
using Unity.UIWidgets.material;
using Unity.UIWidgets.painting;
using Unity.UIWidgets.ui;
using Unity.UIWidgets.widgets;
using UnityEngine;
using System;
using System.Collections.Generic;
public class GalleryEX : UIWidgetsPanel
{
protected override Widget createWidget()
{
return new MyGallery(
);
}
protected override void OnEnable()
{
FontManager.instance.addFont(Resources.Load<Font>("MaterialIcons-Regular"), "Material Icons");
FontManager.instance.addFont(Resources.Load<Font>("GalleryIcons"), "GalleryIcons");
FontManager.instance.addFont(Resources.Load<Font>("CupertinoIcons"), "CupertinoIcons");
FontManager.instance.addFont(Resources.Load<Font>(path: "SF-Pro-Text-Regular"), ".SF Pro Text", FontWeight.w400);
FontManager.instance.addFont(Resources.Load<Font>(path: "SF-Pro-Text-Semibold"), ".SF Pro Text", FontWeight.w600);
FontManager.instance.addFont(Resources.Load<Font>(path: "SF-Pro-Text-Bold"), ".SF Pro Text", FontWeight.w700);
base.OnEnable();
}
}
class MyGallery : StatefulWidget
{
public override State createState()
{
return new _MyGalleryState();
}
}
class _MyGalleryState : State<MyGallery>
{
Unity.UIWidgets.ui.Color pColor = Colors.blueAccent;
int _idx = 0;
List<string> menuList = new List<string> { "메인", "측정일지", "메뉴", "커뮤니티", "프리미엄" };
List<Widget> pageList = new List<Widget>
{
new ListView(
padding: EdgeInsets.all(20)
)
,
};
public override Widget build(BuildContext context)
{
TextStyle _normalSt = new TextStyle(color: Colors.grey);
Widget home = new Scaffold(
appBar: new AppBar(
backgroundColor: pColor
, title: new Text(menuList[_idx]
, style: new TextStyle(color: Colors.white)
)
, centerTitle: true
, leading: new BackButton(color: Colors.white)
, actions: new List<Widget>
{
new IconButton(icon: new Icon(icon:Icons.menu, color:Colors.white))
}
)
, body: new Column(
children: new List<Widget>{
new RaisedButton(
child: new Text("Select Date"),
onPressed: ()=>{
Debug.Log("aaa");
/*Unity.UIWidgets.material.DialogUtils.showDialog(context:context , builder: (_context)=>
{
return new AlertDialog(
actions: new List<Widget>
{
new FlatButton(child: new Text("Close"),
onPressed: ()=>{
Navigator.pop(_context);
}
)
}
);
}
);*/
/*DatePickerUtils.showDatePicker(
context:context,
initialDate:DateTime.Now,
firstDate:new DateTime(2020),
lastDate:new DateTime(2030),
selectableDayPredicate: _decideWhichDayToEnable
)*/;
Navigator.of(context);
Unity.UIWidgets.material.DialogUtils.showDialog(context:context, builder:(_context)=>{
return new AlertDialog();
}
).Then((p)=>{Debug.Log("das"); });
}
)
}
)
, bottomNavigationBar: new BottomNavigationBar(
selectedItemColor: pColor,
onTap: (index) =>
{
setState(() =>
{
_idx = index;
Debug.Log(_idx);
});
}
, currentIndex: _idx
,
items:
new List<BottomNavigationBarItem>()
{
new BottomNavigationBarItem(icon: new Icon(icon: Icons.home, color: Colors.grey) ,title: new Text("Home" , style: _normalSt), activeIcon:new Icon(icon: Icons.home, color: pColor)),
new BottomNavigationBarItem(icon: new Icon(icon: Icons.book, color: Colors.grey) ,title: new Text("Diary" , style: _normalSt), activeIcon:new Icon(icon: Icons.book, color: pColor)),
new BottomNavigationBarItem(icon: new Icon(icon: Icons.check, color: Colors.grey) ,title: new Text("Menu" , style: _normalSt), activeIcon:new Icon(icon: Icons.check, color: pColor)),
new BottomNavigationBarItem(icon: new Icon(icon: Icons.sms, color: Colors.grey) ,title: new Text("SNS", style: _normalSt), activeIcon:new Icon(icon: Icons.sms, color: pColor)),
new BottomNavigationBarItem(icon: new Icon(icon: Icons.chat, color: Colors.grey) ,title: new Text("Premium" , style: _normalSt), activeIcon:new Icon(icon: Icons.chat, color: pColor)),
}
// , type:BottomNavigationBarType.fix
)
);
return new MaterialApp(
home: home
);
}
bool _decideWhichDayToEnable(DateTime day)
{
if ((day-DateTime.Now).TotalDays>0 &&
(DateTime.Now-day).TotalDays>10)
{
return true;
}
return false;
}
public override void initState()
{
base.initState();
}
public override void dispose()
{
base.dispose();
}
}
Error Message
AssertionError: Error caught by gesture, thrown while handling a gesture. Object reference not set to an instance of an object
Handler: onTap
Recognizer:
Unity.UIWidgets.gestures.TapGestureRecognizer#E6C00
at Unity.UIWidgets.widgets.DialogUtils.showGeneralDialog (Unity.UIWidgets.widgets.BuildContext context, Unity.UIWidgets.widgets.RoutePageBuilder pageBuilder, System.Boolean barrierDismissible, Unity.UIWidgets.ui.Color barrierColor, System.Nullable`1[T] transitionDuration, Unity.UIWidgets.widgets.RouteTransitionsBuilder transitionBuilder) [0x00001] in D:\study\App_Practice\Assets\UIWidgets\Runtime\widgets\routes.cs:822
at Unity.UIWidgets.material.DialogUtils.showDialog (Unity.UIWidgets.widgets.BuildContext context, System.Boolean barrierDismissible, Unity.UIWidgets.widgets.WidgetBuilder builder) [0x0001b] in D:\study\App_Practice\Assets\UIWidgets\Runtime\material\dialog.cs:296
at _MyGalleryState+<>c__DisplayClass4_0.<build>b__0 () [0x0001b] in D:\study\App_Practice\Assets\Script\GalleryEX.cs:114
at Unity.UIWidgets.material._RawMaterialButtonState.<build>b__3_0 () [0x00014] in D:\study\App_Practice\Assets\UIWidgets\Runtime\material\button.cs:148
at Unity.UIWidgets.material._InkResponseState`1[T]._handleTap (Unity.UIWidgets.widgets.BuildContext context) [0x0003a] in D:\study\App_Practice\Assets\UIWidgets\Runtime\material\ink_well.cs:282
at Unity.UIWidgets.material._InkResponseState`1+<>c__DisplayClass14_0[T].<build>b__0 () [0x00000] in D:\study\App_Practice\Assets\UIWidgets\Runtime\material\ink_well.cs:346
at Unity.UIWidgets.gestures.TapGestureRecognizer.<_checkUp>b__14_1 () [0x00001] in D:\study\App_Practice\Assets\UIWidgets\Runtime\gestures\tap.cs:132
at Unity.UIWidgets.gestures.GestureRecognizer.invokeCallback[T] (System.String name, Unity.UIWidgets.gestures.RecognizerCallback`1[T] callback, System.Func`1[TResult] debugReport) [0x0001e] in D:\study\App_Practice\Assets\UIWidgets\Runtime\gestures\recognizer.cs:70
Unity.UIWidgets.widgets.DialogUtils.showGeneralDialog (Unity.UIWidgets.widgets.BuildContext context, Unity.UIWidgets.widgets.RoutePageBuilder pageBuilder, System.Boolean barrierDismissible, Unity.UIWidgets.ui.Color barrierColor, System.Nullable`1[T] transitionDuration, Unity.UIWidgets.widgets.RouteTransitionsBuilder transitionBuilder) (at Assets/UIWidgets/Runtime/widgets/routes.cs:822)
Unity.UIWidgets.material.DialogUtils.showDialog (Unity.UIWidgets.widgets.BuildContext context, System.Boolean barrierDismissible, Unity.UIWidgets.widgets.WidgetBuilder builder) (at Assets/UIWidgets/Runtime/material/dialog.cs:296)
_MyGalleryState+<>c__DisplayClass4_0.<build>b__0 () (at Assets/Script/GalleryEX.cs:114)
Unity.UIWidgets.material._RawMaterialButtonState.<build>b__3_0 () (at Assets/UIWidgets/Runtime/material/button.cs:148)
Unity.UIWidgets.material._InkResponseState`1[T]._handleTap (Unity.UIWidgets.widgets.BuildContext context) (at Assets/UIWidgets/Runtime/material/ink_well.cs:282)
Unity.UIWidgets.material._InkResponseState`1+<>c__DisplayClass14_0[T].<build>b__0 () (at Assets/UIWidgets/Runtime/material/ink_well.cs:346)
Unity.UIWidgets.gestures.TapGestureRecognizer.<_checkUp>b__14_1 () (at Assets/UIWidgets/Runtime/gestures/tap.cs:132)
Unity.UIWidgets.gestures.GestureRecognizer.invokeCallback[T] (System.String name, Unity.UIWidgets.gestures.RecognizerCallback`1[T] callback, System.Func`1[TResult] debugReport) (at Assets/UIWidgets/Runtime/gestures/recognizer.cs:70)
UnityEngine.Debug:LogException(Exception)
Unity.UIWidgets.foundation.D:logError(String, Exception) (at Assets/UIWidgets/Runtime/foundation/debug.cs:15)
Unity.UIWidgets.foundation.UIWidgetsError:dumpErrorToConsole(UIWidgetsErrorDetails, Boolean) (at Assets/UIWidgets/Runtime/foundation/assertions.cs:120)
Unity.UIWidgets.foundation.UIWidgetsError:dumpErrorToConsole(UIWidgetsErrorDetails) (at Assets/UIWidgets/Runtime/foundation/assertions.cs:105)
Unity.UIWidgets.foundation.UIWidgetsError:reportError(UIWidgetsErrorDetails) (at Assets/UIWidgets/Runtime/foundation/assertions.cs:131)
Unity.UIWidgets.gestures.GestureRecognizer:invokeCallback(String, RecognizerCallback`1, Func`1) (at Assets/UIWidgets/Runtime/gestures/recognizer.cs:73)
Unity.UIWidgets.gestures.TapGestureRecognizer:_checkUp() (at Assets/UIWidgets/Runtime/gestures/tap.cs:131)
Unity.UIWidgets.gestures.TapGestureRecognizer:handlePrimaryPointer(PointerEvent) (at Assets/UIWidgets/Runtime/gestures/tap.cs:53)
Unity.UIWidgets.gestures.PrimaryPointerGestureRecognizer:handleEvent(PointerEvent) (at Assets/UIWidgets/Runtime/gestures/recognizer.cs:262)
Unity.UIWidgets.gestures.PointerRouter:_dispatch(PointerEvent, PointerRoute) (at Assets/UIWidgets/Runtime/gestures/pointer_router.cs:47)
Unity.UIWidgets.gestures.PointerRouter:route(PointerEvent) (at Assets/UIWidgets/Runtime/gestures/pointer_router.cs:60)
Unity.UIWidgets.gestures.GestureBinding:handleEvent(PointerEvent, HitTestEntry) (at Assets/UIWidgets/Runtime/gestures/binding.cs:161)
Unity.UIWidgets.gestures.GestureBinding:dispatchEvent(PointerEvent, HitTestResult) (at Assets/UIWidgets/Runtime/gestures/binding.cs:152)
Unity.UIWidgets.gestures.GestureBinding:_handlePointerEvent(PointerEvent) (at Assets/UIWidgets/Runtime/gestures/binding.cs:106)
Unity.UIWidgets.gestures.GestureBinding:_flushPointerEventQueue() (at Assets/UIWidgets/Runtime/gestures/binding.cs:43)
Unity.UIWidgets.gestures.GestureBinding:_handlePointerDataPacket(PointerDataPacket) (at Assets/UIWidgets/Runtime/gestures/binding.cs:29)
Unity.UIWidgets.editor.<>c__DisplayClass32_0:<postPointerEvents>b__0() (at Assets/UIWidgets/Runtime/editor/editor_window.cs:250)
Unity.UIWidgets.editor.WindowAdapter:withBinding(Action) (at Assets/UIWidgets/Runtime/editor/editor_window.cs:259)
Unity.UIWidgets.editor.WindowAdapter:postPointerEvents(List`1) (at Assets/UIWidgets/Runtime/editor/editor_window.cs:250)
Unity.UIWidgets.editor.WindowAdapter:postPointerEvent(PointerData) (at Assets/UIWidgets/Runtime/editor/editor_window.cs:254)
Unity.UIWidgets.engine.UIWidgetsPanel:OnPointerUp(PointerEventData) (at Assets/UIWidgets/Runtime/engine/UIWidgetsPanel.cs:293)
UnityEngine.EventSystems.EventSystem:Update() (at C:/Program Files/Unity/Hub/Editor/2019.2.18f1/Editor/Data/Resources/PackageManager/BuiltInPackages/com.unity.ugui/Runtime/EventSystem/EventSystem.cs:377)
I think it's because you have used material widgets in your code, so you need to wrap your app in a material app.This solution also applies to flutter. I removed your font resources loading and changed your source code to this
source code
using Unity.UIWidgets.engine;
using Unity.UIWidgets.material;
using Unity.UIWidgets.painting;
using Unity.UIWidgets.ui;
using Unity.UIWidgets.widgets;
using UnityEngine;
using System;
using System.Collections.Generic;
using DialogUtils = Unity.UIWidgets.material.DialogUtils;
public class GalleryEX : UIWidgetsPanel
{
protected override Widget createWidget()
{
return new
MaterialApp(home: new MyGallery(
));
}
}
class MyGallery : StatefulWidget
{
public override State createState()
{
return new _MyGalleryState();
}
}
class _MyGalleryState : State<MyGallery>
{
Unity.UIWidgets.ui.Color pColor = Colors.blueAccent;
int _idx = 0;
List<string> menuList = new List<string> {"메인", "측정일지", "메뉴", "커뮤니티", "프리미엄"};
List<Widget> pageList = new List<Widget>
{
new ListView(
padding: EdgeInsets.all(20)
),
};
public override Widget build(BuildContext context)
{
TextStyle _normalSt = new TextStyle(color: Colors.grey);
Widget home = new Scaffold(
appBar: new AppBar(
backgroundColor: pColor
, title: new Text(menuList[_idx]
, style: new TextStyle(color: Colors.white)
)
, centerTitle: true
, leading: new BackButton(color: Colors.white)
, actions: new List<Widget>
{
new IconButton(icon: new Icon(icon: Icons.menu, color: Colors.white))
}
)
, body: new Column(
children: new List<Widget>
{
new RaisedButton(
child: new Text("Select Date"),
onPressed: () =>
{
Debug.Log("aaa");
/*Unity.UIWidgets.material.DialogUtils.showDialog(context:context , builder: (_context)=>
{
return new AlertDialog(
actions: new List<Widget>
{
new FlatButton(child: new Text("Close"),
onPressed: ()=>{
Navigator.pop(_context);
}
)
}
);
}
);*/
/*DatePickerUtils.showDatePicker(
context:context,
initialDate:DateTime.Now,
firstDate:new DateTime(2020),
lastDate:new DateTime(2030),
selectableDayPredicate: _decideWhichDayToEnable
)*/
;
Navigator.of(context);
DialogUtils.showDialog(context:
context,
builder: (
_context) =>
{
return new Scaffold(backgroundColor: Colors.transparent,
body: new Text("hello world"));
;
}
).Then((p) => { Debug.Log("das"); });
}
)
}
)
, bottomNavigationBar: new BottomNavigationBar(
selectedItemColor: pColor,
onTap: (index) =>
{
setState(() =>
{
_idx = index;
Debug.Log(_idx);
});
}
, currentIndex: _idx
,
items:
new List<BottomNavigationBarItem>()
{
new BottomNavigationBarItem(icon: new Icon(icon: Icons.home, color: Colors.grey),
title: new Text("Home", style: _normalSt),
activeIcon: new Icon(icon: Icons.home, color: pColor)),
new BottomNavigationBarItem(icon: new Icon(icon: Icons.book, color: Colors.grey),
title: new Text("Diary", style: _normalSt),
activeIcon: new Icon(icon: Icons.book, color: pColor)),
new BottomNavigationBarItem(icon: new Icon(icon: Icons.check, color: Colors.grey),
title: new Text("Menu", style: _normalSt),
activeIcon: new Icon(icon: Icons.check, color: pColor)),
new BottomNavigationBarItem(icon: new Icon(icon: Icons.sms, color: Colors.grey),
title: new Text("SNS", style: _normalSt), activeIcon: new Icon(icon: Icons.sms, color: pColor)),
new BottomNavigationBarItem(icon: new Icon(icon: Icons.chat, color: Colors.grey),
title: new Text("Premium", style: _normalSt),
activeIcon: new Icon(icon: Icons.chat, color: pColor)),
}
)
);
return home;
}
bool _decideWhichDayToEnable(DateTime day)
{
if ((day - DateTime.Now).TotalDays > 0 &&
(DateTime.Now - day).TotalDays > 10)
{
return true;
}
return false;
}
public override void initState()
{
base.initState();
}
public override void dispose()
{
base.dispose();
}
}
Now it works. Thank you very much for your kind reply.