Skip to content

Commit 2ce0e52

Browse files
committed
feat: Add server layer with API client, upload management, and configuration
- Implemented Server class for initialization and management of API interactions. - Created ServerConfig for app-level constants and configuration. - Added UploadProgress class to track upload status and progress. - Developed UploadNotifier for handling file uploads with progress tracking. - Introduced uploadProgressStreamProvider for real-time upload progress updates. - Established a new flutter_api_bridge package for easy access to the server layer. - Updated pubspec.yaml with necessary dependencies and dev dependencies.
1 parent 4cee8e0 commit 2ce0e52

25 files changed

Lines changed: 1716 additions & 0 deletions

.github/workflows/tests.yml

Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
name: Tests
2+
3+
on:
4+
push:
5+
branches: [ main, develop ]
6+
pull_request:
7+
branches: [ main, develop ]
8+
9+
jobs:
10+
test:
11+
runs-on: ubuntu-latest
12+
13+
steps:
14+
- uses: actions/checkout@v4
15+
16+
- name: Set up Flutter
17+
uses: subosito/flutter-action@v2
18+
with:
19+
flutter-version: '3.24.0'
20+
21+
- name: Get dependencies
22+
run: flutter pub get
23+
24+
- name: Analyze
25+
run: flutter analyze
26+
27+
- name: Run tests
28+
run: flutter test
29+
30+
- name: Check formatting
31+
run: dart format --set-exit-if-changed .
32+
33+
- name: Check pub publish
34+
run: flutter pub publish --dry-run

.gitignore

Lines changed: 90 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,90 @@
1+
# Dart / Flutter / Pub related
2+
.dart_tool/
3+
.flutter-plugins
4+
.flutter-plugins-dependencies
5+
.packages
6+
.pub-cache/
7+
.pub/
8+
build/
9+
coverage/
10+
*.iml
11+
*.lock
12+
13+
# IDE specific files
14+
.idea/
15+
.vscode/
16+
*.swp
17+
*.swo
18+
*~
19+
.DS_Store
20+
*.sublime-project
21+
*.sublime-workspace
22+
23+
# Android
24+
android/local.properties
25+
android/GeneratedPluginRegistrant.java
26+
android/.gradle/
27+
android/gradle.properties
28+
android/.idea/
29+
android/.classpath
30+
android/.project
31+
android/.settings/
32+
android/local.properties
33+
34+
# iOS
35+
ios/.symlinks/
36+
ios/.generated/
37+
ios/Flutter/Flutter.framework
38+
ios/Flutter/Flutter.podspec
39+
ios/Flutter/Generated.xcconfig
40+
ios/Flutter/ephemeralfluttermod/
41+
ios/Flutter/app.flx
42+
ios/Flutter/app.zip
43+
ios/Flutter/flutter_assets/
44+
ios/Flutter/flutter_export_environment.sh
45+
ios/ServiceDefinitions.json
46+
ios/Runner/GeneratedPluginRegistrant.*
47+
48+
# macOS
49+
macos/Flutter/Flutter.framework
50+
macos/Flutter/Flutter.podspec
51+
macos/Flutter/GeneratedPluginRegistrant.swift
52+
53+
# Windows
54+
windows/flutter/generated_plugins.cmake
55+
windows/flutter/generated_pluginregistrant.cc
56+
windows/flutter/generated_plugins.cmake
57+
windows/flutter/flutter.vcxproj
58+
windows/flutter/flutter.vcxproj.user
59+
60+
# Linux
61+
linux/flutter/generated_plugins.cmake
62+
63+
# Web
64+
lib/generated_plugin_registrant.dart
65+
66+
# Exceptions to above rules
67+
!/packages/**/example/android/gradlew
68+
!/packages/**/example/android/gradle-wrapper.jar
69+
!/example/android/gradlew
70+
!/example/android/gradle-wrapper.jar
71+
72+
# Hive related
73+
*.hive
74+
*.lock
75+
76+
# Generated files
77+
lib/generated/
78+
test/generated/
79+
80+
# OS
81+
.DS_Store
82+
Thumbs.db
83+
84+
# Local environment files
85+
.env
86+
.env.local
87+
88+
# Package specific
89+
*.tar.gz
90+
*.zip

.prettierrc

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
{
2+
"singleQuote": true,
3+
"trailingComma": "all",
4+
"printWidth": 140
5+
}

CHANGELOG.md

Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
# Changelog
2+
3+
All notable changes to this project will be documented in this file.
4+
5+
The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/),
6+
and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html).
7+
8+
## [0.1.0] - 2026-05-23
9+
10+
### Added
11+
12+
- Initial release of flutter_api_bridge
13+
- Lightweight and extensible HTTP client wrapper for Dart and Flutter
14+
- Built-in cookie management using `dio_cookie_manager` and `cookie_jar`
15+
- State management with `flutter_riverpod`
16+
- Local data persistence using `hive_flutter`
17+
- Automatic request caching
18+
- Request interceptor support via `dio`
19+
- Cookie jar storage and persistence
20+
- Upload progress tracking
21+
- Authentication strategy support
22+
- API request options customization
23+
- API envelope for structured responses
24+
25+
### Features
26+
27+
- `ApiClient` - Main HTTP client wrapper
28+
- `ApiCache` - Local caching layer
29+
- `CookieManager` - Automatic cookie handling
30+
- `UploadProvider` - File upload with progress tracking
31+
- `AuthStrategy` - Pluggable authentication
32+
- `ApiEnvelope` - Response envelope for standardized API responses
33+
- `ServerConfig` - Configuration management for API servers

