<Flutter Dart>特殊文字のエスケープ

シングルクォーテーションでくくっている文字列内にシングルクォーテーションがあった場合にはエラーとなります。これはひとつの例であり、特殊文字が含まれる場合は対応が必要となります。

print('I'm Bob');

// output
// Error: String starting with ' must end with '.
  print('I'm Bob');

文字列をダブルクォーテーションでくくる

print("I'm Bob");

// output
// I'm Bob

バックスラッシュをつける

print('I\'m Bob');

// output
// I'm Bob