<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0" xmlns:atom="http://www.w3.org/2005/Atom" xmlns:dc="http://purl.org/dc/elements/1.1/">
  <channel>
    <title>DEV Community: Carl Wills</title>
    <description>The latest articles on DEV Community by Carl Wills (@carlmobiledev).</description>
    <link>https://dev.to/carlmobiledev</link>
    <image>
      <url>https://media2.dev.to/dynamic/image/width=90,height=90,fit=cover,gravity=auto,format=auto/https:%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Fuser%2Fprofile_image%2F614547%2F5fa6fa1c-0e0b-4eee-a4ce-d457067b0415.jpg</url>
      <title>DEV Community: Carl Wills</title>
      <link>https://dev.to/carlmobiledev</link>
    </image>
    <atom:link rel="self" type="application/rss+xml" href="https://dev.to/feed/carlmobiledev"/>
    <language>en</language>
    <item>
      <title>5 things to do when NOT writing code...</title>
      <dc:creator>Carl Wills</dc:creator>
      <pubDate>Thu, 17 Jun 2021 21:38:24 +0000</pubDate>
      <link>https://dev.to/carlmobiledev/5-things-to-do-when-not-writing-code-5fmp</link>
      <guid>https://dev.to/carlmobiledev/5-things-to-do-when-not-writing-code-5fmp</guid>
      <description>&lt;p&gt;As programmers, we love to code! That's what we do, and it's a big part of our lives. But it's not all that we do, and it's not all that we &lt;em&gt;should&lt;/em&gt; do as coders. Here are five things that I think everybody that writes code should do when they are not coding to keep themselves sharp and to continue learning.&lt;/p&gt;

&lt;h3&gt;
  
  
  1. Talk about code
&lt;/h3&gt;

&lt;p&gt;Yes! Talk about code, frameworks, libraries, algorithms, anything that helps you learn more about what you are working on. I think as programmers we often get caught up in the typing of code and lose our skills in other ways to communicate about it. One of the most important skills in our toolset is being able to communicate and explain technology, code, or high level strategy that we are using when solving complex problems. Talking about code helps enforce these skills and even helps us figure out which topics we need to brush up on.&lt;/p&gt;

&lt;h3&gt;
  
  
  2. Look at code other people wrote
&lt;/h3&gt;

&lt;p&gt;There's soooo many benefits to reading other people's code. Everybody has small little intricate differences when they write code that can be fun to explore and enhance your understanding of how the language works. You might notice some cool new functions you've never noticed before. You may stumble on a pattern that they use that you could easily implement into your project to make it cleaner or more simple. You may even find some mistakes! Reading code other people wrote is a great exercise in checking your level of understanding. It's not easy to jump into a new repository and start understanding what's going on, but by taking some time to explore unknown territory, you'll pick up on a lot!&lt;/p&gt;

&lt;h3&gt;
  
  
  3. Read
&lt;/h3&gt;

&lt;p&gt;Read a book, I dare you! You might even enjoy it! Many programmers enjoy doing what they do because it is a very focused, heavy brain-power job. If that's you, &lt;em&gt;or if you simply like a good story&lt;/em&gt; pick up a book and give it a read. You'll find that doing a quiet solitary task can be really refreshing, especially with all the video calls we are all on &lt;strong&gt;constantly&lt;/strong&gt;. &lt;/p&gt;

&lt;h3&gt;
  
  
  4. Pick up a hobby
&lt;/h3&gt;

&lt;p&gt;Programmers are, in general, great problem solvers. That means that they are naturally clever, creative people. Pick up a hobby that helps get that creativity out! This can be anything from learning a musical instrument, to going out and geocaching. Finding a hobby that you love can be a great way to redirect your focus away from your code and simply let your brain rest. I've met a number of people that then take those hobbies and combine them. Some examples could be writing an app that records music, making a website for your biking club, or even creating a database to keep track of your board game win/loss record with your friends!&lt;/p&gt;