LICENSE

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
MIT License
2+
3+
Copyright (c) 2026
4+
5+
Permission is hereby granted, free of charge, to any person obtaining a copy
6+
of this software and associated documentation files (the "Software"), to deal
7+
in the Software without restriction, including without limitation the rights
8+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9+
copies of the Software, and to permit persons to whom the Software is
10+
furnished to do so, subject to the following conditions:
11+
12+
The above copyright notice and this permission notice shall be included in all
13+
copies or substantial portions of the Software.
14+
15+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21+
SOFTWARE.

analysis_options.yaml

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
linter:
2+
rules:
3+
prefer_const_constructors: true
4+
prefer_const_declarations: true
5+
avoid_print: false
6+
analyzer:
7+
# errors:
8+
# duplicate_export: ignore
9+
# prefer_const_constructors: ignore
10+
# unnecessary_cast: ignore
11+
# unnecessary_null_comparison: ignore
12+
# unused_import: ignore
13+
# unused_local_variable: ignore

example/README.md

Lines changed: 45 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,45 @@
1+
# Flutter API Bridge Example
2+
3+
This directory contains example code demonstrating how to use the `flutter_api_bridge` package.
4+
5+
## Running the Example
6+
7+
```bash
8+
cd example
9+
flutter run
10+
```
11+
12+
## Features Demonstrated
13+
14+
- **Basic API Client Setup** - Configuring and initializing the API client
15+
- **Making Requests** - Performing HTTP requests with automatic caching
16+
- **Cookie Management** - Automatic cookie handling and persistence
17+
- **State Management** - Using Riverpod providers for state
18+
- **Error Handling** - Proper error handling for failed requests
19+
- **File Uploads** - Uploading files with progress tracking
20+
- **Authentication** - Implementing custom authentication strategies
21+
22+
## Example Usage
23+
24+
```dart
25+
import 'package:flutter_api_bridge/flutter_api_bridge.dart';
26+
27+
// Initialize the API client
28+
final apiClient = ApiClient(
29+
serverConfig: ServerConfig(
30+
baseUrl: 'https://api.example.com',
31+
),
32+
);
33+
34+
// Make a GET request
35+
final response = await apiClient.get('/users');
36+
37+
// Handle the response
38+
if (response.isSuccess) {
39+
print('Success: ${response.data}');
40+
} else {
41+
print('Error: ${response.error}');
42+
}
43+
```
44+
45+
For more detailed examples, see the files in this directory.

example/lib/main.dart

Lines changed: 94 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,94 @@
1+
import 'package:flutter/material.dart';
2+
import 'package:flutter_api_bridge/flutter_api_bridge.dart';
3+
4+
Future<void> main() async {
5+
WidgetsFlutterBinding.ensureInitialized();
6+
7+
await Server.init(
8+
baseUrl: 'https://jsonplaceholder.typicode.com',
9+
authStrategy: const CookieStrategy(),
10+
);
11+
12+
runApp(const MyApp());
13+
}
14+
15+
class MyApp extends StatelessWidget {
16+
const MyApp({super.key});
17+
18+
@override
19+
Widget build(BuildContext context) {
20+
return MaterialApp(
21+
title: 'Flutter API Bridge Example',
22+
theme: ThemeData(
23+
primarySwatch: Colors.blue,
24+
useMaterial3: true,
25+
),
26+
home: const MyHomePage(title: 'API Bridge Example'),
27+
);
28+
}
29+
}
30+
31+
class MyHomePage extends StatefulWidget {
32+
const MyHomePage({super.key, required this.title});
33+
34+
final String title;
35+
36+
@override
37+
State<MyHomePage> createState() => _MyHomePageState();
38+
}
39+
40+
class _MyHomePageState extends State<MyHomePage> {
41+
String _responseText = 'Press the button to make a request';
42+
bool _isLoading = false;
43+
44+
Future<void> _makeRequest() async {
45+
setState(() {
46+
_isLoading = true;
47+
_responseText = 'Loading...';
48+
});
49+
50+
try {
51+
// Example: Fetch a todo from the JSON Placeholder API
52+
final response = await ApiClient.instance('').get('/todos/1');
53+
54+
setState(() {
55+
_isLoading = false;
56+
_responseText = 'Response: ${response.data}';
57+
});
58+
} catch (e) {
59+
setState(() {
60+
_isLoading = false;
61+
_responseText = 'Error: $e';
62+
});
63+
}
64+
}
65+
66+
@override
67+
Widget build(BuildContext context) {
68+
return Scaffold(
69+
appBar: AppBar(
70+
title: Text(widget.title),
71+
),
72+
body: Center(
73+
child: Column(
74+
mainAxisAlignment: MainAxisAlignment.center,
75+
children: <Widget>[
76+
Padding(
77+
padding: const EdgeInsets.all(16.0),
78+
child: Text(
79+
_responseText,
80+
textAlign: TextAlign.center,
81+
style: Theme.of(context).textTheme.bodyMedium,
82+
),
83+
),
84+
],
85+
),
86+
),
87+
floatingActionButton: FloatingActionButton(
88+
onPressed: _isLoading ? null : _makeRequest,
89+
tooltip: 'Make API Request',
90+
child: const Icon(Icons.api),
91+
),
92+
);
93+
}
94+
}

example/pubspec.yaml

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
name: flutter_api_bridge_example
2+
description: Example application demonstrating the flutter_api_bridge package.
3+
version: 1.0.0+1
4+
publish_to: none
5+
6+
environment:
7+
sdk: ^3.6.0
8+
flutter: '>=3.24.0'
9+
10+
dependencies:
11+
flutter:
12+
sdk: flutter
13+
14+
# Local path dependency - points to the parent package
15+
flutter_api_bridge:
16+
path: ..
17+
18+
dev_dependencies:
19+
flutter_test:
20+
sdk: flutter
21+
22+
flutter:
23+
uses-material-design: true

0 commit comments

Comments
 (0)