Leonardo da Silva
Leonardo da Silva

Reputation: 1515

Use Flutter foundation types without Flutter

There are three types that are present on the lib 'package:flutter/foundation.dart' that I need to use in an environment without Flutter. They are: ByteData, ReadBuffer and WriteBuffer. Is it possible to use these classes without having the whole Flutter as dependency?

The reason why I need to use it in an environment without Flutter is because I have a server made using Dart and I need to use these classes to encode/decode my socket messages.

Thanks in advance!

Upvotes: 2

Views: 364

Answers (1)

camelCase1492
camelCase1492

Reputation: 672

If you want access to classes in package:flutter/foundation.dart you can create a new flutter project as normal and remove runApp() from main() like this:

void main() {
 print("This is now a console only program")
  //no runApp(new MaterialApp())
}

This code won't start any mobile app and doesn't need an emulator, just a console. I have done some projects only with Dart and you can use all non UI Material Classes, such as File, StringBuffer...

Note: Remember to add the path for dart in the system environment variables, in my case D:\APPS\flutter\bin\cache\dart-sdk\bin, then you can navigate to your flutter project and type dart lib/main.dart in the console to run the code

Upvotes: 1

Related Questions