{"id":900,"date":"2024-07-14T19:24:13","date_gmt":"2024-07-14T19:24:13","guid":{"rendered":"https:\/\/www.cmsgalaxy.com\/blog\/?p=900"},"modified":"2024-07-14T19:24:15","modified_gmt":"2024-07-14T19:24:15","slug":"what-is-import-in-flutter","status":"publish","type":"post","link":"https:\/\/www.cmsgalaxy.com\/blog\/what-is-import-in-flutter\/","title":{"rendered":"WHAT IS &#8220;import&#8221; IN FLUTTER"},"content":{"rendered":"\n<p>In Flutter, the <code>import<\/code> statement is used to include external libraries, packages, or other Dart files into your current Dart file. This allows you to access and use the classes, functions, and other members defined in those external sources.<\/p>\n\n\n\n<p>Here is a basic example of how <code>import<\/code> is used in Flutter:<\/p>\n\n\n\n<p><strong>Importing Dart Packages<\/strong><\/p>\n\n\n\n<p>To use built-in Dart packages or libraries, you use the <code>dart:<\/code> prefix:<\/p>\n\n\n\n<pre class=\"wp-block-preformatted\">import 'dart:io'; \/\/ Importing the Dart I\/O library<br>import 'dart:convert'; \/\/ Importing the Dart convert library<\/pre>\n\n\n\n<p><strong>Importing Flutter Packages<\/strong><\/p>\n\n\n\n<p>To use Flutter-specific packages, you use the <code>package:<\/code> prefix:<\/p>\n\n\n\n<pre class=\"wp-block-preformatted\">import 'package:flutter\/material.dart'; \/\/ Importing the Flutter material package<br>import 'package:flutter\/widgets.dart'; \/\/ Importing the Flutter widgets package<\/pre>\n\n\n\n<p><strong>Importing Files from Your Project<\/strong><\/p>\n\n\n\n<p>You can also import other Dart files from your own project:<\/p>\n\n\n\n<pre class=\"wp-block-preformatted\">import 'my_widget.dart'; \/\/ Importing a Dart file from the same directory<br>import 'src\/utils\/helpers.dart'; \/\/ Importing a Dart file from a subdirectory<\/pre>\n\n\n\n<p><strong>Deferred Imports<\/strong><\/p>\n\n\n\n<p>Deferred imports allow for lazy loading of libraries, which can help reduce the initial startup time of your app. Use the <code>deferred as<\/code> keyword:<\/p>\n\n\n\n<pre class=\"wp-block-preformatted\">import 'package:my_package\/my_library.dart' deferred as myLib;<br><br>void main() async {<br>  await myLib.loadLibrary(); \/\/ Load the library before using it<br>  myLib.someFunction(); \/\/ Now you can use the library's functions<br>}<\/pre>\n","protected":false},"excerpt":{"rendered":"<p>In Flutter, the import statement is used to include external libraries, packages, or other Dart files into your current Dart<\/p>\n","protected":false},"author":5,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[1],"tags":[],"class_list":["post-900","post","type-post","status-publish","format-standard","hentry","category-uncategorized"],"_links":{"self":[{"href":"https:\/\/www.cmsgalaxy.com\/blog\/wp-json\/wp\/v2\/posts\/900","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/www.cmsgalaxy.com\/blog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.cmsgalaxy.com\/blog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.cmsgalaxy.com\/blog\/wp-json\/wp\/v2\/users\/5"}],"replies":[{"embeddable":true,"href":"https:\/\/www.cmsgalaxy.com\/blog\/wp-json\/wp\/v2\/comments?post=900"}],"version-history":[{"count":1,"href":"https:\/\/www.cmsgalaxy.com\/blog\/wp-json\/wp\/v2\/posts\/900\/revisions"}],"predecessor-version":[{"id":901,"href":"https:\/\/www.cmsgalaxy.com\/blog\/wp-json\/wp\/v2\/posts\/900\/revisions\/901"}],"wp:attachment":[{"href":"https:\/\/www.cmsgalaxy.com\/blog\/wp-json\/wp\/v2\/media?parent=900"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.cmsgalaxy.com\/blog\/wp-json\/wp\/v2\/categories?post=900"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.cmsgalaxy.com\/blog\/wp-json\/wp\/v2\/tags?post=900"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}