Home Blog Page 13

7 Practices to reduce flutter app size

0
flutter app size reduce

To Reducing the size of your Flutter app is a major task and crucial for improving performance, decreasing load times, and enhancing user experience. Below are seven practices to help you achieve a smaller flutter app size:

1. Use SVG Images:

Use SVG Images instead of PNG or JPEG images. As SVG images are vector images, which means they can be scaled to any size without losing image quality. This makes them much smaller than PNG or JPEG images, which are raster images.

2. Compress Images:

Compress your images. Even if you’re using svg images, you can still compress them to further reduced size. There are many online tools that can help you to compress SVG images.

3. Remove unused resources:

Remove unused resources. Before publishing your application, take a look at all of the resources that you’re including in it. Are there any resource that you’re not actually using? if so, remove them. This will help to reduce the size of your app.

4. Use code obfuscator:

use a code obfuscator. A code obfuscator can help to reduce the size of your app by making your code more compact. This is done by remaining vairables, functions, and other elements of your code.

5. use Android App Bundles:

Use Android App Bundles. Android App bundles(AAB’s) are a new way to publish or distribute Android apps in playstore. AAB’s allow you to split your application into multiple APK’s each of which is optimized for a specific devices configuation. This can help to reduce the size of your app from users with older devices.

6. Avoid using large images:

Avoid using large images for icons or splash screens. Icons and splash screens are often the first things that users see when they launch process and make your app feel sluggish.

7. use lazy loading:

using lazy loading is a technique that allows you to load images or other resources only when they’re needed. This can help to reduce flutter app size and even app performance is increased.

Difference between Axios and Fetch in making HTTP Request

0
Different Between Axios & fetch
Different Between Axios & fetch

Hi Guy’s Welcome to Proto Coders Point, In this article let’s check out the difference between the most commonly used http module/library i.e. axios and fetch.

What is Axios ?

Axios is basically a Nodejs Library/Module, which is been used to make HTTP requests, It provide a various types of HTTP requests, such as GET, POST, PUT, DELETE etc. Axios is used to fetch data from external servers.

To use Axios in NodeJS we must install the library and then import it where required

npm install axios

How to use Axios in NodeJS

Once Nodejs Axios library is installed, you need top import it into your nodeJS. Below is snippet code for better understanding:

const axios = require('axios');

axios.get('https://api.example.com/data')
  .then(response => {
    console.log(response.data);
  })
  .catch(error => {
    console.error(error);
  });

What is fetch?

fetch function is an in-built global function in nodejs, That helps us in making asynchronois HTTP requests and handle responses.

To use fetch in nodejs you need to import the ‘node-fetch‘ module, and then make http calls like GET or POST method. Below is a code snippet example

const fetch = require('node-fetch');

fetch('https://api.example.com/data')
  .then(response => response.json())
  .then(data => {
    console.log(data);
  })
  .catch(error => {
    console.error(error);
  });

Difference Between Axios & Fetch

Here are some key differences between the Axios & Fetch:

1. Syntax and ease of use:


Axios: Axios provides a simplist way in making HTTP requests. The make advantage of using Axios to make http call is it uses promises which make it a higher level of abstraction, and make the code clean and easily understandable. Syntax & code example is above.


Fetch: Fetch is a in-built module of web API in any modern Web browsers that provides a native way to make HTTP requests. Syntax & code example is above.

2. Browser support:


Axios: Axios library is fully supports on any the browsers and even if the website is loaded into old version of browser it works perfect fine.


Fetch: While the fetch function is commonly supported by modern web browsers, it may necessitate the use of a polyfill or transpiler in order to function correctly in older browser versions.

3. Request and response handling:


Axios: Axios provides in-built feature to make http request and response interceptors, which helps developer to easily allow to modify any requests or responses that is made to API hit. It also supports automatic transformation of request and response data, such as JSON parsing or serialization.


Fetch: Fetch is an lower-level API as it does not have any built-in interceptors with it. develoepr need to manually handle all the request and response modifications. It also requires additional steps to parse or serialize data.

4. Error handling:


Axios: Axios has built-in error handling and automatically rejects the promise on HTTP error status codes (e.g., 404 or 500). It also allows you to define global error handling for all requests.


Fetch: Fetch does not reject the promise on HTTP error status codes by default. You need to check the response status manually and handle errors accordingly.

5. Cross-origin requests:


Axios: Axios supports cross-origin requests by default and handles CORS (Cross-Origin Resource Sharing) headers automatically.


Fetch: Fetch also supports cross-origin requests but requires explicit handling of CORS headers and may involve additional configuration.

In summary, Axios provides a more user-friendly and feature-rich API for making HTTP requests. It offers better error handling, automatic data transformation, and built-in interceptors. Fetch, on the other hand, is a native browser API with a lower-level interface and requires more manual handling for certain tasks.

Flutter Neumorphism – 3D Button

