10.31 NOIP simulation race (Morning)

2023-03-02  

CC 4.0 BY-SA Copyright agreement, please attach the original source link and this statement.

This article link:https://blog.csdn.net/qq_36848370/article/details/90267207

I follow the big sandals tutorial to learn the advantages of Widgets update slow, but there are many knowledge points,

This is a preliminary tutorial to make a input box storage label and delete label

This example, they have the official, and then knocked down with Liang Da to deepen my understanding

In this small class, there is a very serious bug

The screen resolution is not reached. Set the width of the container. If it is done with his Margin value at the same time, the length of the two of them will be added to the current screen. This error will overflow.

This error is a bit difficult to solve. This bug pit has been pitted for more than an hour. One of the reasons is poor English and did not read the error information

Each time you open it, it has a record function, and it is stored and read by the PlayerPrefs class that comes with the unity.

I record a gif first

Next I will paste the code

This class is some expansion of commonly used categories of UIWidgets


 
  
  1. using System;
  2. using System.Globalization;
  3. using System.Collections;
  4. using System.Collections.Generic;
  5. using Unity.UIWidgets.gestures;
  6. using Unity.UIWidgets.painting;
  7. using Unity.UIWidgets.widgets;
  8. using UnityEngine;
  9. using Color = Unity.UIWidgets.ui.Color;
  10. using Unity.UIWidgets.foundation;
  11. namespace MyTestUIWidgets.UIWidgets
  12. {
  13. public class FQ
  14. {
  15. public static ContainerBuild Container => new ContainerBuild();
  16. public static TextBuilder Text => new TextBuilder();
  17. public static ListViewBuilder ListView => new ListViewBuilder();
  18. public static EditableTextBuilder EditableText => new EditableTextBuilder();
  19. }
  20. public class ContainerBuild
  21. {
  22. private Widget mChild { get; set; }
  23. private Alignment mAlignment { get; set; }
  24. private Color mColor { get; set; }
  25. private EdgeInsets mMargin = EdgeInsets.zero;
  26. // Control parameters
  27. private float? mWidth = null;
  28. public static ContainerBuild GetBuilder()
  29. {
  30. return new ContainerBuild();
  31. }
  32. public ContainerBuild Child(Widget _child)
  33. {
  34. mChild = _child;
  35. return this;
  36. }
  37. public ContainerBuild Color(Color _color)
  38. {
  39. mColor = _color;
  40. return this;
  41. }
  42. public ContainerBuild Margin(EdgeInsets _edgInsets)
  43. {
  44. mMargin = _edgInsets;
  45. return this;
  46. }
  47. public ContainerBuild Width(float _width)
  48. {
  49. mWidth = _width;
  50. return this;
  51. }
  52. public ContainerBuild Alignment(Alignment _alignment)
  53. {
  54. mAlignment = _alignment;
  55. return this;
  56. }
  57. public Container EndContainer()
  58. {
  59. return new Container(child: mChild, alignment: mAlignment, color: mColor, width: mWidth, margin: mMargin);
  60. }
  61. }
  62. public class TextBuilder
  63. {
  64. private string mData { get; set; }
  65. private TextStyle mStyle { get; set; } = new TextStyle();
  66. private int mFontSize { get; set; }
  67. public static TextBuilder GetBuilder()
  68. {
  69. return new TextBuilder();
  70. }
  71. public TextBuilder Data(string _data)
  72. {
  73. mData = _data;
  74. return this;
  75. }
  76. public TextBuilder SetTextStyle(TextStyle _style)
  77. {
  78. mStyle = _style;
  79. return this;
  80. }
  81. public TextBuilder SetSize(int _fountSize)
  82. {
  83. mFontSize = _fountSize;
  84. return this;
  85. }
  86. public Text EndText()
  87. {
  88. if (mFontSize == 0)
  89. {
  90. return new Text(data: mData);
  91. }
  92. else
  93. {
  94. return new Text(data: mData, style: new TextStyle(fontSize: mFontSize));
  95. }
  96. }
  97. }
  98. public class ListViewBuilder
  99. {
  100. List<Widget> mChildren = new List<Widget>();
  101. EdgeInsets mPadding = null;
  102. public static ListViewBuilder GetBuilder()
  103. {
  104. return new ListViewBuilder();
  105. }
  106. public ListViewBuilder Padding(EdgeInsets _madding)
  107. {
  108. mPadding = _madding;
  109. return this;
  110. }
  111. public ListViewBuilder Child(List<Widget> _children)
  112. {
  113. mChildren = _children;
  114. return this;
  115. }
  116. public ListViewBuilder Child(Widget _child)
  117. {
  118. mChildren.Add(_child);
  119. return this;
  120. }
  121. public ListViewBuilder Child(params Widget[] _childeen)
  122. {
  123. mChildren.AddRange(_childeen);
  124. return this;
  125. }
  126. public ListView EndListView()
  127. {
  128. return new ListView(children: mChildren, padding: mPadding);
  129. }
  130. }
  131. public static class GestureDetectorExtension
  132. {
  133. public static GestureDetector OnTap(this Widget _widget, GestureTapCallback onTap)
  134. {
  135. return new GestureDetector(child: _widget, onTap: onTap);
  136. }
  137. }
  138. public class EditableTextBuilder
  139. {
  140. private TextEditingController mInputController = new TextEditingController(text: "");
  141. private FocusNode mFocusNode = new FocusNode();
  142. public TextStyle mStyle = new TextStyle();
  143. public Color mCursorColor = Color.black;
  144. public float mFontSize;
  145. ValueChanged< string> mOnValueChanged = null;
  146. ValueChanged< string> mOnSubmit = null;
  147. public EditableTextBuilder OnValueChanged(ValueChanged<string> _onValueChanged)
  148. {
  149. mOnValueChanged = _onValueChanged;
  150. return this;
  151. }
  152. public EditableTextBuilder OnSubmit(ValueChanged<string> _onSubmit)
  153. {
  154. mOnSubmit = _onSubmit;
  155. return this;
  156. }
  157. public EditableTextBuilder SetInputController(TextEditingController _inputController, FocusNode _focusNode, TextStyle _style, Color _cursorColor)
  158. {
  159. mInputController = _inputController;
  160. mFocusNode = _focusNode;
  161. mStyle = _style;
  162. mCursorColor = _cursorColor;
  163. return this;
  164. }
  165. public EditableTextBuilder FontSize(float size)
  166. {
  167. mFontSize = size;
  168. return this;
  169. }
  170. public EditableTextBuilder GetBuilder()
  171. {
  172. return new EditableTextBuilder();
  173. }
  174. public EditableText EndEditableTextBuilder()
  175. {
  176. return new EditableText(
  177. controller: mInputController,
  178. focusNode: mFocusNode,
  179. style: mFontSize == 0 ? mStyle : new TextStyle(fontSize: mFontSize),
  180. cursorColor: mCursorColor,
  181. onChanged: mOnValueChanged,
  182. onSubmitted: mOnSubmit);
  183. }
  184. }
  185. }

