<?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>Forem: Yogesh Sharma</title>
    <description>The latest articles on Forem by Yogesh Sharma (@1995yogeshsharma).</description>
    <link>https://forem.com/1995yogeshsharma</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%2F741118%2F76a50f16-a9dd-4ad6-81c8-0681c860dd63.jpeg</url>
      <title>Forem: Yogesh Sharma</title>
      <link>https://forem.com/1995yogeshsharma</link>
    </image>
    <atom:link rel="self" type="application/rss+xml" href="https://forem.com/feed/1995yogeshsharma"/>
    <language>en</language>
    <item>
      <title>Insights into Forms in Flask</title>
      <dc:creator>Yogesh Sharma</dc:creator>
      <pubDate>Sun, 14 Aug 2022 07:11:00 +0000</pubDate>
      <link>https://forem.com/1995yogeshsharma/insights-into-forms-in-flask-2abl</link>
      <guid>https://forem.com/1995yogeshsharma/insights-into-forms-in-flask-2abl</guid>
      <description>&lt;p&gt;Hey there!&lt;/p&gt;

&lt;p&gt;Today, we will look into implementing &lt;code&gt;forms&lt;/code&gt; in Flask. We will start with quick rendering of forms and look into details of customising the form.&lt;/p&gt;

&lt;h2&gt;
  
  
  Background
&lt;/h2&gt;

&lt;p&gt;&lt;a href="https://flask.palletsprojects.com/en/2.2.x/" rel="noopener noreferrer"&gt;Flask&lt;/a&gt; is popular web development framework implemented in python. &lt;br&gt;
Forms are important part of developing any websites and are used heavily to take inputs from users. &lt;br&gt;
We would see the usage of &lt;a href="https://wtforms.readthedocs.io/en/3.0.x/" rel="noopener noreferrer"&gt;wtform&lt;/a&gt; module for flask. For frontend, we will use &lt;a href="https://flask.palletsprojects.com/en/2.2.x/templating/" rel="noopener noreferrer"&gt;jinja2&lt;/a&gt; templating.&lt;/p&gt;
&lt;h2&gt;
  
  
  Pre-requisites
&lt;/h2&gt;

&lt;p&gt;A basic understanding of python and flask is required. It is expected that you know how a flask server is started and have it running.&lt;/p&gt;

&lt;p&gt;With all the above information, let's get started -&lt;/p&gt;
&lt;h2&gt;
  
  
  Setup
&lt;/h2&gt;

&lt;p&gt;We need following things before we can render a form to frontend - &lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;A basic flask app running&lt;/li&gt;
&lt;li&gt;A python form class implemented&lt;/li&gt;
&lt;li&gt;A controller which would render the form&lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;It is assumed that you already have (1) running. For (2), add the following code to your forms.py&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;# forms.py
from flask_wtf import FlaskForm
from wtforms import StringField, IntegerField, TextField, SubmitField
from wtforms.fields.html5 import IntegerRangeField
from wtforms.validators import DataRequired, Optional, NumberRange


class SampleForm(FlaskForm):
    name = StringField('Name', validators=[DataRequired()])
    age = IntegerField('Age', validators=[DataRequired()])
    moto = TextField('moto', validators=[Optional()])
    range = IntegerRangeField('range', default=10, validators=[DataRequired(), NumberRange(min=1, max=50)])

    submit = SubmitField('Submit')
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;You can read more details about wtf at &lt;a href="https://wtforms.readthedocs.io/en/3.0.x/" rel="noopener noreferrer"&gt;https://wtforms.readthedocs.io/en/3.0.x/&lt;/a&gt; and more about validators at &lt;a href="https://wtforms.readthedocs.io/en/3.0.x/validators/" rel="noopener noreferrer"&gt;https://wtforms.readthedocs.io/en/3.0.x/validators/&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;For 3, add following code to create controller&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;# routes.py
from flask import Blueprint, url_for, redirect, render_template

from app.sample.forms import SampleForm

sample = Blueprint('sample', __name__)


@sample.route("/sample-form", methods=["GET", "POST"])
def sample_controller():
    form = SampleForm()

    if form.validate_on_submit():
        return redirect(url_for('sample.sample_controller'))

    return render_template('sample/sample_form.html', form=form)

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

&lt;/div&gt;



&lt;p&gt;To attach the route to your app, add following to the create_app method&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;# app/__init__.py
from app.sample.routes import sample

app.register_blueprint(sample)
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h2&gt;
  
  
  Quick form rendering