&lt;h3&gt;
  
  
  5. Take a break
&lt;/h3&gt;

&lt;p&gt;Simply taking a break can often be the best thing you can do to keep your energy levels up, stay focused and avoid short term burnout. Personally for me, I love going on walks throughout the day. It get's my body moving and physically away from my desk creating some separation from my work. Maybe for you, reading a chapter in a book might be the best way to relax. Other's might even rather sit back and watch an episode of their favorite show. Breaks are great for hitting the "Brain Reset" button and often times when you get back to coding you can approach it from a different prospective, which can be especially useful when tracking down pesky bugs!&lt;/p&gt;

&lt;p&gt;What do you do to stay sharp and focused when you aren't coding? Let me know in the comments!&lt;/p&gt;

&lt;p&gt;Thanks,&lt;br&gt;
Carl&lt;/p&gt;

</description>
      <category>healthydebate</category>
      <category>career</category>
      <category>productivity</category>
      <category>programming</category>
    </item>
    <item>
      <title>Why video tutorials should NOT replace reading documentation</title>
      <dc:creator>Carl Wills</dc:creator>
      <pubDate>Tue, 15 Jun 2021 14:02:23 +0000</pubDate>
      <link>https://dev.to/carlmobiledev/why-video-tutorials-should-not-replace-reading-documentation-5f02</link>
      <guid>https://dev.to/carlmobiledev/why-video-tutorials-should-not-replace-reading-documentation-5f02</guid>
      <description>&lt;p&gt;As more and more people start their programming journey, I'm finding that the number of video tutorials are increasing. That shouldn't be a surprise to anyone. Of course people will be making video tutorials showing off the basics of a cool new language, package, or feature. Heck, I might even start making video tutorials. But I'm also finding that more and more learners are solely depending on video tutorials when they start learning something new. &lt;/p&gt;

&lt;p&gt;Now, I don't think that video tutorials are bad. I've learned a lot of really good things from them myself. But I'm always amazed at the lack of awareness, by new programmers, that written documentation even exists for whatever they are trying to use.&lt;/p&gt;

&lt;p&gt;I use Flutter a lot in my free time, so I'll use it as an example here. Flutter has awesome documentation. Here's an example from the &lt;a href="https://api.flutter.dev/flutter/dart-ui/Color-class.html" rel="noopener noreferrer"&gt;Color class&lt;/a&gt;&lt;br&gt;
&lt;a href="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fj06tguv6c4244n8v03dy.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fj06tguv6c4244n8v03dy.png" alt="Screen Shot of Color class documentation"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Being able to read and understand this form of documentation is invaluable as you progress on your development journey. In it you'll find useful constructors, parameter descriptions and even common examples!&lt;/p&gt;

&lt;p&gt;There will be many times that all you have to learn from is a set of documentation, and being able to quickly reference it and understand the basics will help you iterate quickly, stand out in the company that you're at, and can even help you be more productive.&lt;/p&gt;

&lt;p&gt;Now all of that being said, I want to reiterate that I think video tutorials are good! But I don't think that they replace being able to read and understand documentation. A healthy balance of both is what's needed to really thrive and grow as a developer these days.&lt;/p&gt;

&lt;p&gt;If you're just learning your first language, or your fifth, I'd recommend taking a look through the documentation to see what you can find! You might be surprised by the little gems that are hidden away in there!&lt;/p&gt;

&lt;p&gt;What do you think? Am I being too harsh? Let me know in the comments if you read through documentation before starting a new project, or if you jump right into video tutorials!&lt;/p&gt;

&lt;p&gt;Thanks for reading,&lt;br&gt;
Carl&lt;/p&gt;

