flutter-flexer / study_log

0 stars 0 forks source link

Week 3] User interface #6

Open 1more opened 5 years ago

1more commented 5 years ago

TODO

1more commented 5 years ago

State

Layout

Box constraints

Adding interactivity

serin9 commented 5 years ago

오 현욱이 벌써 했구먼 👍 나도 flutter.dev 의 user interface 문서 공부한거 여기에 같이 올린당 ㅎㅎ

flutter.dev 의 User Interface

Introduction to widgets

void main() { runApp( Center( child: Text( 'Hello, world!', textDirection: TextDirection.ltr, ), ), ); }

  - 미니멀한 플러터 앱은 위젯과 함께 `runApp()` 함수를 호출한다.
  - 그러면 `runApp()` 이 위젯트리의 루트가 된다.
  - 위젯이 상태를 관리하는지의 여부에 따라 `StatelessWidget` 과 `StatefulWidget` 이 있다.
  - 위젯의 주된 일은 빌드 함수를 구현하는 것
- Basic widgets
  - `Text`: style 지정이 가능하다
  - `Row`, `column`: horizontal (row), vertical (column) 으로 좀 헷갈린다. 옆으로 추가해서 하나의 row 가 되면 row 고, 위아래로 추가해서 하나의 column 이 되면 column 인 것으로 이해하면 좋다.
  - `Stack`: 가로나 세로로 쌓이는 것이 아니라 앞뒤로, background 에서 부터 foreground 로 쌓이는 것을 말한다. 이걸 이용해서 각 위젯의 포지션을 상대적으로 결정할 수 있다.
  - `Container`: 네모난 모양의 요소를 만들 때 사용한다. BoxDecoration 및 3D 트랜스포메이션이 가능하다.
  - 예제 코드로 부터 배운 것:
    - flutter 에서 height 등 단위가 없는 수치들은 logical pixel 이라고 함. (= device-independent pixel)
    - Material 은 UI 를 나타내는 개념적인 도화지 정도로 이해할 수 있다. 여기에 이것저것 붙이면 그게 한 화면이 되는 것이다.
    - Colors.blue[500]: 뒤에 붙은 숫자는 색의 강도? 정도로 이해할 수 있다. 100 ~ 900 (pale to darker) 까지의 수로 이루어져있다. 참고로 accect 는 {100, 200, 400, 700} 만 있다고 한다. 
      - 참고: https://api.flutter.dev/flutter/material/Colors-class.html
  - 참고: pubspec.yaml 에 `users-material-design: true` 로 해두면 플러터의 material icon 을 사용할 수 있다. 그리고 이들은 MaterialApp 안에 있어야 하므로 아래 처럼 작성한다.
  ```dart
  void main() {
    runApp(MaterialApp(
      title: 'My app', // used by the OS task switcher
      home: MyScaffold(),
    ));
  }

정리는 여기까지 ㅠ ㅋㅋㅋ

Building layouts

Layouts in flutter

Adding Interactivity

1more commented 5 years ago

화면에 ListView만 추가하면 아래 오류가....

났었는데, ListView에 아래 두 옵션 추가해서 해결함.

      scrollDirection: Axis.vertical,
      shrinkWrap: true,

flutter: ══╡ EXCEPTION CAUGHT BY RENDERING LIBRARY ╞═════════════════════════════════════════════════════════
flutter: The following assertion was thrown during performResize():
flutter: Vertical viewport was given unbounded height.
flutter: Viewports expand in the scrolling direction to fill their container.In this case, a vertical
flutter: viewport was given an unlimited amount of vertical space in which to expand. This situation
flutter: typically happens when a scrollable widget is nested inside another scrollable widget.
flutter: If this widget is always nested in a scrollable widget there is no need to use a viewport because
flutter: there will always be enough vertical space for the children. In this case, consider using a Column
flutter: instead. Otherwise, consider using the "shrinkWrap" property (or a ShrinkWrappingViewport) to size
flutter: the height of the viewport to the sum of the heights of its children.
flutter:
flutter: User-created ancestor of the error-causing widget was:
flutter:   ListView file:///Users/hyeonwook/workspace/flutter_app_sample/lib/main.dart:198:23
flutter:
flutter: When the exception was thrown, this was the stack:
flutter: #0      RenderViewport.performResize.<anonymous closure> (package:flutter/src/rendering/viewport.dart:1147:15)
flutter: #1      RenderViewport.performResize (package:flutter/src/rendering/viewport.dart:1200:6)
flutter: #2      RenderObject.layout (package:flutter/src/rendering/object.dart:1624:9)
flutter: #3      _RenderProxyBox&RenderBox&RenderObjectWithChildMixin&RenderProxyBoxMixin.performLayout (package:flutter/src/rendering/proxy_box.dart:105:13)
flutter: #4      RenderObject.layout (package:flutter/src/rendering/object.dart:1639:7)
flutter: #5      _RenderProxyBox&RenderBox&RenderObjectWithChildMixin&RenderProxyBoxMixin.performLayout (package:flutter/src/rendering/proxy_box.dart:105:13)
flutter: #6      RenderObject.layout (package:flutter/src/rendering/object.dart:1639:7)
flutter: #7      _RenderProxyBox&RenderBox&RenderObjectWithChildMixin&RenderProxyBoxMixin.performLayout (package:flutter/src/rendering/proxy_box.dart:105:13)
flutter: #8      RenderObject.layout (package:flutter/src/rendering/object.dart:1639:7)
flutter: #9      _RenderProxyBox&RenderBox&RenderObjectWithChildMixin&RenderProxyBoxMixin.performLayout (package:flutter/src/rendering/proxy_box.dart:105:13)
flutter: #10     RenderObject.layout (package:flutter/src/rendering/object.dart:1639:7)
flutter: #11     _RenderProxyBox&RenderBox&RenderObjectWithChildMixin&RenderProxyBoxMixin.performLayout (package:flutter/src/rendering/proxy_box.dart:105:13)
flutter: #12     RenderObject.layout (package:flutter/src/rendering/object.dart:1639:7)
flutter: #13     _RenderProxyBox&RenderBox&RenderObjectWithChildMixin&RenderProxyBoxMixin.performLayout (package:flutter/src/rendering/proxy_box.dart:105:13)
flutter: #14     RenderObject.layout (package:flutter/src/rendering/object.dart:1639:7)
flutter: #15     RenderFlex.performLayout (package:flutter/src/rendering/flex.dart:744:15)
flutter: #16     RenderObject.layout (package:flutter/src/rendering/object.dart:1639:7)
flutter: #17     _RenderProxyBox&RenderBox&RenderObjectWithChildMixin&RenderProxyBoxMixin.performLayout (package:flutter/src/rendering/proxy_box.dart:105:13)
flutter: #18     RenderObject.layout (package:flutter/src/rendering/object.dart:1639:7)
flutter: #19     RenderFlex.performLayout (package:flutter/src/rendering/flex.dart:806:17)
flutter: #20     RenderObject.layout (package:flutter/src/rendering/object.dart:1639:7)
flutter: #21     _RenderProxyBox&RenderBox&RenderObjectWithChildMixin&RenderProxyBoxMixin.performLayout (package:flutter/src/rendering/proxy_box.dart:105:13)
flutter: #22     RenderObject.layout (package:flutter/src/rendering/object.dart:1639:7)
flutter: #23     MultiChildLayoutDelegate.layoutChild (package:flutter/src/rendering/custom_layout.dart:142:11)
flutter: #24     _ScaffoldLayout.performLayout (package:flutter/src/material/scaffold.dart:443:7)
flutter: #25     MultiChildLayoutDelegate._callPerformLayout (package:flutter/src/rendering/custom_layout.dart:212:7)
flutter: #26     RenderCustomMultiChildLayoutBox.performLayout (package:flutter/src/rendering/custom_layout.dart:356:14)
flutter: #27     RenderObject.layout (package:flutter/src/rendering/object.dart:1639:7)
flutter: #28     _RenderProxyBox&RenderBox&RenderObjectWithChildMixin&RenderProxyBoxMixin.performLayout (package:flutter/src/rendering/proxy_box.dart:105:13)
flutter: #29     RenderObject.layout (package:flutter/src/rendering/object.dart:1639:7)
flutter: #30     _RenderProxyBox&RenderBox&RenderObjectWithChildMixin&RenderProxyBoxMixin.performLayout (package:flutter/src/rendering/proxy_box.dart:105:13)
flutter: #31     _RenderCustomClip.performLayout (package:flutter/src/rendering/proxy_box.dart:1214:11)
flutter: #32     RenderObject.layout (package:flutter/src/rendering/object.dart:1639:7)
flutter: #33     _RenderProxyBox&RenderBox&RenderObjectWithChildMixin&RenderProxyBoxMixin.performLayout (package:flutter/src/rendering/proxy_box.dart:105:13)
flutter: #34     RenderObject.layout (package:flutter/src/rendering/object.dart:1639:7)
flutter: #35     _RenderProxyBox&RenderBox&RenderObjectWithChildMixin&RenderProxyBoxMixin.performLayout (package:flutter/src/rendering/proxy_box.dart:105:13)
flutter: #36     RenderObject.layout (package:flutter/src/rendering/object.dart:1639:7)
flutter: #37     _RenderProxyBox&RenderBox&RenderObjectWithChildMixin&RenderProxyBoxMixin.performLayout (package:flutter/src/rendering/proxy_box.dart:105:13)
flutter: #38     RenderObject.layout (package:flutter/src/rendering/object.dart:1639:7)
flutter: #39     RenderStack.performLayout (package:flutter/src/rendering/stack.dart:510:15)
flutter: #40     RenderObject.layout (package:flutter/src/rendering/object.dart:1639:7)
flutter: #41     _RenderProxyBox&RenderBox&RenderObjectWithChildMixin&RenderProxyBoxMixin.performLayout (package:flutter/src/rendering/proxy_box.dart:105:13)
flutter: #42     RenderObject.layout (package:flutter/src/rendering/object.dart:1639:7)
flutter: #43     _RenderProxyBox&RenderBox&RenderObjectWithChildMixin&RenderProxyBoxMixin.performLayout (package:flutter/src/rendering/proxy_box.dart:105:13)
flutter: #44     RenderObject.layout (package:flutter/src/rendering/object.dart:1639:7)
flutter: #45     _RenderProxyBox&RenderBox&RenderObjectWithChildMixin&RenderProxyBoxMixin.performLayout (package:flutter/src/rendering/proxy_box.dart:105:13)
flutter: #46     RenderObject.layout (package:flutter/src/rendering/object.dart:1639:7)
flutter: #47     _RenderProxyBox&RenderBox&RenderObjectWithChildMixin&RenderProxyBoxMixin.performLayout (package:flutter/src/rendering/proxy_box.dart:105:13)
flutter: #48     RenderObject.layout (package:flutter/src/rendering/object.dart:1639:7)
flutter: #49     _RenderProxyBox&RenderBox&RenderObjectWithChildMixin&RenderProxyBoxMixin.performLayout (package:flutter/src/rendering/proxy_box.dart:105:13)
flutter: #50     RenderObject.layout (package:flutter/src/rendering/object.dart:1639:7)
flutter: #51     _RenderProxyBox&RenderBox&RenderObjectWithChildMixin&RenderProxyBoxMixin.performLayout (package:flutter/src/rendering/proxy_box.dart:105:13)
flutter: #52     RenderOffstage.performLayout (package:flutter/src/rendering/proxy_box.dart:3076:13)
flutter: #53     RenderObject.layout (package:flutter/src/rendering/object.dart:1639:7)
flutter: #54     RenderStack.performLayout (package:flutter/src/rendering/stack.dart:510:15)
flutter: #55     RenderObject.layout (package:flutter/src/rendering/object.dart:1639:7)
flutter: #56     __RenderTheatre&RenderBox&RenderObjectWithChildMixin&RenderProxyBoxMixin.performLayout (package:flutter/src/rendering/proxy_box.dart:105:13)
flutter: #57     RenderObject.layout (package:flutter/src/rendering/object.dart:1639:7)
flutter: #58     _RenderProxyBox&RenderBox&RenderObjectWithChildMixin&RenderProxyBoxMixin.performLayout (package:flutter/src/rendering/proxy_box.dart:105:13)
flutter: #59     RenderObject.layout (package:flutter/src/rendering/object.dart:1639:7)
flutter: #60     _RenderProxyBox&RenderBox&RenderObjectWithChildMixin&RenderProxyBoxMixin.performLayout (package:flutter/src/rendering/proxy_box.dart:105:13)
flutter: #61     RenderObject.layout (package:flutter/src/rendering/object.dart:1639:7)
flutter: #62     _RenderProxyBox&RenderBox&RenderObjectWithChildMixin&RenderProxyBoxMixin.performLayout (package:flutter/src/rendering/proxy_box.dart:105:13)
flutter: #63     RenderObject.layout (package:flutter/src/rendering/object.dart:1639:7)
flutter: #64     _RenderProxyBox&RenderBox&RenderObjectWithChildMixin&RenderProxyBoxMixin.performLayout (package:flutter/src/rendering/proxy_box.dart:105:13)
flutter: #65     RenderObject.layout (package:flutter/src/rendering/object.dart:1639:7)
flutter: #66     RenderView.performLayout (package:flutter/src/rendering/view.dart:151:13)
flutter: #67     RenderObject._layoutWithoutResize (package:flutter/src/rendering/object.dart:1516:7)
flutter: #68     PipelineOwner.flushLayout (package:flutter/src/rendering/object.dart:783:18)
flutter: #69     _WidgetsFlutterBinding&BindingBase&GestureBinding&ServicesBinding&SchedulerBinding&PaintingBinding&SemanticsBinding&RendererBinding.drawFrame (package:flutter/src/rendering/binding.dart:346:19)
flutter: #70     _WidgetsFlutterBinding&BindingBase&GestureBinding&ServicesBinding&SchedulerBinding&PaintingBinding&SemanticsBinding&RendererBinding&WidgetsBinding.drawFrame (package:flutter/src/widgets/binding.dart:702:13)
flutter: #71     _WidgetsFlutterBinding&BindingBase&GestureBinding&ServicesBinding&SchedulerBinding&PaintingBinding&SemanticsBinding&RendererBinding._handlePersistentFrameCallback (package:flutter/src/rendering/binding.dart:285:5)
flutter: #72     _WidgetsFlutterBinding&BindingBase&GestureBinding&ServicesBinding&SchedulerBinding._invokeFrameCallback (package:flutter/src/scheduler/binding.dart:1033:15)
flutter: #73     _WidgetsFlutterBinding&BindingBase&GestureBinding&ServicesBinding&SchedulerBinding.handleDrawFrame (package:flutter/src/scheduler/binding.dart:975:9)
flutter: #74     _WidgetsFlutterBinding&BindingBase&GestureBinding&ServicesBinding&SchedulerBinding.scheduleWarmUpFrame.<anonymous closure> (package:flutter/src/scheduler/binding.dart:784:7)
flutter: #83     _Timer._runTimers (dart:isolate-patch/timer_impl.dart:382:19)
flutter: #84     _Timer._handleMessage (dart:isolate-patch/timer_impl.dart:416:5)
flutter: #85     _RawReceivePortImpl._handleMessage (dart:isolate-patch/isolate_patch.dart:172:12)
flutter: (elided 8 frames from package dart:async and package dart:async-patch)
flutter:
flutter: The following RenderObject was being processed when the exception was fired: RenderViewport#56e3f NEEDS-LAYOUT NEEDS-PAINT NEEDS-COMPOSITING-BITS-UPDATE:
flutter:   needs compositing
flutter:   creator: Viewport ← IgnorePointer-[GlobalKey#a00dd] ← Semantics ← Listener ← _GestureSemantics ←
flutter:     RawGestureDetector-[LabeledGlobalKey<RawGestureDetectorState>#88c9c] ← Listener ← _ScrollableScope
flutter:     ← _ScrollSemantics-[GlobalKey#a4548] ← Scrollable ← PrimaryScrollController ← ListView ← ⋯
flutter:   parentData: <none> (can use size)
flutter:   constraints: BoxConstraints(0.0<=w<=414.0, 0.0<=h<=Infinity)
flutter:   size: MISSING
flutter:   axisDirection: down
flutter:   crossAxisDirection: right
flutter:   offset: ScrollPositionWithSingleContext#71af3(offset: 0.0, range: null..null, viewport: null,
flutter:     ScrollableState, AlwaysScrollableScrollPhysics -> BouncingScrollPhysics, IdleScrollActivity#aa512,
flutter:     ScrollDirection.idle)
flutter:   anchor: 0.0
flutter: This RenderObject had the following descendants (showing up to depth 5):
flutter:     center child: RenderSliverPadding#cf111 NEEDS-LAYOUT NEEDS-PAINT NEEDS-COMPOSITING-BITS-UPDATE
flutter:       child: RenderSliverList#fac8e NEEDS-LAYOUT NEEDS-PAINT