&lt;/h2&gt;

&lt;p&gt;First, we'll look at the quickest way to render beautiful forms.&lt;/p&gt;

&lt;p&gt;create &lt;code&gt;sample/sample_form.html&lt;/code&gt; in &lt;code&gt;templates/&lt;/code&gt; folder&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;{% extends 'base.html' %}
{% import 'bootstrap/wtf.html' as wtf %}

{% block app_content %}
&amp;lt;div class="container-fluid"&amp;gt;
    {{ wtf.quick_form(form, button_map={'submit': 'success'}) }}
&amp;lt;/div&amp;gt;
{% endblock %}
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Once you reload the server the output should look like&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media2.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%2Fyjxqb5r4zipxc5tro9vg.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.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%2Fyjxqb5r4zipxc5tro9vg.png" alt="Quick form output" width="800" height="195"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Voila! You have your beautiful form rendered with just one line of html code. Note that, button_map maps the field to bootstrap styling class (btn-success in this case). Another thing to note, the flask setup is using bootstrap in this case so your styling may vary depending on whether you are using bootstrap or not.&lt;/p&gt;

&lt;h2&gt;
  
  
  Field wise form rendering
&lt;/h2&gt;

&lt;p&gt;Change your sample html to following&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;{% extends 'base.html' %}
{% import 'bootstrap/wtf.html' as wtf %}

{% block app_content %}
&amp;lt;div class="container-fluid"&amp;gt;
    &amp;lt;form class="form form-horizontal" method="post" role="form"&amp;gt;
        {{ form.hidden_tag() }}
        {{ wtf.form_field(form.name) }}
        {{ wtf.form_field(form.age) }}
        {{ wtf.form_field(form.moto) }}
        {{ wtf.form_field(form.range, class="form-range") }}
        {{ wtf.form_field(form.submit, class="btn btn-success") }}
    &amp;lt;/form&amp;gt;
&amp;lt;/div&amp;gt;
{% endblock %}
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;This gives more control over handling fields, as we can render field by field and provide custom styling. The end result should look like following - &lt;/p&gt;

&lt;p&gt;&lt;a href="https://media2.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%2Fl9srf2ec0pi40upzoizg.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.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%2Fl9srf2ec0pi40upzoizg.png" alt="Field wise form output" width="800" height="183"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;h2&gt;
  
  
  Further customising
&lt;/h2&gt;

&lt;p&gt;This is the most interesting part for me as I was not able to locate any corresponding docs online easily.&lt;br&gt;
Consider that in the range field, we also want to show the value that is currently selected and we also want to show the default value initially.&lt;/p&gt;

&lt;p&gt;Here's how we can achieve this. Change html file to following -&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;{% extends 'base.html' %}
{% import 'bootstrap/wtf.html' as wtf %}

