lynk_io 0.0.7 copy "lynk_io: ^0.0.7" to clipboard
lynk_io: ^0.0.7 copied to clipboard

A lightweight and modular Flutter networking library for clean API communication using Dio.

example/lynk_io_example.dart

import 'package:flutter_dotenv/flutter_dotenv.dart';
import 'package:lynk_io/lynk_io.dart';

Future<void> main() async {
  await dotenv.load();
  final baseUrl = dotenv.env['API_BASE_URL'] ?? '';

  setupDependencies(baseUrl: baseUrl);

  final api = locator<ApiClient>();

  try {
    final response = await api.get<List<ItemModel>>(
      endpoint: '/todos',
      fromJson: (json) {
        final rawList = json as List;
        return rawList.map((e) => ItemModel.fromJson(e)).toList();
      },
    );

    if (response.isSuccess && response.data != null) {
      for (final item in response.data!) {
        print('Todo: ${item.title} - Completed: ${item.completed}');
      }
    } else {
      print('API Error: ${response.error?.message ?? 'Unknown error'}');
    }
  } catch (e) {
    print('Exception occurred: $e');
  }
}


class ItemModel {
  final int id;
  final String title;
  final bool completed;

  ItemModel({
    required this.id,
    required this.title,
    required this.completed,
  });

  factory ItemModel.fromJson(Map<String, dynamic> json) => ItemModel(
    id: json['id'] as int,
    title: json['title'] as String,
    completed: json['completed'] as bool,
  );
}
6
likes
140
points
5
downloads

Publisher

unverified uploader

Weekly Downloads

A lightweight and modular Flutter networking library for clean API communication using Dio.

Repository (GitHub)
View/report issues

Documentation

API reference

License

MIT (license)

Dependencies

connectivity_plus, dio, flutter, flutter_dotenv, get_it, logger, meta

More

Packages that depend on lynk_io