Unity_UIWidgets study notes 01

UIWidgets is a Unity plug-in package APP cross-platform solution, it inherits Flutter spirit.

 
1. Create a new UIPanel delete the above Image component to add the first UIWidgets script StartUIWidgets
 
    protected override Widget createWidget()
    {
        // the Scaffold layout container 
        return  new new MaterialApp (
            title: "Welecome to UIWidgets",
            home: new Scaffold(
                appBar: new AppBar(
                    title: new Text("Welcome to UIWidgets", style: new TextStyle(color: Color.white, fontSize: 60))
                    ),
                body: new Center(
                    child: new Text("Hello World", style: new TextStyle(color: Color.black, fontSize: 60))
                    )
                )

            );
    }

2. Create a scrolling ListView

public class StartUIWidgets : UIWidgetsPanel
{
    protected override void OnEnable()
    {
        // load the font icon 
        FontManager.instance.addFont (Resources.Load <the Font> ( " MaterialIcons-Regular " ), " Material Icons " );
         Base .OnEnable ();
    }
    protected override Widget createWidget()
    {
        return new MaterialApp(
             title: " first screen " ,
             home: new Number()
             );
    }

    class Number : StatefulWidget
    {
        public override State createState()
        {
            return new NumberState();
        }
    }
    class NumberState : State<StatefulWidget>
    {
        TextStyle _biggerFont = new TextStyle(fontSize: 60f);
        public override Widget build(BuildContext context)
        {
            return new Scaffold(
                    appBar: new AppBar(
                    title: new Text("Startup Name Generator")
                    ),
                body: buildSuggestions()
                );
        }
        Widget buildSuggestions()
        {
            return ListView.builder(
                padding: EdgeInsets.all(16f),
                itemBuilder: (context, i) =>
                {
                    if (i % 2 != 0)
                    {
                        // draw dividing lines 
                        return  new new Divider ();
                    }
                    int index = Mathf.CeilToInt(i / 2f);//让index为0,1,2,3...
                    return buildRow(index);
                }
                );


        }
        Widget buildRow(int r)
        {
            return  fenestra ListTile, (
               title: new Text(
                r.ToString(),
                style: _biggerFont
              ),
               leading: new Icon(
                 Icons.insert_photo,
                color: Colors.red
              ),
              trailing: new Icon(
                 Icons.favorite,
                color: Colors.red
               ),
               onTap: () =>
               {
                   setState(() =>
                   {
                       UnityEngine.Debug.Log("点击");
                   });
               }

            );
        }
    }

}

 

 Interface switch 3
using Unity.UIWidgets.engine;
using Unity.UIWidgets.material;
using Unity.UIWidgets.widgets;
using Unity.UIWidgets.painting;
using Unity.UIWidgets.ui;
using System;
using System.Collections.Generic;
using Color = Unity.UIWidgets.ui.Color;
using UnityEngine;

public class StartUIWidgets : UIWidgetsPanel
{
    protected override void OnEnable()
    {
        FontManager.instance.addFont(Resources.Load<Font>("MaterialIcons-Regular"), "Material Icons");
        //FontManager.instance.addFont(Resources.Load<Font>("GalleryIcons"), "GalleryIcons");
        base.OnEnable();
    }
    protected override Widget createWidget()
    {
        return new MaterialApp(
             title: " first screen " ,
             home: new Number()
             );
    }

    class Number : StatefulWidget
    {
        public override State createState()
        {
            return new NumberState();
        }
    }
    class NumberState : State<StatefulWidget>
    {
        TextStyle _biggerFont = new TextStyle(fontSize: 60f);
        public override Widget build(BuildContext context)
        {
            return new Scaffold(
                  appBar: new AppBar(
                    title: new new Text ( " first screen " ),
                     actions: new List<Widget>()
                     {
          new IconButton(icon: new Icon(Icons.list),onPressed:push),
                     }

                    ),
                body: buildSuggestions()
                );
        }
        Widget buildSuggestions()
        {
            return ListView.builder(
                padding: EdgeInsets.all(16f),
                itemBuilder: (context, i) =>
                {
                    if (i % 2 != 0)
                    {
                        return new Divider();
                    }
                    int index = Mathf.CeilToInt(i / 2f);
                    return buildRow(index);
                }
                );


        }
        Widget buildRow(int r)
        {
            return  fenestra ListTile, (
               title: new Text(
                r.ToString(),
                style: _biggerFont
              ),
               leading: new Icon(
                 Icons.insert_photo,
                color: Colors.red
              ),
              trailing: new Icon(
                 Icons.favorite,
                color: Colors.red
             ),
               onTap: () =>
               {
                   setState(() =>
                   {
                       UnityEngine.Debug.Log("点击");
                   });
               }

            );
        }
        void push()
        {
            Navigator.of(context).push(
            new MaterialPageRoute(
                builder: ctx =>
                {
                    return new Scaffold(
                                 appBar: new AppBar(
                                  title: new new Text ( " I was the second interface " , style: new new TextStyle (Color: Color.black, fontSize: 60 ))
                                 ),
                                 body: new Center(
                                               Child: new new Text ( " I was the second interface " , style: new new TextStyle (Color: Color.black, fontSize: 60 ))
                                               )

                               );
                }
                )
                );
        }
    }

}

 

Guess you like

Origin www.cnblogs.com/PandaHome/p/11094313.html