{% block app_content %}
&amp;lt;div class="container-fluid"&amp;gt;
    &amp;lt;form class="form form-horizontal" method="post" role="form"&amp;gt;
        {{ form.hidden_tag() }}
        {{ wtf.form_field(form.name) }}
        {{ wtf.form_field(form.age) }}
        {{ wtf.form_field(form.moto) }}
{#        {{ wtf.form_field(form.range, class="form-range") }}#}
        &amp;lt;label for="range" class="form-label"&amp;gt;{{ form.range.label }}&amp;lt;/label&amp;gt;
        {{ form.range(min='1', max='50', oninput="r_value.value = this.value", class="form-range") }}
        &amp;lt;input type="text" id="r_value" value="{{ form.range.data }}" disabled&amp;gt;&amp;lt;/input&amp;gt;&amp;lt;br/&amp;gt;&amp;lt;br/&amp;gt;

        {{ wtf.form_field(form.submit, class="btn btn-success") }}
    &amp;lt;/form&amp;gt;
&amp;lt;/div&amp;gt;
{% endblock %}
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Notice the code for range input, we have separately accessed label and input field and we have added a custom &lt;code&gt;oninput&lt;/code&gt; to update value of the new input added.&lt;/p&gt;

&lt;p&gt;The end result looks like this - &lt;/p&gt;

&lt;p&gt;&lt;a href="https://media2.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%2F2m8a6ppdtsov8qyu0co1.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.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%2F2m8a6ppdtsov8qyu0co1.png" alt="Custom output" width="800" height="192"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media2.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%2Fkbz2esm0atkzunthhfvf.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.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%2Fkbz2esm0atkzunthhfvf.png" alt="Custom output 2" width="800" height="195"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;That's all this time!&lt;/p&gt;

</description>
      <category>flask</category>
      <category>python</category>
      <category>webdev</category>
    </item>
    <item>
      <title>Use Random Integer in terraform module</title>
      <dc:creator>Yogesh Sharma</dc:creator>
      <pubDate>Sun, 27 Feb 2022 16:26:00 +0000</pubDate>
      <link>https://forem.com/1995yogeshsharma/use-random-integer-in-terraform-module-21i5</link>
      <guid>https://forem.com/1995yogeshsharma/use-random-integer-in-terraform-module-21i5</guid>
      <description>&lt;p&gt;Hi there!&lt;/p&gt;

&lt;p&gt;Today, we will learn how to use a random integer generator in terraform module.&lt;/p&gt;

&lt;h2&gt;
  
  
  Situation -
&lt;/h2&gt;

&lt;p&gt;You are writing a module which takes a url as variable but needs to add a random userId (or any other thing) to the url. How do you achieve this in your terraform module?&lt;/p&gt;

&lt;h2&gt;
  
  
  Pre-requisites
&lt;/h2&gt;

&lt;p&gt;This post is NOT covering basics of terraform and module writing so some understanding of terraform is expected.&lt;br&gt;
It is assumed that you have terraform setup on your system and have an idea about how to write module.&lt;/p&gt;
&lt;h2&gt;
  
  
  Steps
&lt;/h2&gt;

&lt;ul&gt;
&lt;li&gt;Example module&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;Consider following datadog synthetics module&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;resource "datadog_synthetics_test" "test_template" {
    name = var.name
    request_definition {
        method = var.request_method
        url = var.start_url
    }
    // rest of the module
}
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;The above is a sample for creating a synthetic monitoring test on datadog. &lt;br&gt;
Assume you want to append a parameter &lt;code&gt;userId&lt;/code&gt; with random 6 digit number to the url.&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Add random_integer resource&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;Add a resource for random integer&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;resource "random_integer" "random_user_id" {
    max = 999999
    min = 100000

    keepers = {
        test_name = var.name
    }
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;&lt;a href="https://registry.terraform.io/providers/hashicorp/random/latest/docs/resources/integer" rel="noopener noreferrer"&gt;The documentation for random integer.&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;The above resource generates a 6-digit integer between 100000 and 999999. The &lt;code&gt;keepers&lt;/code&gt; field make sure that a new random number is generated each time a new &lt;code&gt;var.name&lt;/code&gt; is passed to module.&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Link random_integer resource to the example module&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;update the &lt;code&gt;url&lt;/code&gt; field to&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;url = "${var.start_url}/${random_integer.random_user_id.result}"
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;ul&gt;
&lt;li&gt;Checking&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;Use your module as usual and verify.&lt;/p&gt;

&lt;p&gt;That's all!&lt;/p&gt;

</description>
      <category>terraform</category>
    </item>
    <item>
      <title>Build a Budget App using Flutter and Appwrite</title>
      <dc:creator>Yogesh Sharma</dc:creator>
      <pubDate>Tue, 02 Nov 2021 02:21:12 +0000</pubDate>
      <link>https://forem.com/1995yogeshsharma/build-a-budget-app-using-flutter-and-appwrite-1hoi</link>
      <guid>https://forem.com/1995yogeshsharma/build-a-budget-app-using-flutter-and-appwrite-1hoi</guid>
      <description>&lt;h1&gt;
  
  
  Overview
&lt;/h1&gt;

&lt;p&gt;There are multiple components to think about when you are building an App.&lt;/p&gt;

&lt;p&gt;The broad component can be categorised as - &lt;br&gt;
1.) The code for app: How data is consumed, displaying the components.&lt;br&gt;
2.) The backend: Where the data is stored, api implementations&lt;/p&gt;

&lt;p&gt;For 1, we have multiple solutions like react, ionic, flutter, Android sdk etc.&lt;/p&gt;

&lt;p&gt;For 2, there are a lot of things to consider, how you handle authentication / authorisation, which database are you using etc. To make things simpler, there are frameworks like firebase and appwrite. &lt;/p&gt;

