How to save and download text file in Flutter web application

This method is based on manipulations with an HTML document. Some additional packages should be imported: import ‘dart:convert’; import ‘dart:html’ as html; // or package:universal_html/prefer_universal/html.dart Code snippet: final text=”this is the text file”; // prepare final bytes = utf8.encode(text); final blob = html.Blob([bytes]); final url = html.Url.createObjectUrlFromBlob(blob); final anchor = html.document.createElement(‘a’) as html.AnchorElement ..href = … Read more

How can a named route have URL parameters in flutter web?

tl;dr //in your example: settings.name = “/post?id=123” final settingsUri = Uri.parse(settings.name); //settingsUri.queryParameters is a map of all the query keys and values final postID = settingsUri.queryParameters[‘id’]; print(postID); //will print “123” Drilldown In a perfect world you would access queryParameters with Uri.base.queryParameters because: Uri.base Returns the natural base URI for the current platform. When running in … Read more

How can I navigate between 2 classes, one of them requires passing data? in flutter

you can use constructor but in this case, whenever you use this class, you have to provide value, also you can make class value nullable and check it on build time. Another way is passing data by Route. for more navigate-with-arguments Here are is example: Passing data using ModalRoute Navigator.of(context).push( MaterialPageRoute( builder: (context) => WidgetA(), … Read more

How to Pick files and Images for upload with flutter web

Using dart:html package directly in Flutter is not recommended. Instead, use this package: https://pub.dev/packages/file_picker. Example of how to use in Flutter Web: class FileUploadButton extends StatelessWidget { @override Widget build(BuildContext context) { return RaisedButton( child: Text(‘UPLOAD FILE’), onPressed: () async { var picked = await FilePicker.platform.pickFiles(); if (picked != null) { print(picked.files.first.name); } }, ); … Read more

Flutter API Fetch and Sending Data from One screen to another screen

You should try to declare constructor the first page accept the id and push this id to second page or screen like this below code is first page Navigator.push( context, MaterialPageRoute( builder: (context) => ABC.withId( id, ), ), ) the create constructor inside second page screen class ABC extends StatefulWidget { @override _ABCState createState() => … Read more

XMLHttpRequest error in flutter web [Enabling CORS AWS API gateway]

this worked for me, I added the below header on the lambda function return { statusCode: 200, headers: { “Access-Control-Allow-Origin”: “*”, // Required for CORS support to work “Access-Control-Allow-Credentials”: true, // Required for cookies, authorization headers with HTTPS “Access-Control-Allow-Headers”: “Origin,Content-Type,X-Amz-Date,Authorization,X-Api-Key,X-Amz-Security-Token,locale”, “Access-Control-Allow-Methods”: “POST, OPTIONS” }, body: JSON.stringify(item) };