31
17

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

More than 5 years have passed since last update.

Flutter 入門でつまづいたところまとめ

Posted at

はじめに

書籍 Android/iOSクロス開発 フレームワークFlutter入門 を読んでいて、つまづいたところをまとめます。

Flutter Studio の UI が違う?

自分のGoogle検索では「flutter studio」で検索すると、上位に古いバージョンが表示されます。

旧: http://mutisya.com/
新: https://flutterstudio.app/

書籍にはちゃんと新しい方のURLが書かれているので「UIが違う」というのは勘違いでした。

initStateが呼ばれない

ビルドし直すとinitStateが呼ばれるようになりました。

6-1グラフィック描画の基本

リスト6-1を実行すると、下の例外が投げられる。

Performing hot reload...
Syncing files to device iPhone XS...
flutter: [Container(bg: BoxDecoration(color: Color(0xffffffff)), constraints: BoxConstraints(0.0<=w<=Infinity, h=100.0)), Container(bg: BoxDecoration(color: MaterialColor(primary value: Color(0xff2196f3))), constraints: BoxConstraints(0.0<=w<=Infinity, h=100.0)), Container(bg: BoxDecoration(color: Color(0xffffffff)), constraints: BoxConstraints(0.0<=w<=Infinity, h=100.0)), Container(bg: BoxDecoration(color: MaterialColor(primary value: Color(0xff2196f3))), constraints: BoxConstraints(0.0<=w<=Infinity, h=100.0)), Container(bg: BoxDecoration(color: Color(0xffffffff)), constraints: BoxConstraints(0.0<=w<=Infinity, h=100.0)), Container(bg: BoxDecoration(color: MaterialColor(primary value: Color(0xff2196f3))), constraints: BoxConstraints(0.0<=w<=Infinity, h=100.0)), Container(bg: BoxDecoration(color: Color(0xffffffff)), constraints: BoxConstraints(0.0<=w<=Infinity, h=100.0)), Container(bg: BoxDecoration(color: MaterialColor(primary value: Color(0xff2196f3))), constraints: BoxConstraints(0.0<=w<=Infi<…>
flutter: ══╡ EXCEPTION CAUGHT BY RENDERING LIBRARY ╞═════════════════════════════════════════════════════════
flutter: The following assertion was thrown during performLayout():
flutter: _MyRenderBox did not implement performLayout().
flutter: RenderBox subclasses need to either override performLayout() to set a size and lay out any children,
flutter: or, set sizedByParent to true so that performResize() sizes the render object.
flutter:
flutter: When the exception was thrown, this was the stack:
...略
flutter: This RenderObject has no descendants.
flutter: ════════════════════════════════════════════════════════════════════════════════════════════════════
Reloaded 1 of 406 libraries in 2,204ms.

↓を追記で解決(すみません、ちゃんと理解してないです。)

class _MyRenderBox extends RenderBox {
  // 略; hitText と paint の定義
  
  @override
  bool get sizedByParent => true;

  @override
  void performResize() {
    size = constraints.biggest;
  }
}

8-2 feedparser 0.0.2 が Dart2 に対応していない

pub get すると↓のようなエラーが出ました。

The current Dart SDK version is 2.1.0-dev.1.0.flutter-ccb16f7282.

Because yahoo_rss depends on feedparser >=0.0.2 which requires SDK version >=1.21.0 <2.0.0, version solving failed.
pub get failed (1)
Process finished with exit code 1

すでに Dart 2 に対応するための Pull Request は作られている(#4)ようですが、本記事の執筆時点ではまだマージされていません。

代わりにwebfeed を使うことにしました。

pubspec.yaml
dependencies:
  webfeed: ^0.3.0
Feed feed = parse(res.body);
// ↓
RssFeed feed = RssFeed.parse(res.body);
    for (FeedItem item in feed.items) {
// ↓
    for (RssItem item in feed.items) {
31
17
2

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
31
17

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?