1
1

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 3 years have passed since last update.

【Flutter】遭遇したエラー&&解決策まとめ③

Last updated at Posted at 2021-01-02

前回

【Bad state: Stream has already been listened to】

◆ エラー内容

Bad state: Stream has already been listened to.

◆ 解決策

pubspec.yaml
dependencies:
  rxdart: ^0.25.0
main.dart
// StreamController → BehaviorSubject
final _sample = StreamController<String>();  //before
final _sample = BehaviorSubject<String>();  //after

【setState() called after dispose();エラー】

◆ エラー内容

This error happens if you call setState() on a State object for a widget that no longer appears in the widget tree

◆ 解決策

main.dart
int _count = 0;

void _sampleCounter() {
  if(mounted) {  //追加
    setState(() {
      _count++;
  });
}

【cloud_firestore/permission-denied】

◆ エラー内容

cloud_firestore/permission-denied] The caller does not have permission to execute the specified operation.

◆ 解決策

Firebaseコンソール > プロジェクト選択 > Cloud Firestore >  ルール

【Dart条件分岐】

◆ switch文

main.dart
const sample1 = "犬";
const sample2 = "猫";
var pets = "ペット";

switch (pets) {
  case sample1:   
    print('犬好き');
    break;
  
  case sample2:
    continue sample1;

  default:
    print('犬も猫も好き');
    break;
}

◆ if文

main.dart
var pets = "ペット";

if (pets == "犬") {
  print('犬好き');
} else if (pets == "猫") {
  print('猫好き');
} else
  print('犬も猫も好き');
}

【setStateメソッド】

◆ setState

main.dart
int _count = 0;

void _sampleCounter() {
  setState(() {
    _count++;
  });
}

参考文献

1
1
0

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
1
1

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?