<?xml version="1.0" encoding="UTF-8"?><rss xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:content="http://purl.org/rss/1.0/modules/content/" xmlns:atom="http://www.w3.org/2005/Atom" version="2.0" xmlns:cc="http://cyber.law.harvard.edu/rss/creativeCommonsRssModule.html">
    <channel>
        <title><![CDATA[Stories by Russell Cecala on Medium]]></title>
        <description><![CDATA[Stories by Russell Cecala on Medium]]></description>
        <link>https://medium.com/@russell.cecala?source=rss-bcc5a2646f5b------2</link>
        <image>
            <url>https://cdn-images-1.medium.com/fit/c/150/150/0*2qx3imLg3rtR1BV8</url>
            <title>Stories by Russell Cecala on Medium</title>
            <link>https://medium.com/@russell.cecala?source=rss-bcc5a2646f5b------2</link>
        </image>
        <generator>Medium</generator>
        <lastBuildDate>Fri, 27 Nov 2026 21:47:24 GMT</lastBuildDate>
        <atom:link href="https://medium.com/@russell.cecala/feed" rel="self" type="application/rss+xml"/>
        <webMaster><![CDATA[yourfriends@medium.com]]></webMaster>
        <atom:link href="http://medium.superfeedr.com/" rel="hub"/>
        <item>
            <title><![CDATA[Full Stack with Flutter and Django Rest Framework]]></title>
            <link>https://medium.com/@russell.cecala/full-stack-with-flutter-and-django-rest-framework-16fd666d39b?source=rss-bcc5a2646f5b------2</link>
            <guid isPermaLink="false">https://medium.com/p/16fd666d39b</guid>
            <category><![CDATA[google-maps]]></category>
            <category><![CDATA[jetbrains]]></category>
            <category><![CDATA[full-stack]]></category>
            <category><![CDATA[django-rest-framework]]></category>
            <category><![CDATA[fluuter]]></category>
            <dc:creator><![CDATA[Russell Cecala]]></dc:creator>
            <pubDate>Tue, 05 Sep 2023 01:14:19 GMT</pubDate>
            <atom:updated>2024-04-22T22:56:01.129Z</atom:updated>
            <content:encoded><![CDATA[<h3>Introduction and Overview</h3><p>In today’s tech-driven world, the demand for robust and versatile web and mobile applications continues to rise. To meet this demand, developers often need to work with a full stack of technologies, seamlessly integrating frontend and backend components. In this end-to-end guide, we will explore full-stack development by combining two powerful frameworks: Flutter, Django and Django Rest Framework (DRF).</p><p>Flutter, developed by Google, is a dynamic open-source framework for building natively compiled applications for mobile, web, and desktop from a single codebase. Its versatility and expressive user interface components make it a favorite among developers for creating stunning and responsive user experiences.</p><p>On the other hand, Django, the high-level Python web framework, combined with Django Rest Framework (DRF), provides a robust backend foundation for your applications. DRF simplifies the process of building RESTful APIs, making it easier to interact with your backend server from your Flutter app.</p><p>Our project in this guide will showcase the seamless integration of these technologies. We will create a Flutter app that allows users to interact with a map, leave location-based notes, and save this information in a backend database using a custom REST API built with Django and DRF.</p><h3>What You Will Learn</h3><p>Throughout this article, we will cover the following key topics:</p><p><strong>Setting up the Backend:</strong></p><ul><li>We will start by creating the backend of our application using Django and DRF. You’ll learn how to set up a Django project, create models, serializers, and views, and establish a REST API to manage location-based notes.</li></ul><p><strong>Setting up the Frontend:</strong></p><ul><li>In the frontend section, we’ll dive into Flutter development. You’ll discover how to set up a Flutter project, integrate Google Maps, and build an interactive map interface where users can add notes at specific locations.</li></ul><p><strong>API Integration:</strong></p><ul><li>We’ll connect our Flutter app to the Django backend using HTTP requests. You’ll see how to send data from the app to the server and retrieve information to display on the map.</li></ul><p>By the end of this guide, you’ll have gained understanding of full-stack development with Flutter and Django Rest Framework. You’ll be equipped to create your own feature-rich applications that seamlessly blend frontend and backend technologies, opening up a world of possibilities for your projects.</p><p>So, let’s dive in and start building our full-stack app, combining the beauty of Flutter’s frontend with the robustness of Django’s backend. Get ready to embark on a journey that will expand your development skills and empower you to create innovative, data-driven applications.</p><h3><strong>The Backend</strong></h3><p>I am going to use <a href="https://www.jetbrains.com/pycharm/download/?section=mac">PyCharm</a> for my IDE. The instructions in this part of the article are based on <a href="https://www.django-rest-framework.org/tutorial/quickstart/">DRF tutorial quick start</a>. Since I am using PyCharm I will start up PyCharm and create a new project by clicking <strong>File &gt; New Project… </strong>in the menu bar. You should see the<strong> ‘New Project’ </strong>dialog box. Fill it out as shown below and click the <strong>‘Create’ </strong>button.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*V6Gx_YFJtGnzrI0MNOnuQA.png" /></figure><p>You’ll get prompted to choose between opening the project in the current window or if you want to open the project in a new window. Either selection is fine. You should now see this:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*WGYQeboKNF6FaYi3FbOa0w.png" /><figcaption>location_notez PyCharm project newly created</figcaption></figure><blockquote><strong>Note:</strong> The word ‘project’ is a little overloaded. We will have PyCharm project like the one that was just created and we will have a Django project and Google Cloud project and I am probably leave one or two out.</blockquote><p>Speaking of projects, it is time to create our Django project. Click on the <strong>‘Terminal’</strong> tab on the lower menu bar. You should see this:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*3e5EVy3Vd-HuoVQX8HHVwQ.png" /></figure><p><strong>Note:</strong> The commands I will execute will be executed from this terminal. <strong>Note:</strong> Take note of the (env) in the prompt. That means we have <em>activated </em>the Python virtual environment. Next we need to install the django Python package like so:</p><pre>pip install django</pre><p>We also need to install DRF like this:</p><pre>pip install djangorestframework</pre><p>Now we can create our Django project like so:</p><pre>django-admin startproject location_notez .</pre><p>Don’t forget the . and the end of the above command. In the IDE you can expand the location_notez folder and you should see this:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*lZ5FNeIlOrHqHNYmzozOeA.png" /></figure><p>Now we will create our Django app, notes, like so:</p><pre>django-admin startapp notes</pre><p>Now you should be able to see this in the IDE:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*YDkXG3554Et-e3i8gk3M7g.png" /></figure><p>For more in-depth discussion of Django please see Django’s awesome <a href="https://docs.djangoproject.com/en/4.2/intro/tutorial01/">tut</a>. Now sync your database for the first time:</p><pre>python manage.py migrate</pre><p>Now we can create our admin user like so:</p><pre>python manage.py createsuperuser --email admin@example.com --username admin</pre><p>Next we start creating and editing the files in our new Django project.</p><p>Edit your location_notez/settings.py file. Make sure you have this for your INSTALLED_APPS variable is set to this:</p><pre>INSTALLED_APPS = [<br>    &#39;django.contrib.admin&#39;,<br>    &#39;django.contrib.auth&#39;,<br>    &#39;django.contrib.contenttypes&#39;,<br>    &#39;django.contrib.sessions&#39;,<br>    &#39;django.contrib.messages&#39;,<br>    &#39;django.contrib.staticfiles&#39;,<br>    &#39;notes&#39;,<br>    &#39;rest_framework&#39;<br>]</pre><p>We added &#39;notes&#39; and &#39;rest_framework&#39;. Also add these lines to the settings.py file (just about anywhere in the file):</p><pre>REST_FRAMEWORK = {<br>    &#39;DEFAULT_PAGINATION_CLASS&#39;: &#39;rest_framework.pagination.PageNumberPagination&#39;,<br>    &#39;PAGE_SIZE&#39;: 10<br>}</pre><p>Make sure notes/models.py looks like this:</p><pre>from django.db import models<br><br># Create your models here.<br>class Note(models.Model):<br>    created = models.DateTimeField(auto_now_add=True)<br>    updated = models.DateTimeField(auto_now=True)<br>    taker = models.CharField(max_length=128)<br>    message = models.TextField(max_length=1024)<br>    latitude = models.FloatField()<br>    longitude = models.FloatField()</pre><p>Hopefully, the field names are self explanatory. Our frontend app will allow the user to click on a map and make “a note” and store a message and the GPS coordinates of where the user clicked on the map in a relational database.</p><p>Create a notes/serializers.py file with this:</p><pre>from .models import Note<br>from rest_framework import serializers<br><br>class NoteSerializer(serializers.HyperlinkedModelSerializer):<br>    class Meta:<br>        model = Note<br>        fields = &quot;__all__&quot;;</pre><p>Edit the notes/views.py file so it looks like this:</p><pre>from .models import Note<br>from rest_framework import viewsets<br>from .serializers import NoteSerializer<br><br><br>class NoteViewSet(viewsets.ModelViewSet):<br>    &quot;&quot;&quot;<br>    API endpoint that allows notes to be viewed or edited.<br>    &quot;&quot;&quot;<br>    queryset = Note.objects.all().order_by(&#39;-created&#39;)<br>    serializer_class = NoteSerializer%                                      </pre><p>Edit the location_notes/urls.py file:</p><pre>from django.contrib import admin<br>from django.urls import include, path<br>from rest_framework import routers<br>from notes import views<br><br>router = routers.DefaultRouter()<br>router.register(r&#39;notes&#39;, views.NoteViewSet)<br><br>urlpatterns = [<br>    path(&#39;admin/&#39;, admin.site.urls),<br>    path(&#39;&#39;, include(router.urls)),  # Include the router&#39;s URL patterns for the notes app<br>    path(&#39;notes/&#39;, include(&#39;rest_framework.urls&#39;, namespace=&#39;rest_framework&#39;))<br>]                                                                                               Create a file, notes/serializers.py with these lines:</pre><p>We can leave these files alone: __init.py, admin.py, apps.py and tests.py.</p><p><strong>Update database schema with new model</strong></p><p>We need to update the database schema to accommodate our Notes model.</p><pre>python manage.py makemigrations</pre><p>Then run …</p><pre> python manage.py migrate</pre><p>… and BOOM! You got a REST API for your Notes objects. Don’t believe me? Execute …</p><pre>python manage.py runserver</pre><p>Click on the link you see in the output:</p><p>Starting development server at <a href="http://127.0.0.1:8000/">http://127.0.0.1:8000/</a></p><iframe src="https://cdn.embedly.com/widgets/media.html?src=https%3A%2F%2Fplayer.vimeo.com%2Fvideo%2F849659957%3Fapp_id%3D122963&amp;dntp=1&amp;display_name=Vimeo&amp;url=https%3A%2F%2Fvimeo.com%2F849659957&amp;image=https%3A%2F%2Fi.vimeocdn.com%2Fvideo%2F1703722176-43d82d267c2027d850815b50ed65e1235ac5296332eac06bdedee040466f0b05-d_960&amp;key=a19fcc184b9711e1b4764040d3dc5c07&amp;type=text%2Fhtml&amp;schema=vimeo" width="1092" height="1142" frameborder="0" scrolling="no"><a href="https://medium.com/media/c52e2e8e6fdea5dd3aa01f265ffe73e4/href">https://medium.com/media/c52e2e8e6fdea5dd3aa01f265ffe73e4/href</a></iframe><p>Ok! Easy Peezy! Next we will write our Flutter app.</p><h3><strong>The Frontend</strong></h3><p>We will develop the frontend using <a href="https://flutter.dev/">Flutter</a>. I am going to use the <a href="https://www.jetbrains.com/idea/download/other.html">IntelliJ IDEA 2023.1.4 (Community Edition)</a> IDE. We also need a <a href="https://accounts.google.com/signup">Google Cloud project</a> to be able to use Google Maps. The instructions for setting up your Flutter environment are based on the instructions from the <a href="https://codelabs.developers.google.com/codelabs/flutter-codelab-first#0">code lab</a>. If you want to make iPhone apps you will need an to be able to run <a href="https://developer.apple.com/xcode/">Xcode</a>.</p><p>Create new Flutter project use the IDE. Start IntelliJ IDEA, then click the ‘New Project’ button …</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*FLFK6AMjSARJx3ranYPp8w.png" /></figure><p>After clicking the <strong>‘New Project’</strong> button you should see this …</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*YzmLfH9Zp7LxQjdt4AdyYw.png" /></figure><p>If you haven’t installed Flutter click on the <strong>Help:</strong> link (<a href="https://docs.flutter.dev/get-started/install">https://docs.flutter.dev/get-started/install</a>) then click <strong>‘Cancel’</strong>.</p><p>I am using version …</p><pre>% pwd<br>/Users/russ/FLUTTER/flutter/bin/flutter --version<br>Flutter 3.10.6 • channel stable • https://github.com/flutter/flutter.git<br>Framework • revision f468f3366c (2 weeks ago) • 2023-07-12 15:19:05 -0700<br>Engine • revision cdbeda788a<br>Tools • Dart 3.0.6 • DevTools 2.23.1</pre><p>… btw. You might have installed flutter in a different location than I did. So only you know where the flutter executable is on your computer.</p><p>Once you have installed the Flutter SDK repeat the above steps and click the <strong>‘Next’</strong> button and the new `location_notes_flutter` project will load and open a session of our IDE:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*Jc3KgdNcMdGBAaFL-bp9LQ.png" /></figure><p>Let’s do a QA to make sure everything up to this point is working.</p><iframe src="https://cdn.embedly.com/widgets/media.html?src=https%3A%2F%2Fplayer.vimeo.com%2Fvideo%2F849843629%3Fapp_id%3D122963&amp;dntp=1&amp;display_name=Vimeo&amp;url=https%3A%2F%2Fvimeo.com%2F849843629&amp;image=https%3A%2F%2Fi.vimeocdn.com%2Fvideo%2F1704018767-f92d255291dfa77b177f0df8a299f2f94e98043753dbf812819d731bbeaefd00-d_1280&amp;key=a19fcc184b9711e1b4764040d3dc5c07&amp;type=text%2Fhtml&amp;schema=vimeo" width="1920" height="1174" frameborder="0" scrolling="no"><a href="https://medium.com/media/fee38546286d1640042ea11567910973/href">https://medium.com/media/fee38546286d1640042ea11567910973/href</a></iframe><p>In the video there are some noise red warnings and error messages you can ignore. The important thing is that the app ran. You can also test by starting a Web version of the app.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*nAlRh05yE47A36AZcXUh7A.png" /></figure><p>Now we need to make a series of edits to our apps source code. We also need to get a <strong>Google Maps Api Key</strong>. Any documentation I may write about getting a key would be out of date in a matter of months. So here is where I went to find out how to get my key … gptchat.</p><blockquote>How do I make a google cloud project?</blockquote><blockquote>As of my last update in September 2021, here’s a step-by-step guide on how to create a Google Cloud project:</blockquote><blockquote>1. **Sign in to your Google Account**: If you don’t have a Google Account, you’ll need to create one first. Visit <a href="https://accounts.google.com/signup">https://accounts.google.com/signup</a> and follow the instructions.</blockquote><blockquote>2. **Go to Google Cloud Console**: Open your web browser and navigate to the Google Cloud Console at <a href="https://console.cloud.google.com/">https://console.cloud.google.com/</a>.</blockquote><blockquote>3. **Create a new project**: In the Google Cloud Console, click on the project dropdown (usually located in the top navigation bar) and then click on the “New Project” button.</blockquote><blockquote>4. **Enter project details**: A pop-up window will appear where you need to fill in the project details. This includes the project name, organization (if applicable), and the billing account you want to associate with the project. Make sure to select a billing account that you have access to and that is linked to a valid payment method.</blockquote><blockquote>5. **Enable billing**: Before you can use Google Cloud services, you need to enable billing for your project. If you haven’t set up a billing account, you will be prompted to create one during this step.</blockquote><blockquote>6. **Accept Terms and Conditions**: Review the terms and conditions and click on the checkbox to accept them.</blockquote><blockquote>7. **Click “Create”**: Once you’ve filled in all the necessary details and accepted the terms, click on the “Create” button. Google Cloud will create your project, and you’ll be redirected to the project dashboard.</blockquote><blockquote>Congratulations! You’ve successfully created a Google Cloud project.</blockquote><blockquote>Please note that Google Cloud Platform (GCP) might have introduced new features or changes to their platform since my last update. If you encounter any difficulties or discrepancies during the project creation process, I recommend referring to the official Google Cloud documentation for the most up-to-date information.</blockquote><blockquote>How do I create an GoogleMapsApiKey?</blockquote><blockquote>To create a Google Maps API key, follow these steps:</blockquote><blockquote>1. Go to the Google Cloud Console: Visit the Google Cloud Console at <a href="https://console.cloud.google.com/">https://console.cloud.google.com/</a> and log in with your Google Cloud account credentials.</blockquote><blockquote>2. Create a new project (if needed): If you haven’t created a project yet, click on the project dropdown at the top of the page, then click on the “New Project” button. Give your project a name and click “Create.”</blockquote><blockquote>3. Enable the Google Maps Platform: In the Google Cloud Console, click on the “Hamburger” menu (☰) in the top-left corner and navigate to “APIs &amp; Services” &gt; “Library.”</blockquote><blockquote>4. Find the Google Maps Platform: Search for “Google Maps Platform” in the library and select it.</blockquote><blockquote>5. Choose the API you want to use: In the Google Maps Platform, you can choose from multiple APIs, such as Maps JavaScript API, Geocoding API, Places API, etc. Select the appropriate API you want to use (e.g., Maps JavaScript API).</blockquote><blockquote>6. Enable the API: Click on the “Enable” button for the chosen API.</blockquote><blockquote>7. Create an API key: After enabling the API, go back to the “Hamburger” menu (☰) and navigate to “APIs &amp; Services” &gt; “Credentials.”</blockquote><blockquote>8. Create a new API key: Click on the “Create credentials” button and select “API key” from the dropdown.</blockquote><blockquote>9. Restrict the API key (optional): For security purposes, you can restrict the usage of your API key to specific IP addresses, HTTP referrers, or APIs. This step is optional but recommended.</blockquote><blockquote>10. Copy the API key: Once the API key is created, it will be displayed on the screen. Copy the API key to use it in your application.</blockquote><blockquote>11. Implement the API key in your application: In your application code (for example, if you’re using the Google Maps JavaScript API), add the API key as a parameter when loading the Maps API. For instance:</blockquote><blockquote>```html<br>&lt;! — Replace YOUR_API_KEY with the actual API key →<br>&lt;script src=”<a href="https://maps.googleapis.com/maps/api/js?key=YOUR_API_KEY&amp;libraries=places">https://maps.googleapis.com/maps/api/js?key=YOUR_API_KEY&amp;libraries=places</a>&quot;&gt;&lt;/script&gt;<br>```</blockquote><blockquote>That’s it! You now have a Google Maps API key that you can use to access the Google Maps Platform services in your application. Remember to keep your API key secure and avoid sharing it publicly to prevent unauthorized use and potential billing issues.</blockquote><p><strong>KEEP YOUR API KEY SECRET!!! </strong>Use some sort of password manager to keep it secure or something. If someone gets your key they could run up a big bill you’d get stuck with. In this article I will use a made up random string that is complete useless in the code, so you’ll have to use your key.</p><p>My fake API key is jJCh4c5AwEiyknsF5W3NaQ9CQClsNii0</p><p>Here is a list of files that need the key:</p><pre>ios/Runner/AppDelegate.swift<br>ios/Runner/Info.plist<br>.env</pre><p>So let use the IDE’s editor to edit these files so that that: ios/Runner/AppDelegate.swift looks like this:</p><pre>import UIKit<br>import Flutter<br>import GoogleMaps<br><br>@UIApplicationMain<br>@objc class AppDelegate: FlutterAppDelegate {<br>  override func application(<br>    _ application: UIApplication,<br>    didFinishLaunchingWithOptions launchOptions: [UIApplication.LaunchOptionsKey: Any]?<br>  ) -&gt; Bool {<br>    GeneratedPluginRegistrant.register(with: self)<br>    GMSServices.provideAPIKey(&quot;jJCh4c5AwEiyknsF5W3NaQ9CQClsNii0&quot;)<br><br>    return super.application(application, didFinishLaunchingWithOptions: launchOptions)<br>  }<br>}</pre><p>Don’t forget to replace jJCh4c5AwEiyknsF5W3NaQ9CQClsNii0with your key. The ios/Runner/Info.plist ends with these lines:</p><pre><br>        &lt;key&gt;io.flutter.embedded_views_preview&lt;/key&gt;<br>        &lt;true/&gt;<br>        &lt;key&gt;GoogleMapsApiKey&lt;/key&gt;<br>        &lt;string&gt;jJCh4c5AwEiyknsF5W3NaQ9CQClsNii0&lt;/string&gt;<br>        &lt;key&gt;NSLocationAlwaysAndWhenInUseUsageDescription&lt;/key&gt;<br>        &lt;string&gt;Google maps needs this to center the map at your location&lt;/string&gt;<br>        &lt;key&gt;NSLocationWhenInUseUsageDescription&lt;/key&gt;<br>        &lt;string&gt;Google maps needs this to center the map at your location&lt;/string&gt;<br>&lt;/dict&gt;<br>&lt;/plist&gt;</pre><p>.env looks like this:</p><p>GOOGLE_API_KEY=jJCh4c5AwEiyknsF5W3NaQ9CQClsNii0</p><p>Remember to keep your environment variables secure and avoid sharing sensitive data, such as API keys, in public code repositories. The .env file should only be used for local development purposes and should not be committed to version control. Put it in your .gitignore file.</p><p>Edit the pubspec.yaml to look like this:</p><pre>name: location_notes_flutter<br>description: Location Notes App<br>publish_to: &#39;none&#39; # Remove this line if you wish to publish to pub.dev<br>version: 1.0.0+1<br>environment:<br>  sdk: &#39;&gt;=2.18.6 &lt;3.0.0&#39;<br><br>dependencies:<br>  flutter:<br>    sdk: flutter<br>  google_maps_flutter: ^2.0.6  # Replace with the latest version of the package<br>  geolocator: ^7.0.3  # Use the latest version available<br>  http: ^0.13.3  # For making REST API calls<br>  uuid: ^3.0.4  # Add the latest version of the uuid package<br>  flutter_dotenv: ^5.0.2<br>  cupertino_icons: ^1.0.2<br><br>dev_dependencies:<br>  flutter_test:<br>    sdk: flutter<br>  flutter_lints: ^2.0.0<br><br>flutter:<br>  uses-material-design: true<br>  assets:<br>    - .env<br></pre><p>Now we need to install these dependencies by running <strong>‘Pub Get’</strong> in the IDE like so:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*A4CX4Eua9E870Q2HnxMT1w.png" /></figure><p>Edit the lib/main.dart file to look like this:</p><pre>import &#39;package:flutter/material.dart&#39;;<br>import &#39;package:google_maps_flutter/google_maps_flutter.dart&#39;;<br>import &#39;package:http/http.dart&#39; as http;<br>import &#39;dart:convert&#39;;<br>import &#39;package:geolocator/geolocator.dart&#39;;<br>import &#39;package:uuid/uuid.dart&#39;; // Import the uuid package<br>import &#39;package:flutter_dotenv/flutter_dotenv.dart&#39;;<br><br><br>Future&lt;void&gt; main() async {<br>  await dotenv.load();<br>  runApp(MyApp());<br>}<br><br>class Note {<br>  final double latitude;<br>  final double longitude;<br>  String noteText;<br><br>  Note(this.latitude, this.longitude, this.noteText);<br>}<br><br>class MapScreen extends StatefulWidget {<br>  @override<br>  _MapScreenState createState() =&gt; _MapScreenState();<br>}<br><br>class MyApp extends StatelessWidget {<br>  // Generate and store the UUID on the user&#39;s device<br>  final String appId = Uuid().v4(); // Generate a new UUID<br><br>  @override<br>  Widget build(BuildContext context) {<br>    return MaterialApp(<br>      title: &#39;Location Notes&#39;,<br>      home: MapScreen(),<br>    );<br>  }<br>}<br><br>class _MapScreenState extends State&lt;MapScreen&gt; {<br>  GoogleMapController? mapController;<br>  Set&lt;Marker&gt; _markers = {};<br><br>  @override<br>  void initState() {<br>    super.initState();<br>    _getInitialCameraPosition();<br>  }<br><br>  Future&lt;void&gt; _getInitialCameraPosition() async {<br>    try {<br>      Position position = await Geolocator.getCurrentPosition(<br>        desiredAccuracy: LocationAccuracy.best,<br>      );<br><br>      LatLng initialCameraPosition = LatLng(position.latitude, position.longitude);<br>      mapController?.moveCamera(CameraUpdate.newLatLngZoom(initialCameraPosition, 17.5));<br>    } catch (e) {<br>      print(&#39;Error getting initial camera position: $e&#39;);<br>    }<br>  }<br><br>  @override<br>  Widget build(BuildContext context) {<br>    return Scaffold(<br>      appBar: AppBar(<br>        title: Text(&#39;Location Notes&#39;),<br>      ),<br>      body: GoogleMap(<br>        onMapCreated: (GoogleMapController controller) {<br>          mapController = controller;<br>        },<br>        onTap: _addNoteMarker,<br>        markers: _markers,<br>        initialCameraPosition: CameraPosition(<br>          target: LatLng(0, 0), // Default initial position<br>          zoom: 17.5,<br>        ),<br>      ),<br>    );<br>  }<br><br>  void _addNoteMarker(LatLng latLng) {<br>    showDialog(<br>      context: context,<br>      builder: (context) =&gt; NoteInputDialog(),<br>    ).then((noteText) {<br>      if (noteText != null) {<br>        setState(() {<br>          _markers.add(<br>            Marker(<br>              markerId: MarkerId(latLng.toString()),<br>              position: latLng,<br>              onTap: () =&gt; _showNoteDetails(latLng, noteText),<br>            ),<br>          );<br>        });<br><br>        // Make the API call to create a Note object in the background<br>        _createNoteOnServerInBackground(latLng.latitude, latLng.longitude, noteText)<br>            .then((response) {<br>          // Handle the response if needed (e.g., print success message or update UI)<br>          print(&#39;Note created successfully&#39;);<br>        })<br>            .catchError((error) {<br>          // Handle errors if the API call fails (e.g., show an error message or handle retry logic)<br>          print(&#39;Failed to create note: $error&#39;);<br>        });<br>      }<br>    });<br>  }<br><br>  void _showNoteDetails(LatLng latLng, String noteText) {<br>    showDialog(<br>      context: context,<br>      builder: (context) =&gt; AlertDialog(<br>        title: Text(&#39;Note Details&#39;),<br>        content: Text(<br>          &#39;Latitude: ${latLng.latitude}\nLongitude: ${latLng.longitude}\n\nNote: $noteText&#39;,<br>        ),<br>        actions: [<br>          TextButton(<br>            onPressed: () =&gt; Navigator.of(context).pop(),<br>            child: Text(&#39;OK&#39;),<br>          ),<br>        ],<br>      ),<br>    );<br>  }<br><br>  Future&lt;void&gt; _createNoteOnServerInBackground(double latitude, double longitude, String noteText) {<br>    final response = http.post(<br>      Uri.parse(&#39;http://127.0.0.1:8000/notes/&#39;), // Replace with your API endpoint<br>      headers: &lt;String, String&gt;{<br>        &#39;Content-Type&#39;: &#39;application/json; charset=UTF-8&#39;,<br>      },<br>      body: jsonEncode(&lt;String, dynamic&gt;{<br>        &quot;taker&quot;: &quot;phone-app&quot;,<br>        &quot;message&quot;: noteText,<br>        &quot;latitude&quot;: latitude,<br>        &quot;longitude&quot;: longitude,<br>      }),<br>    );<br><br>    return response.then((response) {<br>      if (response.statusCode == 201) {<br>        // If the API call is successful, return here<br>        return;<br>      } else {<br>        // If the API call fails, throw an exception to be caught by the catchError block<br>        throw Exception(&#39;Failed to create note. Status code: ${response.statusCode}&#39;);<br>      }<br>    }).catchError((e) {<br>      // If any error occurs during the API call, throw an exception to be caught by the catchError block<br>      throw Exception(&#39;Error creating note: $e&#39;);<br>    });<br>  }<br>}<br><br>class NoteInputDialog extends StatefulWidget {<br>  @override<br>  _NoteInputDialogState createState() =&gt; _NoteInputDialogState();<br>}<br><br>class _NoteInputDialogState extends State&lt;NoteInputDialog&gt; {<br>  TextEditingController _textEditingController = TextEditingController();<br><br>  @override<br>  Widget build(BuildContext context) {<br>    return AlertDialog(<br>      title: Text(&#39;Add Note&#39;),<br>      content: TextField(<br>        controller: _textEditingController,<br>        decoration: InputDecoration(labelText: &#39;Enter your note&#39;),<br>      ),<br>      actions: [<br>        TextButton(<br>          onPressed: () =&gt; Navigator.of(context).pop(),<br>          child: Text(&#39;Cancel&#39;),<br>        ),<br>        TextButton(<br>          onPressed: () {<br>            String noteText = _textEditingController.text;<br>            Navigator.of(context).pop(noteText);<br>          },<br>          child: Text(&#39;Add&#39;),<br>        ),<br>      ],<br>    );<br>  }<br><br>  @override<br>  void dispose() {<br>    _textEditingController.dispose();<br>    super.dispose();<br>  }<br>}</pre><p>Wow that’s a lot of code. If you want a line by line explanation you can copy and paste the code into gptchat. It’ll do a much better job at explaining the code than I can :) … anyways. You need to make your lib/main.dart file look like that above. Now you should be able to launch the app like I do here:</p><iframe src="https://cdn.embedly.com/widgets/media.html?src=https%3A%2F%2Fplayer.vimeo.com%2Fvideo%2F861043367%3Fapp_id%3D122963&amp;dntp=1&amp;display_name=Vimeo&amp;url=https%3A%2F%2Fvimeo.com%2F861043367&amp;image=https%3A%2F%2Fi.vimeocdn.com%2Fvideo%2F1719426192-6f558324ba33f66a9d2552816b48d9bc595e0d825dd1096205069e2ff873328c-d_1280&amp;key=a19fcc184b9711e1b4764040d3dc5c07&amp;type=text%2Fhtml&amp;schema=vimeo" width="1920" height="1200" frameborder="0" scrolling="no"><a href="https://medium.com/media/7b66d598fbd99943253a2873c8ec624a/href">https://medium.com/media/7b66d598fbd99943253a2873c8ec624a/href</a></iframe><p>In the video I start up our DRF REST API and then I launch the iOS simulator and then launch our Flutter application. I hope eveything works for you too! If not post a question.</p><h3><strong>Miscellaneous notes:</strong></h3><p>If you want to clean up the Notes database really fast you can use Django’s ORM like so:</p><pre>(venv) russellcecala@Russells-MBP location_notes % python manage.py shell                       <br>Python 3.9.6 (default, May  7 2023, 23:32:45) <br>[Clang 14.0.3 (clang-1403.0.22.14.1)] on darwin<br>Type &quot;help&quot;, &quot;copyright&quot;, &quot;credits&quot; or &quot;license&quot; for more information.<br>(InteractiveConsole)<br>&gt;&gt;&gt; from notes.models import Note<br>&gt;&gt;&gt; all_notes = Note.objects.all()<br>&gt;&gt;&gt; len(all_notes)<br>4<br>&gt;&gt;&gt; all_notes.delete()<br>(4, {&#39;notes.Note&#39;: 4})<br>&gt;&gt;&gt; len(all_notes)<br>0<br>&gt;&gt;&gt;</pre><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=16fd666d39b" width="1" height="1" alt="">]]></content:encoded>
        </item>
    </channel>
</rss>