[{"data":1,"prerenderedAt":2223},["ShallowReactive",2],{"navigation_docs_en":3,"-en-flutter-for-jobseekers-using-packages-and-assets":95,"-en-flutter-for-jobseekers-using-packages-and-assets-surround":2218},[4,16],{"title":5,"icon":6,"path":7,"stem":8,"children":9,"page":15},"Getting Started","i-lucide-rocket","\u002Fen\u002Fgetting-started","en\u002F1.getting-started",[10],{"title":11,"path":12,"stem":13,"icon":14},"Introduction","\u002Fen\u002Fgetting-started\u002Fintroduction","en\u002F1.getting-started\u002F1.introduction","i-lucide-house",false,{"title":17,"icon":18,"path":19,"stem":20,"children":21,"page":15},"Flutter for Jobseekers","i-lucide-briefcase","\u002Fen\u002Fflutter-for-jobseekers","en\u002F2.flutter-for-jobseekers",[22,27,32,37,42,47,52,57,62,67,72,77,82,86,91],{"title":23,"path":24,"stem":25,"icon":26},"Introduction to Flutter","\u002Fen\u002Fflutter-for-jobseekers\u002Fintroduction-to-flutter","en\u002F2.flutter-for-jobseekers\u002F1.introduction-to-flutter","i-lucide-history",{"title":28,"path":29,"stem":30,"icon":31},"Market Opportunities for Flutter Developers","\u002Fen\u002Fflutter-for-jobseekers\u002Fmarket-opportunities","en\u002F2.flutter-for-jobseekers\u002F2.market-opportunities","i-lucide-trending-up",{"title":33,"path":34,"stem":35,"icon":36},"Installing Flutter and Configuring Your IDE","\u002Fen\u002Fflutter-for-jobseekers\u002Finstalling-flutter","en\u002F2.flutter-for-jobseekers\u002F3.installing-flutter","i-lucide-wrench",{"title":38,"path":39,"stem":40,"icon":41},"Introduction to Widgets","\u002Fen\u002Fflutter-for-jobseekers\u002Fintroduction-to-widgets","en\u002F2.flutter-for-jobseekers\u002F4.introduction-to-widgets","i-lucide-blocks",{"title":43,"path":44,"stem":45,"icon":46},"Handling User Input","\u002Fen\u002Fflutter-for-jobseekers\u002Fhandling-user-input","en\u002F2.flutter-for-jobseekers\u002F5.handling-user-input","i-lucide-text-cursor-input",{"title":48,"path":49,"stem":50,"icon":51},"Using 3rd Party Libraries and External Assets","\u002Fen\u002Fflutter-for-jobseekers\u002Fusing-packages-and-assets","en\u002F2.flutter-for-jobseekers\u002F6.using-packages-and-assets","i-lucide-package",{"title":53,"path":54,"stem":55,"icon":56},"Working with APIs and Asynchronous Operations","\u002Fen\u002Fflutter-for-jobseekers\u002Fworking-with-apis-and-async","en\u002F2.flutter-for-jobseekers\u002F7.working-with-apis-and-async","i-lucide-cloud-download",{"title":58,"path":59,"stem":60,"icon":61},"Navigation and Routing","\u002Fen\u002Fflutter-for-jobseekers\u002Fnavigation-and-routing","en\u002F2.flutter-for-jobseekers\u002F8.navigation-and-routing","i-lucide-route",{"title":63,"path":64,"stem":65,"icon":66},"State Management and the BLoC","\u002Fen\u002Fflutter-for-jobseekers\u002Fstate-management-and-bloc","en\u002F2.flutter-for-jobseekers\u002F9.state-management-and-bloc","i-lucide-boxes",{"title":68,"path":69,"stem":70,"icon":71},"Reactivity and Platform-Specific Considerations","\u002Fen\u002Fflutter-for-jobseekers\u002Freactivity-and-platforms","en\u002F2.flutter-for-jobseekers\u002F910.reactivity-and-platforms","i-lucide-monitor-smartphone",{"title":73,"path":74,"stem":75,"icon":76},"Debugging, Troubleshooting, and Performance Considerations","\u002Fen\u002Fflutter-for-jobseekers\u002Fdebugging-troubleshooting-performance","en\u002F2.flutter-for-jobseekers\u002F911.debugging-troubleshooting-performance","i-lucide-bug",{"title":78,"path":79,"stem":80,"icon":81},"Creating Your First Application","\u002Fen\u002Fflutter-for-jobseekers\u002Fcreating-your-first-application","en\u002F2.flutter-for-jobseekers\u002F912.creating-your-first-application","i-lucide-cloud-sun",{"title":83,"path":84,"stem":85,"icon":18},"Finding Flutter Jobs","\u002Fen\u002Fflutter-for-jobseekers\u002Ffinding-flutter-jobs","en\u002F2.flutter-for-jobseekers\u002F913.finding-flutter-jobs",{"title":87,"path":88,"stem":89,"icon":90},"Preparing for and Succeeding in the Job Interview","\u002Fen\u002Fflutter-for-jobseekers\u002Fpreparing-for-the-job-interview","en\u002F2.flutter-for-jobseekers\u002F914.preparing-for-the-job-interview","i-lucide-messages-square",{"title":92,"path":93,"stem":94,"icon":61},"Your Road Ahead","\u002Fen\u002Fflutter-for-jobseekers\u002Fyour-road-ahead","en\u002F2.flutter-for-jobseekers\u002F915.your-road-ahead",{"id":96,"title":48,"body":97,"description":2211,"extension":2212,"links":2213,"meta":2214,"navigation":2215,"path":49,"seo":2216,"stem":50,"__hash__":2217},"docs_en\u002Fen\u002F2.flutter-for-jobseekers\u002F6.using-packages-and-assets.md",{"type":98,"value":99,"toc":2171},"minimark",[100,120,124,127,132,167,170,186,203,210,255,258,316,336,347,355,361,364,367,377,382,388,395,405,480,487,500,511,537,540,544,547,570,573,668,671,715,718,753,757,764,767,770,773,787,791,798,856,896,900,906,913,920,943,984,995,999,1006,1024,1030,1039,1049,1053,1056,1066,1092,1096,1099,1113,1120,1123,1126,1142,1146,1149,1152,1159,1163,1170,1177,1181,1188,1215,1220,1229,1287,1309,1316,1327,1330,1333,1340,1344,1357,1360,1391,1398,1404,1411,1417,1423,1428,1454,1460,1466,1471,1497,1501,1514,1521,1527,1532,1535,1562,1576,1580,1590,1593,1611,1614,1620,1625,1628,1631,1641,1651,1661,1664,1670,1697,1704,1707,1713,1731,1734,1737,1744,1751,1793,1802,1805,1823,1835,1839,1842,1854,1858,1864,1867,1878,1882,1939,1943,1967,1971,2000,2048,2051,2073,2077,2167],[101,102,103,107],"u-page-hero",{},[104,105,48],"template",{"v-slot:title":106},"",[104,108,109,110,114,115,119],{"v-slot:description":106},"Writing software is hard. That is why, as software developers, we strive to ",[111,112,113],"strong",{},"solve a problem only once",". Would it not be great if you could benefit from the collected knowledge of Flutter developers everywhere, using ",[116,117,118],"em",{},"their"," widgets to solve the very problem you are currently facing?",[121,122,123],"p",{},"For instance, imagine you develop a practical widget that proves valuable across your entire application. In this scenario, you have successfully addressed a problem once and can now leverage the code repeatedly within your application.",[121,125,126],{},"In this chapter, we will look at the package ecosystem for Flutter and Dart, explore some popular packages, and learn how to include things such as images, sounds, fonts, and other resources in your application.",[128,129,131],"h2",{"id":130},"chapter-overview","Chapter overview",[133,134,135,162],"card-group",{},[136,137,140],"card",{"icon":138,"title":139},"i-lucide-list","Structure",[141,142,143,147,150,153,156,159],"ul",{},[144,145,146],"li",{},"Introduction to pubspec.yaml",[144,148,149],{},"Adding images and other assets to your application",[144,151,152],{},"Introduction to the Pub package management system",[144,154,155],{},"Finding useful packages on Pub",[144,157,158],{},"Using a package to play audio",[144,160,161],{},"Popular Pub packages",[136,163,166],{"icon":164,"title":165},"i-lucide-target","Objectives","Upon completion of this chapter, you will have learned how to include custom resources, such as images, fonts, and sounds in your application. You will also have a familiarity with the package management ecosystem for Flutter and Dart and learn how to evaluate the quality and usefulness of packages. You will also learn how to use a package to play an audio file that you have included in your application as a custom resource. Finally, you will learn about popular packages that are often used by the community.",[128,168,146],{"id":169},"introduction-to-pubspecyaml",[121,171,172,173,177,178,181,182,185],{},"Every Flutter application comes with a special file called ",[174,175,176],"code",{},"pubspec.yaml",". The file exists at the top-level directory of the project, alongside the ",[174,179,180],{},"lib"," directory. We often refer to this file as simply \"pubspec,\" which is how we will be referring to it from here on out. Pubspec contains a lot of metadata that Flutter and Dart need to know about your application and is written in the ",[111,183,184],{},"YAML"," language.",[187,188,189,190,193,194,202],"warning",{},"What is important to know about YAML is that ",[111,191,192],{},"whitespace (spaces versus tabs) matters",". You can learn more about YAML at ",[111,195,196],{},[197,198,199],"a",{"href":199,"rel":200},"https:\u002F\u002Fyaml.org\u002F",[201],"nofollow",".",[121,204,205,206,209],{},"Pubspec is used not only by Flutter but by Dart as well, although many of the sections (called ",[116,207,208],{},"directives",") in the file are specific to Flutter.",[133,211,212,244],{},[136,213,216,219,220,219,223,219,226,219,229,232,233,236,237,240,241,202],{"icon":214,"title":215},"i-simple-icons-dart","Used by Flutter and Dart",[174,217,218],{},"name",", ",[174,221,222],{},"description",[174,224,225],{},"publish_to",[174,227,228],{},"version",[174,230,231],{},"environment"," (and ",[174,234,235],{},"sdk","), ",[174,238,239],{},"dependencies",", and ",[174,242,243],{},"dev_dependencies",[136,245,248,249,252,253,202],{"icon":246,"title":247},"i-simple-icons-flutter","Specific to Flutter","Directives that are specific to Flutter are generally either defined within a ",[174,250,251],{},"flutter"," directive or are named ",[174,254,251],{},[121,256,257],{},"Ok, so, with all these directives, what do each of them do, and why would you want to change anything there? Let us run down the list and break it down.",[259,260,261,289,292,299,302,306,310],"field-group",{},[262,263,265,266,269,270,273,274,280,281,284,285,288],"field",{"name":218,"type":264},"directive","The name of your project, but with some specific requirements. This is not the label that will show up under the application icon, but rather the Dart ",[116,267,268],{},"package"," name. The requirements for the name are that it should be ",[111,271,272],{},"all lowercase with underscores"," separating the words. It cannot be one of the reserved keywords (as they are described here: ",[111,275,276],{},[197,277,278],{"href":278,"rel":279},"https:\u002F\u002Fdart.dev\u002Fguides\u002Flanguage\u002Flanguage-tour#keywords=",[201],"), should not include any non-Latin characters, any accented characters, and ",[116,282,283],{},"may"," include numbers (although it cannot ",[116,286,287],{},"start"," with a number).",[262,290,291],{"name":222,"type":264},"Optional and should be relatively short. (Think the length of a Tweet.) This is mostly useful if you are building a package to share with others, rather than an application. If you are only building an application, you do not technically need to put anything here.",[262,293,294,295,298],{"name":225,"type":264},"Should be set to ",[174,296,297],{},"'none'"," if you are working on an application, so that your application isn't accidentally published to Pub (which we will talk about later in this chapter).",[262,300,301],{"name":228,"type":264},"Where you can increment the version number of your application each time you are ready to release a new version. Flutter is configured, by default, to use this value in the application packages which are created when building the application.",[262,303,305],{"name":304,"type":264},"environment → sdk","Used to define the minimum and maximum versions of the Dart programming language which the application can be compiled and run with.",[262,307,309],{"name":308,"type":264},"dependencies \u002F dev_dependencies","Where you will add any external packages that your project will use. We will discuss this throughout the rest of the chapter.",[262,311,312,313,315],{"name":251,"type":264},"Under the ",[174,314,251],{}," directive, you can add any assets or external files to be included in your application.",[317,318,319,322,323,327,328,331,332,335],"note",{},[111,320,321],{},"Corrected:"," the Dart keywords list now lives at ",[197,324,325],{"href":325,"rel":326},"https:\u002F\u002Fdart.dev\u002Flanguage\u002Fkeywords",[201],". The pubspec reference states the same rules: \"The name should be all lowercase, with underscores to separate words, ",[174,329,330],{},"just_like_this",". Use only basic Latin letters and Arabic digits: ",[174,333,334],{},"[a-z0-9_]","\", and the name must not start with digits or be a reserved word (Dart, n.d.-a).",[121,337,338,339,342,343,346],{},"From time to time, Dart introduces new features (such as when ",[116,340,341],{},"constructor tearoffs"," were introduced in Dart 2.15.) If your application was created before Dart 2.15 was introduced and you wanted to leverage the new constructor tearoff feature in Dart, you would not be able to do so until you updated the ",[111,344,345],{},"minimum version"," in pubspec.",[348,349,350,351,354],"tip",{},"Likewise, when the next major version of Dart is released, there are bound to be some massive, breaking changes that would require a substantial rewrite of your application. This directive allows you to specify a ",[111,352,353],{},"maximum version",", so if Dart is upgraded to a new major version, it does not simply break everything.",[121,356,357,358,360],{},"Let us explore the ",[174,359,251],{}," directive next with a real-world example: you are building an application based on designs presented to you by a product designer.",[128,362,149],{"id":363},"adding-images-and-other-assets-to-your-application",[121,365,366],{},"The product designer has given you a design that includes some beautiful illustrations to spice up the application you will be building. Now, you need to find a way to include those illustrations in your application. So, what do you do?",[121,368,369,370,376],{},"It is customary to create an ",[111,371,372,375],{},[174,373,374],{},"assets"," folder"," at the top level of the application where your external assets such as fonts, images, sounds, and anything else you may need to include in your application will live. Many developers choose to further organize their assets folder into several subdirectories, as well.",[378,379,381],"h3",{"id":380},"images","Images",[121,383,384,385,387],{},"You take the illustrations your designer has provided to you and save them into a well-organized ",[174,386,374],{}," directory.",[187,389,390,391,394],{},"Simply adding the files, however, ",[111,392,393],{},"does not allow Flutter to access them",". We must go back to pubspec and add the directories there, too.",[121,396,312,397,400,401,404],{},[174,398,399],{},"flutter:"," directive, we will add an ",[174,402,403],{},"assets:"," directive, followed by any subdirectories. Here is what that might look like, although it will differ based upon what directories you've created:",[406,407,411],"pre",{"className":408,"code":409,"filename":176,"language":410,"meta":106,"style":106},"language-yaml shiki shiki-themes material-theme-lighter material-theme material-theme-palenight","flutter:\n  assets:\n    - images\u002F\n    # If there are any subdirectories you'd like to include,\n    # be sure to add those to the list as well.\n    - images\u002Fanother_subdirectory\u002F\n    - fonts\u002F\n    - sounds\u002F\n","yaml",[174,412,413,425,433,443,450,456,464,472],{"__ignoreMap":106},[414,415,418,421],"span",{"class":416,"line":417},"line",1,[414,419,251],{"class":420},"swJcz",[414,422,424],{"class":423},"sMK4o",":\n",[414,426,428,431],{"class":416,"line":427},2,[414,429,430],{"class":420},"  assets",[414,432,424],{"class":423},[414,434,436,439],{"class":416,"line":435},3,[414,437,438],{"class":423},"    -",[414,440,442],{"class":441},"sfazB"," images\u002F\n",[414,444,446],{"class":416,"line":445},4,[414,447,449],{"class":448},"sHwdD","    # If there are any subdirectories you'd like to include,\n",[414,451,453],{"class":416,"line":452},5,[414,454,455],{"class":448},"    # be sure to add those to the list as well.\n",[414,457,459,461],{"class":416,"line":458},6,[414,460,438],{"class":423},[414,462,463],{"class":441}," images\u002Fanother_subdirectory\u002F\n",[414,465,467,469],{"class":416,"line":466},7,[414,468,438],{"class":423},[414,470,471],{"class":441}," fonts\u002F\n",[414,473,475,477],{"class":416,"line":474},8,[414,476,438],{"class":423},[414,478,479],{"class":441}," sounds\u002F\n",[348,481,482,483,486],{},"Note that it is ",[111,484,485],{},"not necessary to specify each file"," explicitly. By specifying a directory where multiple files exist, Flutter is smart enough to know to include everything within the directory.",[121,488,489,490,493,494,499],{},"Finally, we are ready to add the image to our application! The ",[174,491,492],{},"Image"," widget has an easy way to display images that you have included in your application as assets. It can be accessed using the ",[111,495,496],{},[174,497,498],{},"Image.asset()"," constructor, then passing in the path to the image as a positional parameter:",[406,501,505],{"className":502,"code":503,"language":504,"meta":106,"style":106},"language-dart shiki shiki-themes material-theme-lighter material-theme material-theme-palenight","Image.asset('assets\u002Fimages\u002Fmy_beautiful_picture.jpg'),\n","dart",[174,506,507],{"__ignoreMap":106},[414,508,509],{"class":416,"line":417},[414,510,503],{},[317,512,513,515,516,518,519,521,522,219,525,528,529,532,533,536],{},[111,514,321],{}," \"Each asset is identified by an explicit path (relative to the ",[174,517,176],{}," file) where the asset file is located\" (Flutter, n.d.). With the files in an ",[174,520,374],{}," folder, the entries must include it (",[174,523,524],{},"- assets\u002Fimages\u002F",[174,526,527],{},"- assets\u002Fimages\u002Fanother_subdirectory\u002F",", and so on); as printed, ",[174,530,531],{},"images\u002F"," does not match ",[174,534,535],{},"assets\u002Fimages\u002Fmy_beautiful_picture.jpg",". A directory entry also includes \"only files located directly in the directory\", which is why each subdirectory needs its own entry.",[121,538,539],{},"That is all there is to it! Now you can add all those beautiful illustrations that the designer gave you. A job well done!",[378,541,543],{"id":542},"fonts","Fonts",[121,545,546],{},"Adding fonts can be done in a similar way, although there are a couple of extra options available to us.",[548,549,551,556,559,563],"steps",{"level":550},"4",[552,553,555],"h4",{"id":554},"name-the-family","Name the family",[121,557,558],{},"First, we specify the name of the font we will be using. This name is how we will refer to the font within the application and does not necessarily have to be the name of the font itself.",[552,560,562],{"id":561},"list-the-font-files","List the font files",[121,564,565,566,569],{},"Next, we specify each font file as an asset for the font family. We do this because some fonts are split into multiple files, where each file may define the font with a different font ",[116,567,568],{},"weight",", or how thick the letters are.",[121,571,572],{},"A complete example with multiple font files of different font weights and styles might look something like the following:",[406,574,576],{"className":408,"code":575,"filename":176,"language":410,"meta":106,"style":106},"flutter:\n  fonts:\n    - family: Comic Sans\n      fonts:\n        - asset: assets\u002FComicSans-Regular.ttf\n        - asset: assets\u002FComicSans-Bold.ttf\n          weight: 700\n        - asset: assets\u002FComicSans-Italic.ttf\n          style: italic\n",[174,577,578,584,591,604,611,624,635,646,657],{"__ignoreMap":106},[414,579,580,582],{"class":416,"line":417},[414,581,251],{"class":420},[414,583,424],{"class":423},[414,585,586,589],{"class":416,"line":427},[414,587,588],{"class":420},"  fonts",[414,590,424],{"class":423},[414,592,593,595,598,601],{"class":416,"line":435},[414,594,438],{"class":423},[414,596,597],{"class":420}," family",[414,599,600],{"class":423},":",[414,602,603],{"class":441}," Comic Sans\n",[414,605,606,609],{"class":416,"line":445},[414,607,608],{"class":420},"      fonts",[414,610,424],{"class":423},[414,612,613,616,619,621],{"class":416,"line":452},[414,614,615],{"class":423},"        -",[414,617,618],{"class":420}," asset",[414,620,600],{"class":423},[414,622,623],{"class":441}," assets\u002FComicSans-Regular.ttf\n",[414,625,626,628,630,632],{"class":416,"line":458},[414,627,615],{"class":423},[414,629,618],{"class":420},[414,631,600],{"class":423},[414,633,634],{"class":441}," assets\u002FComicSans-Bold.ttf\n",[414,636,637,640,642],{"class":416,"line":466},[414,638,639],{"class":420},"          weight",[414,641,600],{"class":423},[414,643,645],{"class":644},"sbssI"," 700\n",[414,647,648,650,652,654],{"class":416,"line":474},[414,649,615],{"class":423},[414,651,618],{"class":420},[414,653,600],{"class":423},[414,655,656],{"class":441}," assets\u002FComicSans-Italic.ttf\n",[414,658,660,663,665],{"class":416,"line":659},9,[414,661,662],{"class":420},"          style",[414,664,600],{"class":423},[414,666,667],{"class":441}," italic\n",[121,669,670],{},"However, if your font only has one file, it is possible to specify a single asset with no associated font weight or style:",[406,672,674],{"className":408,"code":673,"filename":176,"language":410,"meta":106,"style":106},"flutter:\n  fonts:\n    - family: Comic Sans\n      fonts:\n        - asset: assets\u002FComicSans.ttf\n",[174,675,676,682,688,698,704],{"__ignoreMap":106},[414,677,678,680],{"class":416,"line":417},[414,679,251],{"class":420},[414,681,424],{"class":423},[414,683,684,686],{"class":416,"line":427},[414,685,588],{"class":420},[414,687,424],{"class":423},[414,689,690,692,694,696],{"class":416,"line":435},[414,691,438],{"class":423},[414,693,597],{"class":420},[414,695,600],{"class":423},[414,697,603],{"class":441},[414,699,700,702],{"class":416,"line":445},[414,701,608],{"class":420},[414,703,424],{"class":423},[414,705,706,708,710,712],{"class":416,"line":452},[414,707,615],{"class":423},[414,709,618],{"class":420},[414,711,600],{"class":423},[414,713,714],{"class":441}," assets\u002FComicSans.ttf\n",[121,716,717],{},"Now that you have got your font set up in pubspec, you can reference it by the name you have given it in your application:",[406,719,721],{"className":502,"code":720,"language":504,"meta":106,"style":106},"Text(\n  'Comic Sans is arguably the greatest font face of all time.',\n  style: TextStyle(\n    fontFamily: 'Comic Sans'\n  ),\n),\n",[174,722,723,728,733,738,743,748],{"__ignoreMap":106},[414,724,725],{"class":416,"line":417},[414,726,727],{},"Text(\n",[414,729,730],{"class":416,"line":427},[414,731,732],{},"  'Comic Sans is arguably the greatest font face of all time.',\n",[414,734,735],{"class":416,"line":435},[414,736,737],{},"  style: TextStyle(\n",[414,739,740],{"class":416,"line":445},[414,741,742],{},"    fontFamily: 'Comic Sans'\n",[414,744,745],{"class":416,"line":452},[414,746,747],{},"  ),\n",[414,749,750],{"class":416,"line":458},[414,751,752],{},"),\n",[378,754,756],{"id":755},"sounds","Sounds",[317,758,759,760,763],{},"When it comes to playing audio, things become a bit trickier. Since ",[111,761,762],{},"Flutter has no native way of playing audio",", we will have to employ the use of a package.",[121,765,766],{},"Let us first explore Flutter's package management system, and then we can look at a couple of useful packages, including one which will allow us to build a fully featured audio-playing application.",[128,768,152],{"id":769},"introduction-to-the-pub-package-management-system",[121,771,772],{},"From the very start, Flutter was designed to allow the ability to import other people's code and use it in your own project. This ability to reuse code written by others opens the door to building apps and experiences that would not otherwise be possible for a sole developer to accomplish on their own.",[348,774,775,776,779,780,786],{},"There are ",[111,777,778],{},"thousands of packages — all open-source"," — that have been created by and shared with the Flutter community, for free. Developers who create a package and share it with the community submit their package to a website called Pub (",[111,781,782],{},[197,783,784],{"href":784,"rel":785},"https:\u002F\u002Fpub.dev\u002F",[201],"), where anyone can go to discover and see the documentation for all manner of packages shared by and to the community.",[378,788,790],{"id":789},"adding-a-dependency","Adding a dependency",[121,792,793,794,797],{},"Packages are added to your Flutter project by modifying pubspec in the ",[174,795,796],{},"dependencies:"," directive. The way you add a package is by specifying first the package name, followed by a colon, then the version number. A complete example would look like the following:",[406,799,801],{"className":408,"code":800,"filename":176,"language":410,"meta":106,"style":106},"dependencies:\n  flutter:\n    sdk: flutter\n  google_fonts: ^5.0.0\n  path: any\n  provider: 6.0.5\n",[174,802,803,809,816,826,836,846],{"__ignoreMap":106},[414,804,805,807],{"class":416,"line":417},[414,806,239],{"class":420},[414,808,424],{"class":423},[414,810,811,814],{"class":416,"line":427},[414,812,813],{"class":420},"  flutter",[414,815,424],{"class":423},[414,817,818,821,823],{"class":416,"line":435},[414,819,820],{"class":420},"    sdk",[414,822,600],{"class":423},[414,824,825],{"class":441}," flutter\n",[414,827,828,831,833],{"class":416,"line":445},[414,829,830],{"class":420},"  google_fonts",[414,832,600],{"class":423},[414,834,835],{"class":441}," ^5.0.0\n",[414,837,838,841,843],{"class":416,"line":452},[414,839,840],{"class":420},"  path",[414,842,600],{"class":423},[414,844,845],{"class":441}," any\n",[414,847,848,851,853],{"class":416,"line":458},[414,849,850],{"class":420},"  provider",[414,852,600],{"class":423},[414,854,855],{"class":644}," 6.0.5\n",[121,857,858,859,861,862,865,866,872,873,876,877,880,881,884,885,887,888,880,891,887,893,202],{},"Note that ",[174,860,251],{}," is always included as a dependency for our Flutter projects. In this example, we have added the ",[174,863,864],{},"google_fonts"," package to our application, allowing us to use any of the fonts listed at ",[111,867,868],{},[197,869,870],{"href":870,"rel":871},"https:\u002F\u002Ffonts.google.com\u002F",[201]," in our application. Also, note the caret (",[174,874,875],{},"^",") in front of the version number. We use this to specify a version range, rather than a specific version. We also added the ",[174,878,879],{},"path"," and ",[174,882,883],{},"provider"," packages, with ",[174,886,879],{}," being set to the version ",[174,889,890],{},"any",[174,892,883],{},[174,894,895],{},"6.0.5",[378,897,899],{"id":898},"version-ranges","Version ranges",[121,901,902,903,202],{},"Much like an application, a package can have its own dependencies. These dependencies will also have version numbers specified in their pubspec. When adding a package with its own dependencies as a dependency to your application, the package's dependencies are also added to your application as ",[111,904,905],{},"transitive dependencies",[187,907,908,909,912],{},"If a package requires a particular version of a dependency, for example, version 2.4.1, and you have the same dependency in your application, but you have set the version to 2.4.0, there would be a ",[111,910,911],{},"version mismatch",". Your application would require an older version, whereas the package would require a newer version.",[121,914,915,916,919],{},"This is where version ranges come into play. By specifying a caret before the version, Flutter knows that it's allowed to use a range of acceptable versions. In our example, specifying ",[174,917,918],{},"^5.0.0"," would allow any version from 5.0.0 to 6.0.0, satisfying the needs of both the application's dependency as well as the package's dependency. It is for this reason that it is recommended to use version ranges when adding dependencies to your application.",[317,921,922,924,925,928,929,931,932,935,936,931,939,942],{},[111,923,321],{}," the caret range stops ",[116,926,927],{},"before"," the next major version, so ",[174,930,918],{}," means ",[174,933,934],{},">=5.0.0 \u003C6.0.0",": \"",[174,937,938],{},"^version",[116,940,941],{},"the range of all versions guaranteed to be backwards compatible with the given version","\", up to the next one to introduce a breaking change (Dart, n.d.-b). Version 6.0.0 itself is not allowed.",[133,944,945,957,966],{},[136,946,949,950,952,953,956],{"icon":947,"title":948},"i-lucide-lock","Specific version (provider: 6.0.5)","It is also possible to use a specific version, such as when we specified a version for ",[174,951,883],{},". In our example, only version 6.0.5 is allowed to be resolved, requiring other packages to conform to that decision. This is the ",[111,954,955],{},"most restrictive"," way to specify a version number.",[136,958,961,962,965],{"icon":959,"title":960},"i-lucide-move-horizontal","Range (google_fonts: ^5.0.0)","A range of acceptable versions, satisfying both the application and its packages. The ",[111,963,964],{},"recommended"," way.",[136,967,970,971,973,974,976,977,980,981,983],{"icon":968,"title":969},"i-lucide-infinity","Any (path: any)","The version of ",[174,972,879],{}," we chose, ",[174,975,890],{},", is the ",[111,978,979],{},"least restrictive",". If you specify ",[174,982,890],{}," for the version, the latest possible version that works with the rest of your dependencies will be used.",[985,986,987,988,990,991,994],"caution",{},"Using ",[174,989,890],{}," can cause ",[111,992,993],{},"breaking changes"," if the package suddenly updates to a new, major version, so be careful when using this.",[378,996,998],{"id":997},"downloading-and-importing","Downloading and importing",[121,1000,1001,1002,1005],{},"Once the dependency has been added to your pubspec, it will need to be downloaded and cached before you can start using it. Be sure to save the file, then use the command ",[174,1003,1004],{},"flutter pub get"," to download the package.",[406,1007,1011],{"className":1008,"code":1009,"language":1010,"meta":106,"style":106},"language-bash shiki shiki-themes material-theme-lighter material-theme material-theme-palenight","flutter pub get\n","bash",[174,1012,1013],{"__ignoreMap":106},[414,1014,1015,1018,1021],{"class":416,"line":417},[414,1016,251],{"class":1017},"sBMFI",[414,1019,1020],{"class":441}," pub",[414,1022,1023],{"class":441}," get\n",[121,1025,1026,1027,1029],{},"Now that the package has been downloaded, it is ready for use in your project. The last step to using the package in your project is to import it into the file where you want to use it. Let us import the ",[174,1028,864],{}," package that we added as a dependency earlier. At the top of the file, you will include it like the following:",[406,1031,1033],{"className":502,"code":1032,"language":504,"meta":106,"style":106},"import 'package:google_fonts\u002Fgoogle_fonts.dart';\n",[174,1034,1035],{"__ignoreMap":106},[414,1036,1037],{"class":416,"line":417},[414,1038,1032],{},[121,1040,1041,1042,880,1045,1048],{},"From there, you will be able to use the widget(s) provided by the package as though they were code you have written in the file, yourself. You are already used to doing this: we have been using the ",[174,1043,1044],{},"Material",[174,1046,1047],{},"Cupertino"," packages throughout this book!",[378,1050,1052],{"id":1051},"keeping-packages-up-to-date","Keeping packages up to date",[121,1054,1055],{},"Packages are updated all the time by their developers to meet their own needs and the needs of the community. It is a good idea to keep your packages up to date with the newest versions, but doing that by hand can be a long, frustrating process. Thankfully, we have another command for that.",[121,1057,1058,1059,1062,1063,202],{},"To upgrade the packages in your project to the latest versions within the version ranges you specified in your pubspec, you can run the command ",[174,1060,1061],{},"flutter pub upgrade",". If you would like to include newer versions of packages that are not within your specified version ranges as well, you can instead use the command ",[174,1064,1065],{},"flutter pub upgrade --major-versions",[406,1067,1069],{"className":1008,"code":1068,"language":1010,"meta":106,"style":106},"flutter pub upgrade\nflutter pub upgrade --major-versions\n",[174,1070,1071,1080],{"__ignoreMap":106},[414,1072,1073,1075,1077],{"class":416,"line":417},[414,1074,251],{"class":1017},[414,1076,1020],{"class":441},[414,1078,1079],{"class":441}," upgrade\n",[414,1081,1082,1084,1086,1089],{"class":416,"line":427},[414,1083,251],{"class":1017},[414,1085,1020],{"class":441},[414,1087,1088],{"class":441}," upgrade",[414,1090,1091],{"class":441}," --major-versions\n",[378,1093,1095],{"id":1094},"troubleshooting-the-package-cache","Troubleshooting the package cache",[121,1097,1098],{},"Finally, there may come a time when you find yourself needing to troubleshoot why your application is not building and you suspect it might have something to do with the packages you have imported.",[133,1100,1101,1109],{},[136,1102,1105,1106,1108],{"icon":1103,"title":1104},"i-lucide-trash-2","flutter pub cache clean","Removes all packages which have been downloaded (this is generally followed by ",[174,1107,1004],{}," to re-download the packages necessary for your project).",[136,1110,1112],{"icon":36,"title":1111},"flutter pub cache repair","Re-downloads all the packages for your project without cleaning the cache first.",[187,1114,1115,1116,1119],{},"Keep in mind that running these commands will affect the packages ",[111,1117,1118],{},"for all projects",", not just the one you are currently working on.",[128,1121,155],{"id":1122},"finding-useful-packages-on-pub",[121,1124,1125],{},"Pub has a huge selection of packages to choose from. Some packages are written for Dart (which can then be used in any Dart-based application, including Flutter applications), whereas others explicitly require the Flutter framework. Furthermore, packages are sometimes designed to work with specific platforms and may or may not have support for others. There may be a package that works on Android and iOS but isn't compatible with the Web or desktop operating systems, for example. With so many packages available, though, how do you decide which are worth using and which are better to pass on?",[133,1127,1128,1133,1137],{},[136,1129,1132],{"icon":1130,"title":1131},"i-lucide-crosshair","1. The problem","Choosing the right package starts with knowing what problem you are trying to solve.",[136,1134,1136],{"icon":71,"title":1135},"2. The platforms","Determining the platform(s) you will be targeting with your application.",[136,1138,1141],{"icon":1139,"title":1140},"i-lucide-badge-check","3. The quality","Arguably the most important consideration: likes, popularity, and Pub Points.",[378,1143,1145],{"id":1144},"the-problem","The problem",[121,1147,1148],{},"In fact, there is very little (if anything) that you cannot accomplish on your own by using a package from Pub. However, the aim is to save development time and rely on the experience of others to provide value.",[121,1150,1151],{},"Not all packages on Pub provide widgets that will be drawn to the screen. In fact, many packages on Pub offer features that are more abstract, such as widgets that help with state management, interface with databases and other services, or make sharing content to other applications easier. Also, many, many other things that would just be time-consuming to write from scratch every time you need to do something that the Flutter framework does not immediately provide to you.",[348,1153,1154,1155,1158],{},"It is important to pick a package that is ",[111,1156,1157],{},"suitable for the problem"," you are trying to solve, so ensure that you take the time to consider this carefully.",[378,1160,1162],{"id":1161},"the-platforms","The platforms",[121,1164,1165,1166,1169],{},"As previously mentioned, many packages are only available for ",[116,1167,1168],{},"some"," of the available platforms that Flutter is capable of building for. Furthermore, some packages implement features that might not make sense for all platforms.",[317,1171,1172,1173,1176],{},"If you are building an application that targets the Web, it does not make sense to use a package that implements the ability to report app crashes to Google's Firebase Crashlytics. (In fact, the package available on Pub to do this, ",[174,1174,1175],{},"firebase_crashlytics",", doesn't have support for web, at all, nor does it have support for Windows, at least as of the time of writing.)",[378,1178,1180],{"id":1179},"the-quality","The quality",[121,1182,1183,1184,1187],{},"Finally, and arguably the most important consideration, is the ",[116,1185,1186],{},"quality"," of the package. There are three broad metrics by which you can judge the quality of a package: likes, popularity, and Pub Points.",[133,1189,1190,1202,1206],{},[136,1191,1194,1195,1198,1199,202],{"icon":1192,"title":1193},"i-lucide-thumbs-up","Likes","A simple enumeration of how many developers have logged into Pub and pressed the thumbs-up button next to a package. Were you to do the same, you could find your list of liked packages under the ",[174,1196,1197],{},"My pub.dev"," menu at the top of the page, then by navigating to ",[116,1200,1201],{},"likes",[136,1203,1205],{"icon":31,"title":1204},"Popularity","Currently, this is a measure of the number of apps that depend on the given packages over the past 60 days, measured by download count (and adjusted for automatic downloads, such as with build tools), and displayed as a percent from 0% (the least used package) to 100% (the most used package.) This metric's calculation is bound to change once the team has completed work on measuring absolute usage counts, however that is not currently the case as of the time of writing.",[136,1207,1210,1211,1214],{"icon":1208,"title":1209},"i-lucide-award","Pub Points","Alongside the popularity metric, this is arguably the most useful metric. Unlike the other metrics, this value is ",[111,1212,1213],{},"automatically calculated"," and cannot be directly influenced by the number of people liking or using the package.",[317,1216,1217,1219],{},[111,1218,321],{}," the popularity percentage has since been replaced. pub.dev now scores packages on \"Likes\", \"Pub Points\", and \"Download count\", the last being \"A measure of how often a package is downloaded, providing insight into what other developers are using\" that \"should only be regarded as an indicator of popularity\" (pub.dev, n.d.-a).",[121,1221,1222,1223,1228],{},"There are many checks which are done automatically on a package to determine its Pub Points by a tool called ",[111,1224,1225],{},[174,1226,1227],{},"pana",". Pana automatically evaluates the quality of the package by looking at a multitude of criteria within several categories, then scoring each category independently before producing a total number (which, at the time of writing, is out of 140 possible points). The criteria for how these points are awarded, at least at the time of writing, are as follows:",[259,1230,1231,1257,1273,1276,1281,1284],{},[262,1232,1235],{"name":1233,"type":1234},"Follow Dart file conventions","30 points total",[141,1236,1237,1243,1249,1254],{},[144,1238,1239,1240,1242],{},"Provide a valid ",[174,1241,176],{}," (10 points)",[144,1244,1239,1245,1248],{},[174,1246,1247],{},"README.md"," (5 points)",[144,1250,1239,1251,1248],{},[174,1252,1253],{},"CHANGELOG.md",[144,1255,1256],{},"Use an OSI-approved license (10 points)",[262,1258,1261],{"name":1259,"type":1260},"Provide documentation","20 points",[141,1262,1263,1266],{},[144,1264,1265],{},"Provide an example usage of the package (10 points)",[144,1267,1268,1269,1272],{},"20% or more of the public API has ",[174,1270,1271],{},"dartdoc"," comments (10 points)",[262,1274],{"name":1275,"type":1260},"Provide support for all 6 platforms",[262,1277,1280],{"name":1278,"type":1279},"Pass static analysis","30 points","Code has no errors, warnings, lints, or formatting issues.",[262,1282],{"name":1283,"type":1260},"Support up-to-date dependencies",[262,1285],{"name":1286,"type":1260},"Dart 3 and Flutter 3.10 compatibility",[317,1288,1289,1291,1292,219,1294,219,1296,1299,1300,1303,1304,240,1306,1308],{},[111,1290,321],{}," pub.dev's scoring help no longer publishes a total or a point value per check. It says \"Pub points are awarded in six categories\", lists the checks under ",[116,1293,1233],{},[116,1295,1259],{},[116,1297,1298],{},"Platform support"," (including ",[116,1301,1302],{},"Support modern toolchains"," such as Swift Package Manager and Wasm), ",[116,1305,1278],{},[116,1307,1283],{}," (the latest stable Dart SDK, Flutter SDK and dependencies), and has no separate Dart 3 \u002F Flutter 3.10 check (pub.dev, n.d.-a).",[348,1310,1311,1312,1315],{},"Given the rigorous criteria by which Pub Points are calculated, it should come as no surprise that Pub Points are one of the ",[111,1313,1314],{},"easiest ways to determine the overall quality"," of any given package.",[187,1317,1318,1319,1322,1323,1326],{},"Finally, it is always an excellent idea to ",[111,1320,1321],{},"read the package description thoroughly",". There have certainly been times when a package was developed to overcome a shortcoming in Dart or Flutter, then later that shortcoming was remedied, making the package obsolete. An excellent example of this is the ",[174,1324,1325],{},"supercharged"," package.",[128,1328,158],{"id":1329},"using-a-package-to-play-audio",[121,1331,1332],{},"Now that we have a firm grasp of what a package is, where to find them, and how to evaluate them for quality before depending on them in our application, let us loop back to the earlier example of finding and using a package to play audio.",[121,1334,1335,1336,1339],{},"As we discussed earlier, Flutter does not (natively) support playing audio, so using a package is the easiest way to add this functionality. Any package we use will have ",[111,1337,1338],{},"platform-specific code"," for each supported platform which does the heavy lifting of playing audio. There will also be a widget (or perhaps several) which will enable us to choose what audio to play and control the playback.",[378,1341,1343],{"id":1342},"searching-pub-for-audio","Searching Pub for audio",[121,1345,1346,1347,1350,1351,1356],{},"By searching for ",[116,1348,1349],{},"audio"," on ",[111,1352,1353],{},[197,1354,784],{"href":784,"rel":1355},[201],", we are presented with several options.",[317,1358,1359],{},"One thing to note is that these results are certainly outdated from the time of writing to the time you are reading this. Many of these packages may have been updated in the intervening time. Your results are almost certain to be different than those listed here.",[121,1361,1362,1363,219,1365,219,1368,219,1371,219,1374,219,1377,240,1380,1383,1384,1386,1387,1390],{},"Generally speaking you will probably notice the packages ",[174,1364,1349],{},[174,1366,1367],{},"dart:web_audio",[174,1369,1370],{},"dart:html",[174,1372,1373],{},"material",[174,1375,1376],{},"flutter_sound",[174,1378,1379],{},"flutter_widget_from_html",[174,1381,1382],{},"just_audio",", which is what we will be focusing on for our example. Let us start by looking at the ",[174,1385,1349],{}," package (",[116,1388,1389],{},"figure 6.1","):",[121,1392,1393],{},[1394,1395],"img",{"alt":1396,"src":1397},"Figure 6.1: The pub.dev search result listing for the audio package","\u002Fimages\u002Fflutter-for-jobseekers\u002Ffigure-6-1.png",[1399,1400,1401],"blockquote",{},[121,1402,1403],{},"Figure 6.1: The pub.dev search result listing for the audio package.",[985,1405,1406,1407,1410],{},"This package has very few likes, a very low number of Pub Points, and relatively weak popularity. Also note the last update was version 0.0.5, which was released four years prior. In addition, Pub cannot determine which platforms this package will run on. Finally, there's no Dart 3 compatibility. Given all these elements together, it's a safe bet that this package is ",[111,1408,1409],{},"not a good choice"," for our application.",[121,1412,1413,1414,600],{},"Let us look at the next set of results; refer to ",[116,1415,1416],{},"figure 6.2",[121,1418,1419],{},[1394,1420],{"alt":1421,"src":1422},"Figure 6.2: More search results for the query \"audio\" on pub.dev","\u002Fimages\u002Fflutter-for-jobseekers\u002Ffigure-6-2.png",[1399,1424,1425],{},[121,1426,1427],{},"Figure 6.2: More search results for the query \"audio\" on pub.dev.",[133,1429,1430,1439,1447],{},[136,1431,1434,1435,1438],{"icon":1432,"title":1433},"i-lucide-library","Core libraries","The top three are ",[116,1436,1437],{},"core libraries",", meaning that they are built-in to the Flutter framework or Dart itself. Since we know that Flutter (and Dart) are incapable of playing audio, we can safely ignore them.",[136,1440,1442,1443,1446],{"icon":1441,"title":1376},"i-lucide-audio-lines","This package has a huge number of likes, a maximum number of Pub Points, and an excellent popularity rating. Additionally, it supports the Web and mobile platforms and works with Dart 3. This would be an ",[111,1444,1445],{},"excellent choice",", so let us add it to our list of potential solutions and keep looking.",[136,1448,1450,1451,202],{"icon":1449,"title":1379},"i-lucide-code-xml","Sounds like it will render HTML code as Flutter widgets, which does not match what we are looking for. Despite the rest of the stats looking good, it ",[111,1452,1453],{},"will not solve our problem",[121,1455,1456,1457,1390],{},"There are several more search results on the page, and several pages of search results in total. However, the very next search result looks promising (",[116,1458,1459],{},"figure 6.3",[121,1461,1462],{},[1394,1463],{"alt":1464,"src":1465},"Figure 6.3: The pub.dev search result listing for the just_audio package","\u002Fimages\u002Fflutter-for-jobseekers\u002Ffigure-6-3.png",[1399,1467,1468],{},[121,1469,1470],{},"Figure 6.3: The pub.dev search result listing for the just_audio package.",[348,1472,1473,1474,1476,1477,1479,1480,1483,1484,1490,1491,1493,1494,1496],{},"The ",[174,1475,1382],{}," package, like the ",[174,1478,1376],{}," package, has the maximum number of Pub Points, was updated within the past couple of days, supports Dart 3, and has an incredibly popular rating. Where it sets itself apart is the ",[111,1481,1482],{},"enormous number of likes"," and the ",[111,1485,1486,1489],{},[116,1487,1488],{},"Flutter Favorite"," badge",". Good thing we did not stop looking when we found ",[174,1492,1376],{},", because ",[174,1495,1382],{}," looks like it is an even better choice!",[378,1498,1500],{"id":1499},"the-package-page","The package page",[121,1502,1503,1504,1507,1508,202],{},"Now that we have found the package we want to use, let us explore it a bit further. To start, let us look at the package page (as shown in ",[116,1505,1506],{},"figure 6.4","). You can find this on your own by navigating to ",[111,1509,1510],{},[197,1511,1512],{"href":1512,"rel":1513},"https:\u002F\u002Fpub.dev\u002Fpackages\u002Fjust_audio",[201],[121,1515,1516,1517,1520],{},"Here, we can find a slew of useful information about the package. At the top, we see the package name and current version. (There is even a handy ",[111,1518,1519],{},"copy icon"," next to the version, which will copy the line we need to paste into our pubspec!). It tells us the last time the version was updated, the developer, and all the useful bits about Dart 3 support, being a Flutter Favorite, the supported platforms, and so on:",[121,1522,1523],{},[1394,1524],{"alt":1525,"src":1526},"Figure 6.4: The package details page for the just_audio package on pub.dev","\u002Fimages\u002Fflutter-for-jobseekers\u002Ffigure-6-4.png",[1399,1528,1529],{},[121,1530,1531],{},"Figure 6.4: The package details page for the just_audio package on pub.dev.",[121,1533,1534],{},"The tabbed view below defaults to the package's readme, which has even more useful information:",[259,1536,1537,1542,1546,1550,1554,1558],{},[262,1538,1541],{"name":1539,"type":1540},"Readme","tab","If you scroll down, you will even see some examples detailing exactly how to use it in the application.",[262,1543,1545],{"name":1544,"type":1540},"Changelog","Details all the changes made in each version that has been released.",[262,1547,1549],{"name":1548,"type":1540},"Example","Has a complete working example that you could copy\u002Fpaste into your application.",[262,1551,1553],{"name":1552,"type":1540},"Installing","Tells you how to add it as a dependency in your code.",[262,1555,1557],{"name":1556,"type":1540},"Versions","A useful way to download a copy of any given version (or see the documentation for said version).",[262,1559,1561],{"name":1560,"type":1540},"Scores","Breaks down the Pub Points calculation to see exactly what points were awarded for.",[121,1563,1564,1565,1568,1569,1572,1573,1575],{},"Other useful information on this page can be found on the ",[111,1566,1567],{},"right sidebar",", where you can see links to the homepage, GitHub repository (in case you would like to browse the source code), and a place to see\u002Freport any issues with the package. There is also a complete ",[111,1570,1571],{},"API reference",", which covers the entirety of the package and how to use every aspect of it (although, in the case of ",[174,1574,1382],{},", the relevant information is on the readme tab, so the API reference simply displays this information.)",[378,1577,1579],{"id":1578},"try-it-yourself","Try it yourself",[348,1581,1582,1583,1586,1587,1589],{},"Normally, this is where we would go step-by-step over how to add this package to your application and start using it. This time, however, why not try following the instructions on the ",[116,1584,1585],{},"installing"," tab, then use the example to get it up and running on your own? After all, this is often the process you will need to follow when you are out there building apps. (Plus, you have got this!) Do not forget to run ",[174,1588,1004],{}," once you have added the dependency!",[128,1591,161],{"id":1592},"popular-pub-packages",[121,1594,1595,1596,880,1599,1602,1603,1606,1607,1610],{},"There is no shortage of packages on Pub. Sometimes the most difficult part of choosing a package is even knowing what is even available and what other people are using to solve problems. If you have already visited pub.dev, you will no doubt have noticed the ",[116,1597,1598],{},"most popular packages",[116,1600,1601],{},"top Flutter packages"," sections on the home screen (",[116,1604,1605],{},"figure 6.5","). (There is also a ",[116,1608,1609],{},"top Dart packages"," section if you are looking for something specific to Dart.)",[121,1612,1613],{},"This is an excellent place to start browsing packages that other developers are commonly using. Sometimes inspiration for a new application or feature can come from just browsing these lists. You might even discover a solution to a problem you did not know you were having!",[121,1615,1616],{},[1394,1617],{"alt":1618,"src":1619},"Figure 6.5: Popular packages on pub.dev","\u002Fimages\u002Fflutter-for-jobseekers\u002Ffigure-6-5.png",[1399,1621,1622],{},[121,1623,1624],{},"Figure 6.5: Popular packages on pub.dev.",[121,1626,1627],{},"Let us look at a couple of the most popular packages to understand what problems other developers are trying to solve.",[378,1629,1630],{"id":1630},"shared_preferences",[121,1632,1633,1634,1637,1638,1640],{},"Have you ever thought it might be useful to store some user data on the device? Maybe you are storing the user's preference for a light\u002Fdark mode. Perhaps you want to keep track of how many times they have opened the application. Maybe you want to store user-generated content (such as a list of items) so that it is available next time the app is launched. If you have answered ",[116,1635,1636],{},"yes"," to any of these questions, look no further than ",[174,1639,1630],{},"!",[121,1642,1643,1644,1646,1647,1650],{},"With ",[174,1645,1630],{},", you can store ",[111,1648,1649],{},"integers, Booleans, doubles, strings, and lists of strings"," to a user's device with ease. Then, you can easily recall those values later. It works on all platforms that Flutter can target.",[187,1652,1653,1654,1657,1658,1660],{},"Beware that the data is ",[111,1655,1656],{},"stored locally on the device"," — if you build an application that uses ",[174,1659,1630],{},", do not expect the same data to be available on multiple devices that the user uses.",[378,1662,1663],{"id":1663},"url_launcher",[121,1665,1666,1667,1669],{},"If you want to have a tappable email address which automatically launches the user's email client and pre-fills the to, subject, and body lines, look no further than ",[174,1668,1663],{},"! Why stop at emails, though?",[133,1671,1672,1677,1682,1687,1692],{},[136,1673,1676],{"icon":1674,"title":1675},"i-lucide-mail","Email","Launch the email client with the to, subject, and body lines pre-filled.",[136,1678,1681],{"icon":1679,"title":1680},"i-lucide-globe","Website","You could launch a website.",[136,1683,1686],{"icon":1684,"title":1685},"i-lucide-phone","Phone","Automatically enter a phone number into the user's default phone application so all they need to do is press call.",[136,1688,1691],{"icon":1689,"title":1690},"i-lucide-message-square","SMS","Initiate an SMS conversation.",[136,1693,1696],{"icon":1694,"title":1695},"i-lucide-file","File","Or even open a file.",[121,1698,1699,1700,1703],{},"All of this is possible on ",[111,1701,1702],{},"every platform"," that Flutter targets.",[378,1705,1706],{"id":1706},"dio",[121,1708,1709,1710,1712],{},"The default HTTP client that comes with Dart is usually good enough for most tasks. However, there are times when you need to do something that the built-in client just cannot handle. This is where ",[174,1711,1706],{}," comes to the rescue!",[133,1714,1715,1723],{},[136,1716,1719,1720,1722],{"icon":1717,"title":1718},"i-lucide-settings","Global settings","Use ",[174,1721,1706],{}," to configure global settings for all HTTP connections made within your application, such as setting an authorization header.",[136,1724,1726,1727,1730],{"icon":76,"title":1725},"Interceptors","Want access to better debug logging to see what requests and responses are being made more easily? Try using an interceptor! (Write your own ",[116,1728,1729],{},"or"," find a package that does it for you!)",[121,1732,1733],{},"If for whatever reason you find that Dart's HTTP client is not quite doing the trick, look at Dio. You will be glad you did.",[378,1735,1736],{"id":1736},"flutter_bloc",[121,1738,1739,1740,1743],{},"Stateful widgets can only get you so far in life. The minute a stateful widget is disposed of ",[111,1741,1742],{},"the state is lost",". That might be fine for some use cases, but other times you might need to save that state. You could be building a list\u002Fdetails application. When viewing the details, you have got the option to update the title. Save the changes by passing the updated details to a BLoC, and the list will rebuild automatically.",[121,1745,1746,1747,1750],{},"A lot of business logic can be moved outside the widget's build method by using a BLoC, as well. By leveraging the ",[111,1748,1749],{},"event-driven"," nature of the BLoC, you can send an event to the BLoC (sometimes with parameters), allow the BLoC to do the heavy lifting, and then the BLoC will return a given state. That state can be used to build your widget in a different way. For example:",[548,1752,1753,1757,1764,1768,1771,1775,1786,1790],{"level":550},[552,1754,1756],{"id":1755},"send-an-event","Send an event",[121,1758,1759,1760,1763],{},"Sending an event of ",[116,1761,1762],{},"load all the things"," to the bloc would trigger the BLoC to reach out to an API and acquire some data.",[552,1765,1767],{"id":1766},"process-the-data","Process the data",[121,1769,1770],{},"Then, the data would be processed.",[552,1772,1774],{"id":1773},"return-a-state","Return a state",[121,1776,1777,1778,1781,1782,1785],{},"If successful, a state of ",[116,1779,1780],{},"all good!"," could be sent back; otherwise a state of ",[116,1783,1784],{},"that did not quite work out"," could be sent instead.",[552,1787,1789],{"id":1788},"build-the-widget","Build the widget",[121,1791,1792],{},"When the widget is built, it could check for the success\u002Ffailure states and either return the details of the response or an error message.",[121,1794,1795,1796,1798,1799,202],{},"And we are only scratching the surface of what ",[174,1797,1736],{}," can do! In fact, we are going to discuss it in-depth in ",[116,1800,1801],{},"Chapter 9: State Management and the BLoC",[378,1803,1804],{"id":1804},"isar",[121,1806,1807,1808,1810,1811,1813,1814,1817,1818,1820,1821,1640],{},"If you have found yourself using ",[174,1809,1630],{}," and realizing the limitations of what you are able to store and how you can retrieve it, you need ",[174,1812,1804],{},". This package is an easy-to-use ",[111,1815,1816],{},"NoSQL database"," for storing and retrieving any type of data imaginable. It is easy to use, fast, and has excellent documentation. The limitations of ",[174,1819,1630],{}," are a thing of the past with ",[174,1822,1804],{},[317,1824,1825,1827,1828,1830,1831,1834],{},[111,1826,321],{}," check ",[174,1829,1804],{},"'s maintenance before depending on it. When this page was written (November 2026), its latest stable version on pub.dev, 3.1.0+1, had been published three years earlier, with only ",[174,1832,1833],{},"4.0.0-dev"," prereleases after it (pub.dev, n.d.-b).",[378,1836,1838],{"id":1837},"package-of-the-week","Package of the Week",[121,1840,1841],{},"This is just a small sampling of some of the more popular packages which can be found on Pub.",[348,1843,1844,1845,1849,1850,1853],{},"The Flutter team has a ",[116,1846,1847],{},[111,1848,1838],{}," playlist on YouTube (see the ",[116,1851,1852],{},"Further reading"," section at the end of the chapter) in which they choose a package from Pub each week and give a brief overview of the problem that the package seeks to solve, then show an example of it in action. They are short videos, and you are highly encouraged to check out the playlist!",[128,1855,1857],{"id":1856},"conclusion","Conclusion",[121,1859,1860,1861,1863],{},"We have covered a lot of ground in this chapter. By now, you know what ",[174,1862,176],{}," is and how to use it to add packages and resources to your application. You learned how to find and evaluate the quality of packages using Pub, the package manager for Flutter and Dart, and pub.dev, the website where all the available packages can be found. Then, we learned how to make our application play sounds. Finally, we explored a small selection of some popular packages that many developers come back to time and time again.",[121,1865,1866],{},"How are you feeling about all this new information? If you are overwhelmed, that is perfectly okay. Take a break, stretch, drink some water, and come back to it when you are ready. Or are you feeling confident that you are really starting to get a good grasp on Flutter? That is great!",[317,1868,1869,1870,1873,1874,1877],{},"We have almost all the tools we need to start building our first application. There are just a couple more concepts we need to learn before we can start digging into building something from scratch. Next up, we are going to explore the concept of ",[111,1871,1872],{},"asynchronous operations"," and use them to communicate with an API. So, whenever you are ready, let's ",[174,1875,1876],{},"async await"," some new concepts!",[128,1879,1881],{"id":1880},"questions","Questions",[1883,1884,1885,1891,1897,1903,1909,1912,1915,1918,1921,1924,1927,1930,1933,1936],"ol",{},[144,1886,1887,1888,1890],{},"What is ",[174,1889,176],{}," used for?",[144,1892,1893,1894,1896],{},"What language is ",[174,1895,176],{}," written in?",[144,1898,1899,1900,1902],{},"What are the required directives for Flutter in ",[174,1901,176],{},", and what do they do?",[144,1904,1905,1906,1908],{},"How do you update the package versions in ",[174,1907,176],{}," with a single command?",[144,1910,1911],{},"How do you add images, fonts, sounds, or other assets to your application?",[144,1913,1914],{},"What is Pub?",[144,1916,1917],{},"How does dependency version pinning work?",[144,1919,1920],{},"Where can one browse a list of packages that are available to add to a Flutter or Dart project?",[144,1922,1923],{},"What are Pub Points and how are they calculated?",[144,1925,1926],{},"How can one save a list of their favorite packages on Pub?",[144,1928,1929],{},"How can you play audio in your Flutter application?",[144,1931,1932],{},"Where can you find a list of popular Flutter and Dart packages?",[144,1934,1935],{},"What are some ways in which data can be persisted across app launches?",[144,1937,1938],{},"What YouTube playlist does the Flutter team use to showcase popular packages?",[128,1940,1942],{"id":1941},"key-terms","Key terms",[259,1944,1945,1949,1953,1957,1960],{},[262,1946,1948],{"name":1947},"Asset","Any file which is included with a project, such as an image or font.",[262,1950,1952],{"name":1951},"Pana","The tool used to automatically calculate the number of Pub Points a given package has earned.",[262,1954,1956],{"name":1955},"Pub","The package ecosystem for Flutter and Dart.",[262,1958,1959],{"name":176},"The configuration file for a Flutter or Dart project which includes useful items such as the package name and description, the version of Dart used by the project, and any dependencies the project may have.",[262,1961,1963,1964,1966],{"name":1962},"Pub points","A number generated by ",[174,1965,1227],{},", which is used to loosely determine the quality of a given package.",[128,1968,1970],{"id":1969},"command-reference","Command reference",[259,1972,1973,1976,1979,1985,1989,1995],{},[262,1974,1975],{"name":1104},"Removes all cached packages, globally.",[262,1977,1978],{"name":1111},"Re-downloads all cached packages, globally.",[262,1980,1981,1982,1984],{"name":1004},"Downloads all of the packages specified in the ",[174,1983,176],{}," file and caches them locally for use in your application.",[262,1986,1988],{"name":1987},"flutter pub outdated (--major-versions)","Lists out-of-date dependencies.",[262,1990,1991,1992,1994],{"name":1061},"Updates ",[174,1993,176],{}," with the newest available versions of packages within their allowed version ranges.",[262,1996,1991,1997,1999],{"name":1065},[174,1998,176],{}," with the newest available versions of packages, even if those new versions have a version available outside of the allowed version ranges.",[317,2001,2002,2004,2005,2007,2008,2011,2012,2014,2015,2018,2019,2021,2022,2025,2026,2028,2029,219,2032,219,2035,219,2038,219,2041,880,2044,2047],{},[111,2003,321],{}," plain ",[174,2006,1061],{}," resolves the newest allowed versions and writes them to the lockfile (\"it writes a lockfile to ensure that ",[174,2009,2010],{},"dart pub get"," will use the same versions\"); it leaves the constraints in ",[174,2013,176],{}," as they are. Only ",[174,2016,2017],{},"--major-versions"," \"Also updates ",[174,2020,176],{}," with the new constraints\" (Dart, n.d.-c). The ",[174,2023,2024],{},"pub outdated"," reference lists no ",[174,2027,2017],{}," option; its options are ",[174,2030,2031],{},"--[no-]dependency-overrides",[174,2033,2034],{},"--[no-]dev-dependencies",[174,2036,2037],{},"--json",[174,2039,2040],{},"--[no-]prereleases",[174,2042,2043],{},"--[no-]transitive",[174,2045,2046],{},"--[no-]up-to-date"," (Dart, n.d.-d).",[128,2049,1852],{"id":2050},"further-reading",[133,2052,2053,2063,2069],{},[136,2054,2059,2060,2062],{"icon":2055,"title":2056,"target":2057,"to":2058},"i-simple-icons-youtube","Flutter Package of the Week","_blank","https:\u002F\u002Fwww.youtube.com\u002Fplaylist?list=PLjxrf2q8roU1quF6ny8oFHJ2gBdrYN_AK","Check out the Flutter team's ",[116,2061,2056],{}," playlist on YouTube.",[136,2064,2068],{"icon":2065,"title":2066,"target":2057,"to":2067},"i-lucide-git-branch","Package versioning","https:\u002F\u002Fdart.dev\u002Ftools\u002Fpub\u002Fversioning","Learn more about package versioning.",[136,2070,2072],{"icon":1208,"title":1209,"target":2057,"to":2071},"https:\u002F\u002Fpub.dev\u002Fhelp\u002Fscoring#pub-points","Learn more about how Pub Points are calculated.",[128,2074,2076],{"id":2075},"references","References",[141,2078,2079,2094,2106,2118,2130,2143,2156],{},[144,2080,2081,2082,2085,2086,2090,2091],{},"Dart. (n.d.-a). ",[116,2083,2084],{},"The pubspec file",". Retrieved from Dart: ",[197,2087,2088],{"href":2088,"rel":2089},"https:\u002F\u002Fdart.dev\u002Ftools\u002Fpub\u002Fpubspec",[201]," ",[116,2092,2093],{},"(added, not in the book)",[144,2095,2096,2097,2085,2100,2090,2104],{},"Dart. (n.d.-b). ",[116,2098,2099],{},"Package dependencies",[197,2101,2102],{"href":2102,"rel":2103},"https:\u002F\u002Fdart.dev\u002Ftools\u002Fpub\u002Fdependencies",[201],[116,2105,2093],{},[144,2107,2108,2109,2085,2112,2090,2116],{},"Dart. (n.d.-c). ",[116,2110,2111],{},"dart pub upgrade",[197,2113,2114],{"href":2114,"rel":2115},"https:\u002F\u002Fdart.dev\u002Ftools\u002Fpub\u002Fcmd\u002Fpub-upgrade",[201],[116,2117,2093],{},[144,2119,2120,2121,2085,2124,2090,2128],{},"Dart. (n.d.-d). ",[116,2122,2123],{},"dart pub outdated",[197,2125,2126],{"href":2126,"rel":2127},"https:\u002F\u002Fdart.dev\u002Ftools\u002Fpub\u002Fcmd\u002Fpub-outdated",[201],[116,2129,2093],{},[144,2131,2132,2133,2136,2137,2090,2141],{},"Flutter. (n.d.). ",[116,2134,2135],{},"Adding assets and images",". Retrieved from Flutter: ",[197,2138,2139],{"href":2139,"rel":2140},"https:\u002F\u002Fdocs.flutter.dev\u002Fui\u002Fassets\u002Fassets-and-images",[201],[116,2142,2093],{},[144,2144,2145,2146,2149,2150,2090,2154],{},"pub.dev. (n.d.-a). ",[116,2147,2148],{},"Scoring",". Retrieved from pub.dev: ",[197,2151,2152],{"href":2152,"rel":2153},"https:\u002F\u002Fpub.dev\u002Fhelp\u002Fscoring",[201],[116,2155,2093],{},[144,2157,2158,2159,2149,2161,2090,2165],{},"pub.dev. (n.d.-b). ",[116,2160,1804],{},[197,2162,2163],{"href":2163,"rel":2164},"https:\u002F\u002Fpub.dev\u002Fpackages\u002Fisar",[201],[116,2166,2093],{},[2168,2169,2170],"style",{},"html .light .shiki span {color: var(--shiki-light);background: var(--shiki-light-bg);font-style: var(--shiki-light-font-style);font-weight: var(--shiki-light-font-weight);text-decoration: var(--shiki-light-text-decoration);}html.light .shiki span {color: var(--shiki-light);background: var(--shiki-light-bg);font-style: var(--shiki-light-font-style);font-weight: var(--shiki-light-font-weight);text-decoration: var(--shiki-light-text-decoration);}html .default .shiki span {color: var(--shiki-default);background: var(--shiki-default-bg);font-style: var(--shiki-default-font-style);font-weight: var(--shiki-default-font-weight);text-decoration: var(--shiki-default-text-decoration);}html .shiki span {color: var(--shiki-default);background: var(--shiki-default-bg);font-style: var(--shiki-default-font-style);font-weight: var(--shiki-default-font-weight);text-decoration: var(--shiki-default-text-decoration);}html .dark .shiki span {color: var(--shiki-dark);background: var(--shiki-dark-bg);font-style: var(--shiki-dark-font-style);font-weight: var(--shiki-dark-font-weight);text-decoration: var(--shiki-dark-text-decoration);}html.dark .shiki span {color: var(--shiki-dark);background: var(--shiki-dark-bg);font-style: var(--shiki-dark-font-style);font-weight: var(--shiki-dark-font-weight);text-decoration: var(--shiki-dark-text-decoration);}html pre.shiki code .swJcz, html code.shiki .swJcz{--shiki-light:#E53935;--shiki-default:#F07178;--shiki-dark:#F07178}html pre.shiki code .sMK4o, html code.shiki .sMK4o{--shiki-light:#39ADB5;--shiki-default:#89DDFF;--shiki-dark:#89DDFF}html pre.shiki code .sfazB, html code.shiki .sfazB{--shiki-light:#91B859;--shiki-default:#C3E88D;--shiki-dark:#C3E88D}html pre.shiki code .sHwdD, html code.shiki .sHwdD{--shiki-light:#90A4AE;--shiki-light-font-style:italic;--shiki-default:#546E7A;--shiki-default-font-style:italic;--shiki-dark:#676E95;--shiki-dark-font-style:italic}html pre.shiki code .sbssI, html code.shiki .sbssI{--shiki-light:#F76D47;--shiki-default:#F78C6C;--shiki-dark:#F78C6C}html pre.shiki code .sBMFI, html code.shiki .sBMFI{--shiki-light:#E2931D;--shiki-default:#FFCB6B;--shiki-dark:#FFCB6B}",{"title":106,"searchDepth":427,"depth":427,"links":2172},[2173,2174,2175,2180,2187,2192,2197,2205,2206,2207,2208,2209,2210],{"id":130,"depth":427,"text":131},{"id":169,"depth":427,"text":146},{"id":363,"depth":427,"text":149,"children":2176},[2177,2178,2179],{"id":380,"depth":435,"text":381},{"id":542,"depth":435,"text":543},{"id":755,"depth":435,"text":756},{"id":769,"depth":427,"text":152,"children":2181},[2182,2183,2184,2185,2186],{"id":789,"depth":435,"text":790},{"id":898,"depth":435,"text":899},{"id":997,"depth":435,"text":998},{"id":1051,"depth":435,"text":1052},{"id":1094,"depth":435,"text":1095},{"id":1122,"depth":427,"text":155,"children":2188},[2189,2190,2191],{"id":1144,"depth":435,"text":1145},{"id":1161,"depth":435,"text":1162},{"id":1179,"depth":435,"text":1180},{"id":1329,"depth":427,"text":158,"children":2193},[2194,2195,2196],{"id":1342,"depth":435,"text":1343},{"id":1499,"depth":435,"text":1500},{"id":1578,"depth":435,"text":1579},{"id":1592,"depth":427,"text":161,"children":2198},[2199,2200,2201,2202,2203,2204],{"id":1630,"depth":435,"text":1630},{"id":1663,"depth":435,"text":1663},{"id":1706,"depth":435,"text":1706},{"id":1736,"depth":435,"text":1736},{"id":1804,"depth":435,"text":1804},{"id":1837,"depth":435,"text":1838},{"id":1856,"depth":427,"text":1857},{"id":1880,"depth":427,"text":1881},{"id":1941,"depth":427,"text":1942},{"id":1969,"depth":427,"text":1970},{"id":2050,"depth":427,"text":1852},{"id":2075,"depth":427,"text":2076},"The pubspec.yaml file, adding images and fonts as assets, the Pub package ecosystem, judging package quality, playing audio with a package, and popular packages.","md",null,{},{"icon":51},{"title":48,"description":2211},"sR7J49q8r_s-wFU_uxPOGAoYNs8vLPalE1vRj1sUMPk",[2219,2221],{"title":43,"path":44,"stem":45,"description":2220,"icon":46,"children":-1},"Buttons, text fields, pickers, radios, checkboxes, switches and sliders in Material and Cupertino, plus validating and submitting input with a Form.",{"title":53,"path":54,"stem":55,"description":2222,"icon":56,"children":-1},"Futures and async\u002Fawait, requesting and sending data with the http package, turning JSON into Dart classes, FutureBuilder and StreamBuilder, and sinks and streams.",1795696849864]