CORS with Dart, how do I get it to work?

Was facing the same problem. Below is my server code. It just prints the query parameters. Added access control headers to fix the issue. HttpServer.bind(‘127.0.0.1’, 8080).then((server){ server.listen((HttpRequest request){ request.uri.queryParameters.forEach((param,val){ print(param + ‘-‘ + val); }); request.response.headers.add(“Access-Control-Allow-Origin”, “*”); request.response.headers.add(“Access-Control-Allow-Methods”, “POST,GET,DELETE,PUT,OPTIONS”); request.response.statusCode = HttpStatus.OK; request.response.write(“Success!”); request.response.close(); }); }); Hope this helps.

How does a set determine that two objects are equal in dart?

For a comprehensive write-up about operator== in Dart see http://work.j832.com/2014/05/equality-and-dart.html It just checks if they are equal a == b You can override the == operator to customize this behavior. Keep in mind that also hashCode should be overridden when the == operator is overridden. class Action { @override bool operator==(other) { // Dart ensures … Read more

How to convert asset image to File?

You can access the byte data via rootBundle. Then, you can save it to the device’s temporary directory which is obtained by path_provider (you need to add it as a dependency). import ‘dart:async’; import ‘dart:io’; import ‘package:flutter/services.dart’ show rootBundle; import ‘package:path_provider/path_provider.dart’; Future<File> getImageFileFromAssets(String path) async { final byteData = await rootBundle.load(‘assets/$path’); final file = File(‘${(await … Read more

Flutter floating action button with speed dial

Here’s a sketch of how to implement a Speed dial using FloatingActionButton. import ‘package:flutter/material.dart’; import ‘dart:math’ as math; void main() { runApp(new MyApp()); } class MyApp extends StatelessWidget { @override Widget build(BuildContext context) { return new MaterialApp( home: new MyHomePage(), ); } } class MyHomePage extends StatefulWidget { @override State createState() => new MyHomePageState(); } … Read more

Multiple widgets used the same GlobalKey

Could you create your keys “by hand” and use static/constant values? e.g. … import ‘package:flutter/widgets.dart’; class RIKeys { static final riKey1 = const Key(‘__RIKEY1__’); static final riKey2 = const Key(‘__RIKEY2__’); static final riKey3 = const Key(‘__RIKEY3__’); } then in … body: new TabBarView( children: [ new RefreshIndicator(new RefreshIndicator( // Use the Manual Static Value instead … Read more

How do I crop an image in Flutter?

I would probably use a BoxDecoration with a DecorationImage. You can use the alignment and fit properties to determine how your image is cropped. You can use an AspectRatio widget if you don’t want to hard code a height on the Container. import ‘package:flutter/material.dart’; void main() { runApp(new MaterialApp( home: new MyHomePage(), )); } class … Read more

How can we change appbar background color in flutter

Declare your Color: const primaryColor = Color(0xFF151026); In the MaterialApp level (will change the AppBar Color in the whole app ) change primaryColor return MaterialApp( title: ‘Flutter Demo’, theme: ThemeData( primaryColor: primaryColor, ), home: MyApp(), ); and if you want to change it on the Widget level modify the backgroundColor appBar: AppBar( backgroundColor: primaryColor, ),

Display SnackBar in Flutter

In my case i had code like this (in class state) final GlobalKey<ScaffoldState> _scaffoldKey = new GlobalKey<ScaffoldState>(); void showInSnackBar(String value) { _scaffoldKey.currentState.showSnackBar(new SnackBar(content: new Text(value))); } but i didn’t setup the key for scaffold. so when i add key: _scaffoldKey @override Widget build(BuildContext context) { return new Scaffold( key: _scaffoldKey, body: new SafeArea( snackbar start … Read more