This class is used to help the TodolistApp class build


 
  
  1. using Color = Unity.UIWidgets.ui.Color;
  2. using Unity.UIWidgets.foundation;
  3. using System;
  4. using System.Collections.Generic;
  5. using MyTestUIWidgets.UIWidgets;
  6. using Unity.UIWidgets.painting;
  7. using Unity.UIWidgets.widgets;
  8. using UnityEngine;
  9. namespace MyTestUIWidgets.UIWidgets
  10. {
  11. public class TodoView : StatelessWidget
  12. {
  13. private readonly string mData;
  14. private readonly Action mOnFinish;
  15. public TodoView(string data, Action onFinish)
  16. {
  17. mData = data;
  18. mOnFinish = onFinish;
  19. }
  20. public override Widget build(BuildContext context)
  21. {
  22. return FQ.Container
  23. .Alignment(Alignment.center)
  24. .Child(
  25. FQ.Text
  26. .Data(mData)
  27. .SetSize( 20).EndText()
  28. )
  29. .EndContainer().OnTap(() =>
  30. {
  31. mOnFinish();
  32. });
  33. }
  34. }
  35. public class TodoInputView : StatelessWidget
  36. {
  37. private string mInputContent = string.Empty;
  38. private Action< string> mOnAdd;
  39. public TodoInputView(Action<string> onAdd)
  40. {
  41. mOnAdd = onAdd;
  42. }
  43. public void AddTodo()
  44. {
  45. if (! string.IsNullOrWhiteSpace(mInputContent))
  46. {
  47. mOnAdd(mInputContent);
  48. }
  49. }
  50. public override Widget build(BuildContext context)
  51. {
  52. return
  53. new Container(child:
  54. new Row(children: new List<Widget>(){
  55. FQ.Container.Width( 190).Color(Color.white).Margin(EdgeInsets.only(left : 15))
  56. .Child(FQ.EditableText.FontSize( 30)
  57. .OnValueChanged(mInputContent => { this.mInputContent = mInputContent; } )
  58. .OnSubmit(inputvalue => AddTodo())
  59. .EndEditableTextBuilder() )
  60. .EndContainer(),
  61. FQ.Container.Child(
  62. FQ.Text.Data( "+")
  63. .SetSize( 30)
  64. .EndText()
  65. .OnTap(() => {
  66. AddTodo();
  67. Debug.Log( "On Tap");})
  68. ).Margin(EdgeInsets.only(left: 12)).EndContainer()
  69. } //, mainAxisAlignment: Unity.UIWidgets.rendering.MainAxisAlignment.spaceBetween
  70. ));
  71. }
  72. }
  73. }