</description>
      <category>career</category>
      <category>programming</category>
      <category>productivity</category>
      <category>beginners</category>
    </item>
    <item>
      <title>Flutter Package Preview: shared_preferences</title>
      <dc:creator>Carl Wills</dc:creator>
      <pubDate>Sat, 12 Jun 2021 15:15:00 +0000</pubDate>
      <link>https://dev.to/carlmobiledev/flutter-package-preview-sharedpreferences-4kc1</link>
      <guid>https://dev.to/carlmobiledev/flutter-package-preview-sharedpreferences-4kc1</guid>
      <description>&lt;p&gt;Welcome to my new series of helpful preview articles, "Flutter Package Preview" where I talk about different packages on pub.dev and how to use them!&lt;/p&gt;

&lt;p&gt;For the first entry in this series, I'm excited to introduce &lt;a href="https://pub.dev/packages/shared_preferences"&gt;shared_preferences!&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;I always recommend reading through the pub.dev page of any new package before using it, so here's where you can find &lt;a href="https://pub.dev/packages/shared_preferences"&gt;shared_preferences.&lt;/a&gt;&lt;/p&gt;

&lt;h2&gt;
  
  
  What is shared_preferences
&lt;/h2&gt;

&lt;p&gt;shared_preferences is a package that helps streamline storing persistent data in a users, you guessed it, Shared Preferences! Each device type stores simple data in different ways. On iOS and macOS devices, this simple data is stored in what they call NSUserDefaults. On Android and other platforms, it's stored in what they call SharedPreferences. &lt;/p&gt;

&lt;p&gt;This data can be any of the following data types: int, bool, double, String, or List. It also persists between device or app restarts! So your user doesn't have to configure the app every time they open it!&lt;/p&gt;

&lt;h2&gt;
  
  
  How to include shared_preferences in your project
&lt;/h2&gt;

&lt;p&gt;So you want to use this package in your project?! Awesome! Either run &lt;code&gt;flutter pub add shared_preferences&lt;/code&gt; in your terminal or simply add this statement to your pubspec.yaml file.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;dependencies:
  shared_preferences: ^2.0.6
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h2&gt;
  
  
  How to use it in practice
&lt;/h2&gt;

&lt;p&gt;First, you'll need to include the import statement at the top of whichever class you'd like to use it in.&lt;br&gt;
&lt;code&gt;import 'package:shared_preferences/shared_preferences.dart';&lt;/code&gt;&lt;/p&gt;

&lt;p&gt;Great! Now before you can save or fetch any data from the persistent storage you need to get an instance of the SharedPreferences object.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;    SharedPreferences prefs = await SharedPreferences.getInstance();
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;You'll notice that this uses the &lt;code&gt;await&lt;/code&gt; keyword. This means that getting an instance of SharedPreferences is asynchronous and requires a little extra setup. You'll either need to use a FutureBuilder widget, or simply wrap it in an asynchronous function by using the &lt;code&gt;async&lt;/code&gt; keyword, like I've done here:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;void setUserNamePref() async {
    SharedPreferences prefs = await SharedPreferences.getInstance();
  }
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;&lt;em&gt;Although I do not do this in this example. I'd recommend trying to limit the number of times you get an instance of Shared Preferences. That way you can reduce the number of asynchronous calls you make. Separating getting an instance, and using the instance would also be a good idea.&lt;/em&gt;&lt;/p&gt;

&lt;h3&gt;
  
  
  Writing data to persistent storage
&lt;/h3&gt;

&lt;p&gt;Now we are ready to read or write to our preferences! Let's start by writing to our preferences. Since we've done so much setup, writing is easy:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;void setUserNamePref(String userName) async {
    SharedPreferences prefs = await SharedPreferences.getInstance();
    prefs.setString('userName', userName);
  }
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;The new code here is &lt;code&gt;prefs.setString('userName', userName);&lt;/code&gt;&lt;br&gt;
Our SharedPreferences object has a number of different set methods. One for each of the supported data types! Make sure when you are using these set methods that you choose the right one for your use case. In this example, userName is a String so I can use &lt;code&gt;prefs.setString&lt;/code&gt;.&lt;/p&gt;
&lt;h3&gt;
  
  
  Reading from persistent storage
