flutter_http_caching 0.0.2 copy "flutter_http_caching: ^0.0.2" to clipboard
flutter_http_caching: ^0.0.2 copied to clipboard

outdated

Best way for caching http request

example/lib/main.dart

import 'package:example/network/api_repo.dart';
import 'package:flutter/material.dart';
void main() {
  runApp(const MyApp());
}

class MyApp extends StatefulWidget {
  const MyApp({super.key});

  @override
  State<MyApp> createState() => _MyAppState();
}

class _MyAppState extends State<MyApp> {

  @override
  Widget build(BuildContext context) {
    return MaterialApp(
      title: 'Flutter Demo',
      theme: ThemeData(

        primarySwatch: Colors.blue,
      ),
      home: const MyHomePage(title: 'Flutter Demo Home Page'),
    );
  }


}

class MyHomePage extends StatefulWidget {
  const MyHomePage({super.key, required this.title});


  final String title;

  @override
  State<MyHomePage> createState() => _MyHomePageState();
}

class _MyHomePageState extends State<MyHomePage> {
  String? response;

  @override
  void initState() {
    getResponseData();
    super.initState();
  }

  getResponseData() async{
  var res =  await getNewsData();
  setState(() {
    response = res;
  });
  }

  @override
  Widget build(BuildContext context) {

    return Scaffold(
      appBar: AppBar(
        title: Text(widget.title),
      ),
      body: Container(
        child: Text(response ?? ''),
      ),
    );
  }
}