A ready-made structure that holds HTTP requests.

Overview

A ready-made structure that holds HTTP requests.

Usage

import 'package:flutter/material.dart';
import 'package:uigitdev_request_holder/src/http_request_holder.dart';

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

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

  @override
  Widget build(BuildContext context) {
    return MaterialApp(
      home: Scaffold(
        body: SizedBox(
          width: double.maxFinite,
          child: Column(
            mainAxisAlignment: MainAxisAlignment.center,
            crossAxisAlignment: CrossAxisAlignment.center,
            children: [
              _postDataBuilder(),
            ],
          ),
        ),
      ),
    );
  }

  Widget _postDataBuilder() {
    return FutureBuilder<PostModel?>(
      future: PostRequest(id: 1).send(),
      builder: (context, snapshot) {
        if (snapshot.connectionState == ConnectionState.done) {
          if (snapshot.hasData) {
            return Text(snapshot.data!.title.toString());
          } else {
            if (snapshot.hasError) {
              return Text('Error: ${snapshot.error}');
            } else {
              return const Text('No data');
            }
          }
        } else {
          return const Text('Loading');
        }
      },
    );
  }
}

class PostModel {
  int? userId;
  int? id;
  String? title;
  String? body;

  PostModel.fromJson(Map<String, dynamic> json) {
    userId = json['userId'];
    id = json['id'];
    title = json['title'];
    body = json['body'];
  }
}

class PostRequest extends HTTPRequestHolder<PostModel> {
  final int id;

  PostRequest({required this.id});

  @override
  HTTPRequestProtocol get protocol => HTTPRequestProtocol.HTTP;

  @override
  String get host => 'jsonplaceholder.typicode.com';

  @override
  String get path => '/posts/$id';

  @override
  HTTPRequestMethod get method => HTTPRequestMethod.GET;

  @override
  JSONParserType get parserType => JSONParserType.MAP;

  @override
  JSONMapParser<PostModel>? get mapParser => PostModel.fromJson;
}
You might also like...

Flutter Architecture Blueprints is a project that introduces MVVM architecture and project structure approaches to developing Flutter apps.

Flutter Architecture Blueprints is a project that introduces MVVM architecture and project structure approaches to developing Flutter apps.

Flutter Architecture Blueprints Flutter Architecture Blueprints is a project that introduces MVVM architecture and project structure approaches to dev

Apr 9, 2022

Flutter App Templete is a project that introduces an approach to architecture and project structure for developing Flutter apps.

Flutter App Template "Flutter App Template" is a project that introduces an approach to architecture and project structure for developing Flutter apps

Jan 5, 2023

Flutter template project - Simple ToDo app with scalable project structure.

Flutter template project - Simple ToDo app with scalable project structure.

Flutter Template Flutter template project - A simple TODO list app. This template provides simple UI and scalable project structure that goes beyond t

Nov 21, 2022

Project Structure Auth Generator For Flutter

get_structure_generator Project Structure Auto Generator This is not the package

Mar 22, 2022

Flutter Architecture Blueprints is a project that introduces MVVM architecture and project structure approaches to developing Flutter apps.

Flutter Architecture Blueprints is a project that introduces MVVM architecture and project structure approaches to developing Flutter apps.

Flutter Architecture Blueprints Flutter Architecture Blueprints is a project that introduces MVVM architecture and project structure approaches to dev

Dec 31, 2022

Flutter-Wings - This is a structure for flutter developers developed by Invention Technology.

Flutter : Wings File Structure About Wings installation simple use Advance Use About Wings Wings is an MVC file structure build with getx for flutter

Nov 20, 2022

A flutter demo app to practice Map data structure and its common operations

Map Operations A flutter demo app to practice Map data structure and its common operations Developer Alexander Sosa (https://www.linkedin.com/in/alexa

Jan 3, 2022

Flutter micro app - A package to speed up the creation of micro frontend(or independent features) structure in Flutter applications

Flutter micro app - A package to speed up the creation of micro frontend(or independent features) structure in Flutter applications

A package to speed up the creation of micro frontend(or independent features) st

Dec 22, 2022

SIMPLE TODO APP WITH FEATURE WISE FOLDER STRUCTURE

SIMPLE TODO APP WITH FEATURE WISE FOLDER STRUCTURE

SIMPLE TODO APP WITH FEATURE WISE FOLDER STRUCTURE

May 13, 2022
Comments
  • Changing settings method structure

    Changing settings method structure

    Move dummy option from settings to a new abstract method.

    Reason: The reason is to my code needs to be readable. Settings is not the best place for this function.

    opened by uigitdev 0
Owner
Uigitdev
Software Developer | #uigitdev
Uigitdev
An easy-to-use flutter http network requests handler with more functionality than http but more simpler than dio.

network_requests An easy-to-use flutter http network requests handler with more functionality than http but more simpler than dio. Platform Supported

Coder_Manuel 3 Dec 15, 2022
A composable API for making HTTP requests in Dart.

A composable, Future-based library for making HTTP requests. This package contains a set of high-level functions and classes that make it easy to cons

Dart 888 Dec 26, 2022
This example handles HTTP GET requests by responding with 'Hello, World!'

Hello world example This example handles HTTP GET requests by responding with 'Hello, World!'. // lib/functions.dart import 'package:functions_framewo

TryIt (김동현) 0 May 25, 2022
Charlatan - A library for configuring and providing fake http responses to your dio HTTP client.

charlatan This package provides the ability to configure and return fake HTTP responses from your Dio HTTP Client. This makes it easy to test the beha

Betterment 14 Nov 28, 2022
A google browser clone which is made by using flutter and fetching the google search api for the search requests.

google_clone A new Flutter project. Project Preview Getting Started This project is a starting point for a Flutter application. A few resources to get

Priyam Soni 2 May 31, 2022
A movies app made with Flutter focused on solid software structure patterns.

Flutter Movies App An application made with Flutter to practice the principles of Clean Architecture. Even being focused on architecture, the project

Márcio Valim 59 Dec 12, 2022
A Flutter boilerplate made by GeniusCrew BV and inspired to the Clean Architecture structure.

GeniusArchitecture This is a boilerplate project created in flutter using Provider, Firebase, Dio, and some fundamentals of Robert C Martin's Clean Ar

GeniusCrew 10 Dec 16, 2022
🌈 Repository for a compass project, basically an App for displaying bank transfers, with API requests, Flag persistence, Infinite Scroll, Error Handling, Unit Tests, Extract Sharing working with SOLID, BLoC and Designer Patterns.

?? Green Bank Aplicação desenvolvida em Flutter com intuito de trabalhar conexão com API, Gerenciamento de estado usando BLoC, Refatoração, Arquitetur

André Guerra Santos 28 Oct 7, 2022
Listen to remote Flutter GTK application instances' command-line arguments and file open requests.

gtk_application This package allows the primary Flutter GTK application instance to listen to remote application instances' command-line arguments and

null 12 Dec 15, 2022
This is template toolkit fasten your project setup within a minute. The toolkit is based on MVC+S structure.

BWeird Flutter Toolkit! Hi! From a Weirder Flutter has been great on mobile development and I took this opportunity to make it even greater with templ

Setak Varaman !!!! 6 Aug 22, 2021