rocket_client 0.0.1 copy "rocket_client: ^0.0.1" to clipboard
rocket_client: ^0.0.1 copied to clipboard

Simple http package for RocketModel or get json data.

example/lib/main.dart

import 'package:flutter/material.dart';
import 'dart:convert';
import 'package:rocket_client/rocket_client.dart';

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

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

  // This widget is the root of your application.
  @override
  Widget build(BuildContext context) {
    return MaterialApp(
      title: 'Rocket Client Example',
      theme: ThemeData(
        colorScheme: ColorScheme.fromSeed(seedColor: Colors.deepPurple),
        useMaterial3: true,
      ),
      home: const RocketClientExample(),
    );
  }
}

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

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

class RocketClientExampleState extends State<RocketClientExample> {
  final client = RocketClient(url: 'https://jsonplaceholder.typicode.com');
  bool isLoading = false;

  @override
  Widget build(BuildContext context) {
    return Scaffold(
      appBar: AppBar(
        title: const Text('Rocket Client Example'),
      ),
      body: Center(
        child: isLoading
            // ignore: prefer_const_constructors
            ? CircularProgressIndicator()
            : ElevatedButton(
                onPressed: () async {
                  isLoading = true;
                  setState(() {});
                  // Make a GET request to the /posts endpoint
                  final response = await client.request('posts');
                  isLoading = false;
                  setState(() {});
                  // Display the response in a dialog
                  // ignore: use_build_context_synchronously
                  showDialog(
                    context: context,
                    builder: (context) {
                      return AlertDialog(
                        title: const Text('Response'),
                        content: Text(json.encode(response)),
                        actions: [
                          TextButton(
                            onPressed: () {
                              Navigator.pop(context);
                            },
                            child: const Text('OK'),
                          ),
                        ],
                      );
                    },
                  );
                },
                child: const Text('Make Request'),
              ),
      ),
    );
  }
}
1
likes
0
pub points
18%
popularity

Publisher

verified publisherbixat.dev

Simple http package for RocketModel or get json data.

Homepage
Repository (GitHub)
View/report issues

License

unknown (license)

Dependencies

flutter, http, rocket_model

More

Packages that depend on rocket_client