&lt;/h3&gt;

&lt;p&gt;Now that we have data in storage, let's read it! By slightly modifying the example we've been working with, I can achieve this pretty easily:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;Future&amp;lt;String&amp;gt; getUserNamePref() async {
    SharedPreferences prefs = await SharedPreferences.getInstance();
    prefs.getString('userName');
  }
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Again in this example, we are dealing with asynchronous functions so we need to return a &lt;code&gt;Future&lt;/code&gt; and mark our function definition with &lt;code&gt;async&lt;/code&gt;. &lt;/p&gt;

&lt;p&gt;Yay! We're done, right? &lt;br&gt;
Well, not quite, there's one more important thing to think about when getting a shared preference. What if userName doesn't exist yet? What if we've never stored a userName for this user before, and now we try to access it?&lt;/p&gt;

&lt;p&gt;Well we can protect ourselves against this by using some of the new null safety features. See this example:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;Future&amp;lt;String&amp;gt; getUserNamePref() async {
    SharedPreferences prefs = await SharedPreferences.getInstance();
    return prefs.getString('userName') ?? 'Carl';
  }
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;If the key &lt;code&gt;'userName'&lt;/code&gt; doesn't exist, we can instead return the String 'Carl' so that the program can proceed!&lt;/p&gt;

&lt;h2&gt;
  
  
  Wrap up
&lt;/h2&gt;

&lt;p&gt;Using shared_preferences can be really powerful. You can use it to store data about the app settings, like whether the user has selected to use dark mode. Also, since it supports storing Strings, you can serialize your dart objects into JSON and store them! Then when you want to use them you can deserialize them back into their objects! There are so many different ways to use shared preferences, that it's a really flexible way to store simple user data in a fast efficient way.&lt;/p&gt;

&lt;p&gt;Thanks so much for getting this far! Hopefully you've enjoyed this brief look into the shared_preferences package! Make sure to follow if you're interested in more Flutter Package Previews!&lt;/p&gt;

&lt;p&gt;Carl&lt;/p&gt;

</description>
      <category>flutter</category>
      <category>dart</category>
      <category>tutorial</category>
      <category>mobile</category>
    </item>
    <item>
      <title>Simplify your Flutter app with Provider</title>
      <dc:creator>Carl Wills</dc:creator>
      <pubDate>Fri, 11 Jun 2021 11:50:39 +0000</pubDate>
      <link>https://dev.to/carlmobiledev/simplify-your-flutter-app-with-provider-2dkd</link>
      <guid>https://dev.to/carlmobiledev/simplify-your-flutter-app-with-provider-2dkd</guid>
      <description>&lt;p&gt;You may be aware of statefull and stateless widgets in flutter, but what if you want to share data between multiple different widgets in your app? You could pass the data between the widgets, but if you're creating something responsive that will change based on screen size, for example, you may need to structure your UI differently based on screen size or rotation. It becomes really tricky to manage the state of your application by passing that data to and from your widgets. Instead, I'd propose that you think about including a system of state management! &lt;/p&gt;

&lt;h2&gt;
  
  
  What is State Management anyway?
&lt;/h2&gt;

&lt;p&gt;State management is the process to keep and share data across different components. It allows you to store data pertaining to the state of your application, and retrieve that data from anywhere else without needing to pass it around! You could say it helps you &lt;strong&gt;manage your state!&lt;/strong&gt;&lt;/p&gt;

&lt;h2&gt;
  
  
  Okay, so what is Provider?
&lt;/h2&gt;

&lt;p&gt;Provider is a package that helps with state management! In short, it inserts a widget into your widget tree that holds values of state for your app. Because of this, any children to that Provider widget can access that state because it exists within the same widget tree!&lt;/p&gt;

&lt;h2&gt;
  
  
  How do I start working with Provider?