&lt;p&gt;In this blog we will learn about &lt;strong&gt;Flutter&lt;/strong&gt; for building the app and &lt;strong&gt;Appwrite&lt;/strong&gt; for its backend. Both Flutter and Appwrite are open-source projects and you can find them at -&lt;br&gt;
Appwrite - &lt;a href="https://github.com/appwrite/appwrite" rel="noopener noreferrer"&gt;https://github.com/appwrite/appwrite&lt;/a&gt;&lt;br&gt;
Flutter - &lt;a href="https://github.com/flutter/flutter" rel="noopener noreferrer"&gt;https://github.com/flutter/flutter&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;The best method to learn any new technology is to build something using it!&lt;/p&gt;

&lt;p&gt;So, in this blog we will make an app using flutter and appwrite.&lt;/p&gt;

&lt;p&gt;We will create a simple &lt;strong&gt;budget management&lt;/strong&gt; app which can do following things -&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Allow authentication for multiple user, thus different users can manage their budgets&lt;/li&gt;
&lt;li&gt;Show current balance and option to add expense / income&lt;/li&gt;
&lt;li&gt;Show the historical transactions done by the user&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;Alright, with these requirements in mind, we are ready to start building!!&lt;/p&gt;

&lt;p&gt;&lt;em&gt;pre-requisites&lt;/em&gt; - A little knowledge of flutter would be helpful but I will point to different resources as and when needed.&lt;/p&gt;
&lt;h1&gt;
  
  
  Building the Budget App
&lt;/h1&gt;

&lt;p&gt;You can find the final version of app in the repository - &lt;a href="https://github.com/1995YogeshSharma/budget-app" rel="noopener noreferrer"&gt;https://github.com/1995YogeshSharma/budget-app&lt;/a&gt;&lt;/p&gt;
&lt;h2&gt;
  
  
  Step 1: Dev Environment Setup
&lt;/h2&gt;

&lt;p&gt;Setting up both flutter and appwrite for local development is very easy. Appwrite comes as dockerized container and is very easy to use.&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Instruction to setup flutter - &lt;a href="https://flutter.dev/docs/get-started/install" rel="noopener noreferrer"&gt;https://flutter.dev/docs/get-started/install&lt;/a&gt;
&lt;/li&gt;
&lt;li&gt;Instruction to setup appwrite - &lt;a href="https://github.com/appwrite/appwrite#installation" rel="noopener noreferrer"&gt;https://github.com/appwrite/appwrite#installation&lt;/a&gt;
&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;I am using &lt;strong&gt;VS Code&lt;/strong&gt; as IDE but you can choose your preferred IDE.&lt;/p&gt;
&lt;h2&gt;
  
  
  Step 2: Build the layout using Flutter
&lt;/h2&gt;

&lt;p&gt;In this section, we build the layout of our app and use mock data. &lt;/p&gt;
&lt;h3&gt;
  
  
  2.1 Create a blank project
&lt;/h3&gt;

&lt;p&gt;Run the following command to create a blank flutter project&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;flutter create budget-app
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Strip down the code in &lt;code&gt;lib/main.dart&lt;/code&gt; to just have the outline code -&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;import 'package:flutter/material.dart';

void main() {
  // runApp(BudgetApp());
  runApp(new MaterialApp(
    home: new BudgetApp(),
  ));
}

// Our main widget
class BudgetApp extends StatefulWidget {
  @override
  _State createState() =&amp;gt; new _State();
}

class _State extends State&amp;lt;BudgetApp&amp;gt; {
  @override
  Widget build(BuildContext context) {
    return Scaffold(
      appBar: AppBar(
        title: Text('Budget App'),
      ),
      body: Container(
        child: Center(
          child: Text('Hello World'),
        ),
      ),
    );
  }
}
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;When you run the app, it should look like -&lt;br&gt;
&lt;a href="https://media2.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%2F22v57iv0123ro1ru2nj7.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.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%2F22v57iv0123ro1ru2nj7.png" alt="Step 1" width="800" height="1596"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;h3&gt;
  
  
  2.2 Build the layout
&lt;/h3&gt;

&lt;p&gt;You can find the updated code at - &lt;a href="https://github.com/1995YogeshSharma/budget-app/blob/main/blog_steps/step3_lib/main.dart" rel="noopener noreferrer"&gt;https://github.com/1995YogeshSharma/budget-app/blob/main/blog_steps/step3_lib/main.dart&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;On compiling the app should look like - &lt;br&gt;
&lt;a href="https://media2.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%2F9qq5od4g79jza3w51joq.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.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%2F9qq5od4g79jza3w51joq.png" alt=" " width="800" height="1590"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;h3&gt;
  
  
  2.3 Add the functionality
&lt;/h3&gt;

