flashapi_generator 0.1.0 copy "flashapi_generator: ^0.1.0" to clipboard
flashapi_generator: ^0.1.0 copied to clipboard

A Flutter plugin for API-driven BLoC generation with VS Code extension integration

example/lib/main.dart

import 'package:flutter/material.dart';
import 'package:flashapi/flashapi.dart';

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

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

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

class _MyAppState extends State<MyApp> {
  final _flashapiPlugin = Flashapi();
  String _platformVersion = 'Unknown';
  String _apiResponse = 'No API call made yet';
  bool _isLoading = false;

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

  Future<void> initPlatformState() async {
    String platformVersion;
    try {
      platformVersion = await _flashapiPlugin.getPlatformVersion() ??
          'Unknown platform version';
    } on Exception {
      platformVersion = 'Failed to get platform version.';
    }

    if (!mounted) return;

    setState(() {
      _platformVersion = platformVersion;
    });
  }

  Future<void> _makeApiCall() async {
    setState(() {
      _isLoading = true;
    });

    try {
      final response = await Flashapi.makeRequest(
        url: 'https://jsonplaceholder.typicode.com/posts/1',
        method: 'GET',
      );

      setState(() {
        _apiResponse = response ?? 'No response received';
        _isLoading = false;
      });
    } catch (e) {
      setState(() {
        _apiResponse = 'Error: $e';
        _isLoading = false;
      });
    }
  }

  @override
  Widget build(BuildContext context) {
    return MaterialApp(
      home: Scaffold(
        appBar: AppBar(
          title: const Text('FlashAPI Example'),
        ),
        body: Padding(
          padding: const EdgeInsets.all(16.0),
          child: Column(
            crossAxisAlignment: CrossAxisAlignment.stretch,
            children: [
              Card(
                child: Padding(
                  padding: const EdgeInsets.all(16.0),
                  child: Column(
                    children: [
                      const Text('Platform Info:',
                          style: TextStyle(fontWeight: FontWeight.bold)),
                      const SizedBox(height: 8),
                      Text(_platformVersion),
                    ],
                  ),
                ),
              ),
              const SizedBox(height: 16),
              Card(
                child: Padding(
                  padding: const EdgeInsets.all(16.0),
                  child: Column(
                    children: [
                      const Text('API Test:',
                          style: TextStyle(fontWeight: FontWeight.bold)),
                      const SizedBox(height: 8),
                      ElevatedButton(
                        onPressed: _isLoading ? null : _makeApiCall,
                        child: _isLoading
                            ? const CircularProgressIndicator()
                            : const Text('Make GET Request'),
                      ),
                      const SizedBox(height: 8),
                      const Text('Response:',
                          style: TextStyle(fontWeight: FontWeight.bold)),
                      const SizedBox(height: 4),
                      Container(
                        width: double.infinity,
                        padding: const EdgeInsets.all(8),
                        decoration: BoxDecoration(
                          color: Colors.grey[100],
                          borderRadius: BorderRadius.circular(4),
                        ),
                        child: Text(
                          _apiResponse,
                          style: const TextStyle(fontSize: 12),
                        ),
                      ),
                    ],
                  ),
                ),
              ),
              const SizedBox(height: 16),
              const Card(
                child: Padding(
                  padding: EdgeInsets.all(16.0),
                  child: Column(
                    children: [
                      Text('VS Code Extension Usage:',
                          style: TextStyle(fontWeight: FontWeight.bold)),
                      SizedBox(height: 8),
                      Text('1. Add flashapi to your pubspec.yaml'),
                      Text('2. Use Ctrl+Shift+P and search "FlashApi"'),
                      Text('3. Enter URL and select HTTP method'),
                      Text('4. Generate Flutter BLoC files'),
                    ],
                  ),
                ),
              ),
            ],
          ),
        ),
      ),
    );
  }
}
2
likes
140
points
141
downloads

Publisher

unverified uploader

Weekly Downloads

A Flutter plugin for API-driven BLoC generation with VS Code extension integration

Documentation

API reference

License

MIT (license)

Dependencies

flutter, plugin_platform_interface

More

Packages that depend on flashapi_generator

Packages that implement flashapi_generator