&lt;/h2&gt;

&lt;p&gt;Just like with any package, it's a good idea to read through the documentation on pub.dev before continuing. Here's the link to the provider: &lt;a href="https://pub.dev/packages/provider" rel="noopener noreferrer"&gt;https://pub.dev/packages/provider&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Okay, so you've read the documentation, right? &lt;br&gt;
Now we can import it into our project, simply include this in your pubspec.yaml file:&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;

dependencies:
  provider: ^5.0.0


&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;

&lt;p&gt;Now that you've imported the package we need start using it. To create the Provider into the widget tree you need to first identify the best spot in the widget tree (often right at the top level for small projects) and then create a Provider widget. Here's an example where I've decided to wrap my entire app in a Provider I've called &lt;strong&gt;MyProvider&lt;/strong&gt;&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;

void main() {
  runApp(ChangeNotifierProvider(
    create: (_) =&amp;gt; MyProvider(),
     child: MyApp()));
}

class MyProvider extends ChangeNotifier {
  int counter = 0;

  void increment() {
    counter++;
    notifyListeners();
  }

  void decrement() {
    counter--;
    notifyListeners();
  }
}


&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;
&lt;h2&gt;
  
  
  So, how do we access this and update it?
&lt;/h2&gt;

&lt;p&gt;It's easy! There are a few different ways to interact with your provider. If you are trying to access or modify state from outside of a StatelessWidget.build or State.build method you must access it like this:&lt;/p&gt;
&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;

Provider.of&amp;lt;MyProvider&amp;gt;(context).increment();


&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;

&lt;p&gt;If you are trying to access state within the build function, you can use this example:&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;

context.watch&amp;lt;MyProvider&amp;gt;().counter;


&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;

&lt;p&gt;There's something really interesting about these two functions. They will trigger an update to the UI! By calling notifyListeners() at the end of the increment and decrement functions, we're telling the UI that it's state has changed and it should rebuild!&lt;/p&gt;

&lt;p&gt;There's a few other ways to read state from provider that I'd like to touch on:&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;

context.select((MyProvider myProvider) =&amp;gt; myProvider.counter);



&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;

&lt;p&gt;The Provider Select/Selector functionality is really powerful! It causes your widget to only watch for changes to a specific member of the state, instead of the whole state entity. This becomes really useful if you have multiple different variables you're trying to keep state in, but you only want your widget to care about a single one of them!&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;

Selector&amp;lt;MyProvider, int&amp;gt;(
        builder: (context, data, child) {
          return Text("$data");
        },
        selector: (_, myProvider) =&amp;gt; myProvider.counter,
      ),


&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;

&lt;p&gt;That's right! If you're building this directly in the build function and have widgets dependent on this data, you can create the appropriate Widgets that are equivalent to the context statements above! In this case I decided to make an example for the Selector widget. &lt;/p&gt;

&lt;p&gt;Lastly, if you're debugging, you can see the values of all of your providers in Flutter DevTools!&lt;br&gt;
&lt;a href="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2F4cezu1bb1jsk1ldh5qt5.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2F4cezu1bb1jsk1ldh5qt5.png" alt="Provider information shown in Flutter DevTools on the Providers tab"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;I also want to mention that there's a newer state management package out the called &lt;em&gt;Riverpod&lt;/em&gt;. It's thought of as "Provider 2.0" by many and offers some awesome improvements. I'll be writing about Riverpod soon!&lt;/p&gt;

&lt;p&gt;I hope this quick run-through of the provider package and a few of its uses was helpful to you! I am not an expert at this, but knowledge sharing is always good and it's how we learn together. &lt;/p&gt;

&lt;p&gt;Thanks!&lt;br&gt;
Carl&lt;/p&gt;

</description>
      <category>flutter</category>
      <category>mobile</category>
      <category>firstpost</category>
      <category>dart</category>
    </item>
  </channel>
</rss>