&lt;p&gt;Now, let's add the functionality to add expense / income and show the transaction history. We also add the bottom sheet view for the login / signup.&lt;/p&gt;

&lt;p&gt;You can find the updated code at -&lt;br&gt;
&lt;a href="https://github.com/1995YogeshSharma/budget-app/blob/main/blog_steps/step3_lib/main.dart" rel="noopener noreferrer"&gt;https://github.com/1995YogeshSharma/budget-app/blob/main/blog_steps/step3_lib/main.dart&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;On compiling the app should look like -&lt;br&gt;
&lt;a href="https://media2.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%2F5mms9vg96fga14kzxgc9.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.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%2F5mms9vg96fga14kzxgc9.png" alt=" " width="800" height="1600"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media2.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%2Fd62icsnndm48niigvlw9.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.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%2Fd62icsnndm48niigvlw9.png" alt=" " width="794" height="1600"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;h2&gt;
  
  
  Step 3: Add the Appwrite authentication and database
&lt;/h2&gt;

&lt;h3&gt;
  
  
  3.1: Add flutter project to Appwrite
&lt;/h3&gt;

&lt;p&gt;Follow the instructions at &lt;a href="https://appwrite.io/docs/getting-started-for-flutter" rel="noopener noreferrer"&gt;https://appwrite.io/docs/getting-started-for-flutter&lt;/a&gt; to setup your app connections with Appwrite.&lt;/p&gt;

&lt;h3&gt;
  
  
  3.2: Create required collections in Appwrite
&lt;/h3&gt;

&lt;p&gt;We will need two collections for the functionality &lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;balances : This collection will be used to store the current balance for each user. The Document has 'email' and 'balance'&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;Click on the left bar options in Appwrite UI to create your collection with following settings&lt;br&gt;
&lt;a href="https://media2.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%2F5gxgpfnmbs8sruuq63g6.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.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%2F5gxgpfnmbs8sruuq63g6.png" alt=" " width="800" height="1609"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;transactions : This collection will be used to store transactional history for a user. Each document will have 'email' filed and 'transactions' which is an array of transactions
&lt;img src="https://media2.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%2Fxw7xpn6izki290dr6id3.png" alt=" " width="800" height="1603"&gt;
&lt;/li&gt;
&lt;/ul&gt;

&lt;h3&gt;
  
  
  3.3: Add appwrite authentication to the app
&lt;/h3&gt;

&lt;p&gt;We need to create 'login', 'logout' and 'signup' functions in our appwrite client code and use them in the main file&lt;/p&gt;

&lt;p&gt;Code for appwrite client - &lt;a href="https://github.com/1995YogeshSharma/budget-app/blob/main/blog_steps/step6_lib/appwrite_client.dart" rel="noopener noreferrer"&gt;https://github.com/1995YogeshSharma/budget-app/blob/main/blog_steps/step6_lib/appwrite_client.dart&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Updated main file code - &lt;br&gt;
&lt;a href="https://github.com/1995YogeshSharma/budget-app/blob/main/blog_steps/step6_lib/main.dart" rel="noopener noreferrer"&gt;https://github.com/1995YogeshSharma/budget-app/blob/main/blog_steps/step6_lib/main.dart&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;We should be able to login and signup in our app now!&lt;br&gt;
&lt;a href="https://media2.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%2Fdlnedo9j9u44hwb9xylj.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.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%2Fdlnedo9j9u44hwb9xylj.png" alt=" " width="800" height="1594"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;h3&gt;
  
  
  3.4: Add appwrite database connections
&lt;/h3&gt;

&lt;p&gt;For transactions, we need to create a model which will be used to store the Transaction object and convert it to JSON to store it to appwrite database and back to object when fetched from appwrite&lt;/p&gt;

&lt;p&gt;The updated code is present at - &lt;a href="https://github.com/1995YogeshSharma/budget-app/tree/main/budget_app/lib" rel="noopener noreferrer"&gt;https://github.com/1995YogeshSharma/budget-app/tree/main/budget_app/lib&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;We have built our app now!&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;The final App&lt;/strong&gt;&lt;br&gt;
&lt;a href="https://media2.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%2F9vu806xshoyeh1i3rc1k.gif" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.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%2F9vu806xshoyeh1i3rc1k.gif" alt="App gif" width="320" height="636"&gt;&lt;/a&gt;&lt;/p&gt;

</description>
      <category>appwrite</category>
      <category>flutter</category>
      <category>mobileapp</category>
    </item>
  </channel>
</rss>
