CodeBlanks Logo Icon CodeBlanks

Summary - Flutter web

Combine build web and setUrlStrategy for a web app.

Summary - Flutter web

Publishing a Flutter web app combines two steps: produce a production bundle with flutter build web, and remove the '#' from the URL with setUrlStrategy(PathUrlStrategy()). Together they yield a fast web app with clean URLs.

// Terminal
flutter build web

// main.dart
setUrlStrategy(PathUrlStrategy());

Practice Publishing steps list

In main, define a list with two commands: ['flutter build web', 'setUrlStrategy']. Print the length of the list.

Starter code

main.dart
void main() {
  // flutter build web ve setUrlStrategy elemanlarından oluşan steps listesi tanımla
  // uzunluğunu yazdır
}

Sample solution

main.dart
void main() {
  final steps = ['flutter build web', 'setUrlStrategy'];
  print(steps.length);
}

Expected output

2

Questions and answers

Review the lesson questions together with their answers. To test yourself, solve the lesson interactively.

1 Which two steps combine when publishing a Flutter web app?

  • flutter clean and flutter analyze
  • flutter build web and setUrlStrategy Correct answer
  • flutter run and flutter test
  • flutter create and flutter pub get

Explanation: flutter build web produces the production bundle, setUrlStrategy removes the '#' from the URL; together they form the published web app.

2 setUrlStrategy call

Question
____(PathUrlStrategy());
Answer
setUrlStrategy(PathUrlStrategy());

Explanation: setUrlStrategy sets the URL strategy; setPath, configureUrl and urlStrategy are not valid function names in flutter_web_plugins.

3 Flutter web summary matches

Term Meaning
flutter_web Browser platform
build_web Build step
setUrlStrategy URL configuration
PathUrlStrategy Clean URL strategy

All lessons in Expert