Skip to main content

Flutter Web Application Development with and setting the path url strategy

Web Application Development with Flutter 

Flutter 2.0 is now live and the creation of the web application using Flutter is now fully supported. In this blog post, we are going to create a web application using Flutter and Navigator 2.0.

Create Web Application Project 

For creating the web application using you need to install  2.0 or a later version of the Flutter. You check the version of the dart and Flutter using the below command.

flutter --version
Flutter 2.0.6 • channel stable • https://github.com/flutter/flutter.git
Framework • revision 1d9032c7e1 (2 weeks ago) • 2021-04-29 17:37:58 -0700
Engine • revision 05e680e202
Tools • Dart 2.12.3

You can follow the steps mention on flutter.dev getting started page to configure the web application. For this post, I am going to create a simple web application that will show the route name in the browser as we change the view in the apps. Let's give the project a name web navigator demo.

Step1:- Create a Web Application using Android Studio

Open the Android Studio and tab on File -> New Flutter Project It will open the below Window as per the latest android studio version 4.2.1

Choose Flutter App and tab on next:-

If you want to create only for the Web then untick the Android and iOS option in the above window and give the name to project and tab on Finish. It will create a project with basic code in it.

For testing the web application just select the browser and tab on run, first time it will take some time to complete the compilation and then launch the application in the separate Chrome tab.


How to remove the # in the Url of the web application in Flutter

For removing the # from the URL pattern we have two options.

Option 1:  Configure the URL strategy as advised in the Flutter document
Add the following in the pubspec.yaml file and set the path into your main.dart file before the runApp().
dependencies:
flutter:
sdk: flutter
flutter_web_plugins:
sdk: flutter

void main() {
setUrlStrategy(PathUrlStrategy());
runApp(MyApp());
}
Option2: If you don't want to use the flutter_web_plugin then add the url_strategy package and add the below code in main.dart file before runApp() like given below.
void main() {
  // Here we set the URL strategy for our web app.
  // It is safe to call this function when running on mobile or desktop as well.
  setPathUrlStrategy();
  runApp(MyApp());
}

Thanks for visiting the page, will continue on this Web application and the next post will share the routing of the web application with Navigator 2.0


Comments

Popular posts from this blog

Flutter How to Start Android Activity from Flutter View

Flutter and Dart is an excellent combination for creating the UI, but for accessing the platform-specific service we need to open platform-specific activity. So lets in this article we will explore how to start an android activity and access the service from Flutter View. Create a Project for this Android Activity Flutter View Demo Create a Project From File menu select the New Flutter Project Enter the project name Select the AndroidX support and click on next After the above, we step click on Finish We will have the following project structure created. Create the Second Activity in Android Just go to the android folder and open it in separate windows. We will have the following project structure. Create the Activity Just right-click on the Kotlin folder and create a blank activity from the menu. If you create the activity then you may be required to upgrade the Gradle and do some import. So Just click on update and wait for the project s

WordPress Android App with REST API And Retrofit

Retrofit is the library which converts your JSON data into Java object. In this tutorial, we will learn about how to implement the Retrofit to create a WordPress Mobile App. As we all know, WordPress is the one of the biggest CMS (Content Management System) of the world. Wordpress full fill the requirements for all most every type of the website. So, in this tutorial, I am going to learn how to create an Android App using the WordPress REST API and Retrofit. What is Retrofit? If you want to know about Retrofit, I would like to give you just a simple one-line explanation of the Retrofit. It is a library which converts your REST HTTP request to Java interface. We will learn how we can do all these stuff using some very simple steps. Further, you can check the Retrofit Library here . So, In this tutorial, we will use the Retrofit to retrieve all post and there except ( A short Description of Post) form a WordPress website. Prerequisite for using the Retrofit for WordPress Android App Ther

Flutter State Management With Provider and ChangeNotifier

Flutter state management with provider library and why it's so important? There are lots of topics in flutter which are very important but out of those state management of your flutter application is the most important and little bit complicated as well. So in this article, I will try to explain how to use the provider package for managing the state of flutter and dart application and how to access the data down the hierarchy of the widget tree without recreating the whole UI. Basic knowledge of the state management and data flow in the Flutter Before starting the coding I would like to explain some basics about the Flutter application so that you can understand, why it's important to manage the state of your application in the correct way. In Flutter, everything is a widget and whenever the state of your application changes the UI is recreated the UI with the new data. Let's list out the topic or problem that we are going to explore about state management. Challenge o