0
Flutter Neumorphirm - 3D Button.
Flutter Neumorphirm - 3D Button.

Hi Guy’s Welcome to Proto Coders Point, In this Flutter Article let’s learn How to Create Neuporphism button.

Neumorphism in Flutter

Flutter Neomorphism is an UI element that is created by applying Shadows to give a Elevation effect to any Widget.

Let’s Understand neumorphism with a container, Two opposite edges, On is in front of light source while another is opposite, This create a shadow on the other end of the container.

In this Article we will give a neumorphism effect to a container making it a 3D button in flutter.

Complete Source Code – Flutter Neumorphic Button

import 'dart:ui';

import 'package:flutter/material.dart';

void main() {
  runApp(const MyApp());
}

class MyApp extends StatelessWidget {
  const MyApp({Key? key}) : super(key: key);

  // This widget is the root of your application.
  @override
  Widget build(BuildContext context) {
    return MaterialApp(
      title: 'Flutter Demo',
      theme: ThemeData(

        primarySwatch: Colors.blue,
      ),
      home: const MyHomePage(),
      debugShowCheckedModeBanner: false,
    );
  }
}

class MyHomePage extends StatefulWidget {
  const MyHomePage({Key? key}) : super(key: key);

  @override
  _MyHomePageState createState() => _MyHomePageState();
}

class _MyHomePageState extends State<MyHomePage> {
  var darkColors = Color(0xFF000A1F);
  var lightColors = Color(0xFF5A86EA);
  var isPressed = false;
  @override
  Widget build(BuildContext context) {
    return Scaffold(
      backgroundColor: Colors.indigo,
        body: Center(
          child: GestureDetector(
            onTapUp: (val){
              setState(() {
                isPressed = false;

              });

            },
            onTapDown: (val){
              setState(() {
                isPressed = true;
              });

            },
            child: AnimatedContainer(
              duration: Duration(milliseconds: 100),
              width: 200,
              height: 200,
              padding: EdgeInsets.all(20.0),
              decoration: BoxDecoration(
                color: darkColors,
                borderRadius: BorderRadius.circular(20.0),
                boxShadow: isPressed ? null : [
                  BoxShadow(color: Colors.white,offset: Offset(-3,-3),blurRadius: 10.0,spreadRadius: 3.0),
                  BoxShadow(color: darkColors,offset: Offset(3,3),blurRadius: 10.0,spreadRadius: 3.0)
                ],
                gradient: LinearGradient(
                  begin: Alignment.topLeft,
                  end: Alignment.bottomRight,
                  colors: [
                    isPressed ? lightColors : darkColors,
                    isPressed ? darkColors : lightColors
                  ]
                )
              ),
            ),
          ),
        )
    );
  }
}

So, In above flutter code, we have a square shaped AnimatedContainer at the center of the screen.

In the container widget we will use decoration: property with BoxDecoration to make the normal container a neumorphism container.

In BoxDecoration, We are using:

  • color: To give color to the container.
  • borderRadius: To give a Circular Radius to the container.
  • boxShadow: To Apply a meumorphism shadow effect to the container.
  • gradient: linear gradient from topLeft to bottonRight a light & dark color gredient effect.

That make a normal container a neumorphism container & then to give a click/onTop feel I have Simply wrapped the AnimatedContainer with GestureDetector & make few changes in color when user tap by using onTapUp() & onTopDown() methods.

Video Tutorial

Blur Background in flutter using BackdropFilter widget

0
blur background in flutter using backdropfilter

Hi Guy’s Welcome to Proto Coders Point, In this flutter article we will learn how to Blur a background in flutter by using "BackdropFilter" widget with imageFilter.blur property.

Code to Blur Background in flutter

import 'dart:ui';

import 'package:flutter/material.dart';

void main() {
  runApp(MyApp());
}

class MyApp extends StatelessWidget {
  @override
  Widget build(BuildContext context) {
    return MaterialApp(
      home: Scaffold(
        body: Stack(
          children: [
            // Background widget
            Image.asset(
              'assets/background_image.jpg',
              fit: BoxFit.cover,
              width: double.infinity,
              height: double.infinity,
            ),

            // BackdropFilter to blur the background
            BackdropFilter(
              filter: ImageFilter.blur(sigmaX: 5, sigmaY: 5),
              child: Container(
                color: Colors.black.withOpacity(0.5), // Adjust the opacity as needed
              ),
            ),

            // Content widget
            Center(
              child: Text(
                'Hello, World!',
                style: TextStyle(fontSize: 30, color: Colors.white),
              ),
            ),
          ],
        ),
      ),
    );
  }
}

Output

blur background in flutter using backdropfilter

