Strings and Quotes
Part of the Your First App section of Coddy's Flutter journey. Lesson 5 of 32.
A string starts and ends with a quote. That makes an apostrophe tricky: in 'It's', Dart thinks the string ends after It, and the rest is not code it understands. The app does not even start.
There are two ways out. Put a backslash before the apostrophe, so Dart knows it is part of the string:
Text('It\'s raining')Or start and end the string with double quotes. Dart accepts both kinds, so inside double quotes an apostrophe is just a letter:
Text("It's raining")Challenge
EasyThe app shows Its my app. Fix the spelling so it shows It's my app, with the apostrophe.
Try it yourself
import 'package:flutter/material.dart';
void main() {
runApp(const MyApp());
}
class MyApp extends StatelessWidget {
const MyApp({super.key});
@override
Widget build(BuildContext context) {
return MaterialApp(
debugShowCheckedModeBanner: false,
home: Scaffold(
body: Center(
child: Text('Its my app'),
),
),
);
}
}
This lesson includes a short quiz. Start the lesson to answer it and track your progress.
All lessons in Your First App
1Hello, Flutter
What Is Flutter?Change the TextThe Widget TreeScaffold and AppBarStrings and QuotesCommentsPractice on your own: Online Flutter compiler