This TodolistApp class is used to build the APP interface


 
  
  1. using System.Xml.Linq;
  2. using System;
  3. using System.Text;
  4. using System.Linq;
  5. using System.Collections;
  6. using System.Collections.Generic;
  7. using Unity.UIWidgets.engine;
  8. using Unity.UIWidgets.painting;
  9. using Unity.UIWidgets.widgets;
  10. using UnityEngine;
  11. using Color = Unity.UIWidgets.ui.Color;
  12. using MyTestUIWidgets.UIWidgets;
  13. using Unity.UIWidgets.foundation;
  14. namespace MyTestUIWidgets
  15. {
  16. public class TodoListApp : UIWidgetsPanel
  17. {
  18. protected override Widget createWidget()
  19. {
  20. return new TodoListPage();
  21. }
  22. }
  23. class TodoListPage : StatefulWidget
  24. {
  25. public override State createState()
  26. {
  27. return new TodoListState();
  28. }
  29. }
  30. class TodoListState : State< TodoListPage>
  31. {
  32. public override void initState()
  33. {
  34. //PlayerPrefs.DeleteAll();
  35. var toDoListContent = PlayerPrefs.GetString( "TODO_LIST_KEY", string.Empty);
  36. var splitDatas = toDoListContent.Split( new[] { "@@@@" }, StringSplitOptions.None);
  37. mTodoDatas = splitDatas.Where(data => ! string.IsNullOrEmpty(data)).ToList();
  38. }
  39. private List< string> mTodoDatas = null;
  40. public override Widget build(BuildContext context)
  41. {
  42. return FQ.ListView
  43. .Child( new TodoInputView( data => { AddState(data); }))
  44. .Child(TodoViews)
  45. .Padding(EdgeInsets.only( 0, 50))
  46. .EndListView();
  47. }
  48. private void AddState( string data)
  49. {
  50. this.setState(() =>
  51. {
  52. mTodoDatas.Add(data);
  53. Save();
  54. });
  55. }
  56. void Save()
  57. {
  58. StringBuilder stringBuilder = new StringBuilder();
  59. mTodoDatas.ForEach(
  60. data =>
  61. {
  62. stringBuilder.Append(data);
  63. stringBuilder.Append( "@@@@");
  64. }
  65. );
  66. PlayerPrefs.SetString( "TODO_LIST_KEY", stringBuilder.ToString());
  67. }
  68. Widget[] TodoViews
  69. {
  70. get
  71. {
  72. return mTodoDatas.Select(data => new TodoView(data, () =>
  73. {
  74. this.setState(() =>
  75. {
  76. mTodoDatas.Remove(data);
  77. Save();
  78. });
  79. })).ToArray();
  80. }
  81. }
  82. }
  83. }

Now this code can make the effect just now, I will continue to update

source

Related Posts

html -mobile terminal

Connect the database with ThinkPHP and test whether the connection is successful

Seeking the shortest path of the picture 2 Detailed explanation of the Dijkstra algorithm Eric

PRETRANSLATEMESSAGE and TranslateMessage

10.31 NOIP simulation race (Morning)

Random Posts

docker set up registry (built with the new version of Docker-CE)

HDU5536 Chip Factory 【01 dictionary tree】

[Linux Advanced] LSTAT of the system call -Get the file attribute

neural network and deep learning notes (3) The activation function and parameter initialization

Sorting method (C ++)