The Above Code Explanation to blur a background in flutter

  1. Use a Stack widget as root widget. By using Stack widget we can stack multiple widget on top on each other.
  2. Add a Image widget as a first child of the Stack. This will be backgroud widget that will get blurred.
  3. Use BackdropFilter widget. The BackdropFilter widget applies a filter to the widget that come behind it.
  4. Set the filter property of the BackdropFilter widget to the ImageFilter.blur constructor, specifying the amount of blur you want. You can adjust the sigmaX and sigmaY values to control the blur intensity.

Video Tutorial

Image Blur Background in Flutter

0
flutter blur background image
flutter blur background image

Hi Guy’s Welcome to Proto Coders Point, In this flutter article let’s learn how to blur an image in flutter, Basically will learn how to apply blur filter to a Image Widget.

Blur Background Image in flutter

In order to give blur effect to a Image, We will make use of ImageFiltered Widget with imageFilter: property and apply ImageFilter.blur() with X & Y axis Sigma on top of Image Widget as Parent widget.

ImageFilter.blur constructor

ImageFilter.blur(
                  sigmaX: 10,
                  sigmaY: 10
)

Complete Source Code – Apply Blur Background Image

import 'dart:ui';

import 'package:flutter/material.dart';

void main() {
  runApp(const MyApp());
}

class MyApp extends StatelessWidget {
  const MyApp({Key? key}) : super(key: key);

  // This widget is the root of your application.
  @override
  Widget build(BuildContext context) {
    return MaterialApp(
      title: 'Flutter Demo',
      theme: ThemeData(

        primarySwatch: Colors.blue,
      ),
      home: const MyHomePage(),
      debugShowCheckedModeBanner: false,
    );
  }
}

class MyHomePage extends StatefulWidget {
  const MyHomePage({Key? key}) : super(key: key);

  @override
  _MyHomePageState createState() => _MyHomePageState();
}

class _MyHomePageState extends State<MyHomePage> {

  @override
  Widget build(BuildContext context) {
    return Scaffold(
      body: Stack(
        alignment: Alignment.center,
        children: [
          SizedBox.expand(
            child: ImageFiltered(
                imageFilter: ImageFilter.blur(
                  sigmaX: 10,
                  sigmaY: 10
                ),
            child: Image.network(
                'https://media.istockphoto.com/id/1146517111/photo/taj-mahal-mausoleum-in-agra.jpg?s=612x612&w=0&k=20&c=vcIjhwUrNyjoKbGbAQ5sOcEzDUgOfCsm9ySmJ8gNeRk=',
              fit: BoxFit.fill,
            )),
          ),
           Image.network('https://media.istockphoto.com/id/1146517111/photo/taj-mahal-mausoleum-in-agra.jpg?s=612x612&w=0&k=20&c=vcIjhwUrNyjoKbGbAQ5sOcEzDUgOfCsm9ySmJ8gNeRk=')
        ],
      )
    );
  }
}

Output

blur image background in flutter

Video Tutorial

Flutter Draw Bezier Curve with ClipPath

0
Flutter Bezier Curve Wave using customClipper
Flutter Bezier Curve Wave using customClipper

Hi Guy’s Welcome to Proto Coders Point, In this flutter tutorial we learn how to create a Bezier Curve which looks like a water wave.

To draw a Bezier curve in flutter we will be using ‘ClipPath’ widget using we can give any shape to it’s child(Container).

Step’s

  • Create a class that extends CustomClipper class
  • Override CustomClipper class methods i.e. getClips and shouldReclip
  • In getClip() method define the cliping shape
  • then finally provide the customclipper class to ClipPath Widget

CustomClipper Class

The Below clip path code will give a curve shape, that will can then apply to ClipPath widget

path.lineTo(0, size.height * 0.75); Will draw a straight line from current position to the height been defined.

The first path.quadraticBezierTo() will draw a first half of Bezier curve from current point.

The second path.quadraticBezierTo() draw a second half Bezier curve making it look like a water wave.

then finally path.lineTo(size.width,0); draw a straight line from the last curve point to the top-right corner that’s completes the clipPath class.

class BezierClipper extends CustomClipper<Path>{
  @override
  Path getClip(Size size) {
   Path path = Path();
   path.lineTo(0, size.height * 0.75);

   path.quadraticBezierTo(
       size.width * 0.25,
       size.height * 0.5,
       size.width * 0.5,
       size.height * 0.75
   );
   //
   path.quadraticBezierTo(
       size.width * 0.75,
       size.height * 1,
       size.width,
       size.height * 0.75
   );
   path.lineTo(size.width,0);
   return path;
  }

  @override
  bool shouldReclip(covariant CustomClipper<Path> oldClipper) {
    // TODO: implement shouldReclip
    return true;
  }
}

Use CustomClipper class into ClipPath widget to clips

Scaffold(
      body: Stack(
        children: [
          Container(
            color: Colors.blueAccent,
          ),
          ClipPath(
            clipper: BezierClipper(),
            child: Container(
              color: Colors.black,
              height: 400,
            ),
          )
        ],
      )
    );

Output