AppForge Kit ๐ ๏ธ๐
A production-ready foundation kit for Flutter applications. Eliminates boilerplate for Multi-Environment configuration, Automatic Auth Routing, Global Crash Boundaries, Inactivity & Session Guards, and Context-less Navigation.
โก Features
- ๐ Multi-Environment Management: One-line config for Dev, Staging, and Production environments with auto-toggled logging, base URLs, and on-screen environment badges.
- ๐ก๏ธ Global Crash Boundary: Eliminates the ugly red screen of death in production with a polished fallback screen, copyable stack trace, and Crashlytics/Sentry hooks.
- ๐ช Ready-Made AuthGate: Manages the initial Splash -> Token Verification -> Login / Home routing sequence seamlessly without boilerplate.
- โณ Inactivity & Session Guard: Monitors user interactions across the app and triggers auto-logout or PIN lock when inactive for a configured duration.
- ๐งญ Context-less Navigation (
AppForgeNav): Navigate (to,replace,toAndClearStack,back) from anywhere without needing aBuildContext. - ๐ AppForgeLogger: Formatted, leveled console logger with emojis and timestamps, automatically silenced in production.
๐ฆ Installation
Add appforge_kit to your pubspec.yaml:
dependencies:
appforge_kit: ^0.0.1
๐ Quick Start
1. Initialize in main()
import 'package:flutter/material.dart';
import 'package:appforge_kit/appforge_kit.dart';
void main() async {
WidgetsFlutterBinding.ensureInitialized();
// Initialize AppForge
await AppForge.init(
environment: AppEnvironment.dev(
baseUrl: 'https://dev.api.example.com',
showBanner: true, // Shows small "DEV" badge in corner
),
onCrash: (error, stack) {
// Send unhandled errors to Firebase Crashlytics or Sentry
},
);
runApp(const MyApp());
}
2. Configure MaterialApp with AppForge.builder()
class MyApp extends StatelessWidget {
const MyApp({super.key});
@override
Widget build(BuildContext context) {
return MaterialApp(
navigatorKey: AppForge.navigatorKey, // Context-less navigation
builder: AppForge.builder(), // Injects Crash Boundary & Env Badge
home: AuthGate(
minSplashDuration: const Duration(seconds: 1),
isAuthenticated: () async {
// Check token or secure storage
return false;
},
splashScreen: const SplashScreen(),
loginScreen: const LoginScreen(),
homeScreen: const HomeScreen(),
),
);
}
}
๐ Feature Guide
1. Multi-Environment Support
AppForge provides standard factory constructors for common environments:
// Development
AppEnvironment.dev(
baseUrl: 'https://dev.api.com',
showBanner: true,
enableLogging: true,
);
// Staging / QA
AppEnvironment.staging(
baseUrl: 'https://qa.api.com',
showBanner: true,
);
// Production
AppEnvironment.prod(
baseUrl: 'https://api.com',
showBanner: false,
enableLogging: false,
);
// Custom
AppEnvironment(
type: EnvironmentType.custom,
name: 'SANDBOX',
baseUrl: 'https://sandbox.api.com',
showBanner: true,
extra: {'stripeKey': 'pk_test_...'},
);
Access details anywhere in your code:
final url = AppForge.baseUrl;
if (AppForge.isDev) {
// Developer tools
}
2. Ready-Made AuthGate
The AuthGate widget handles the common sequence of app launch:
- Shows
splashScreen(with customizableminSplashDurationto prevent flickering). - Asynchronously invokes
isAuthenticated. - Seamlessly transitions to
homeScreenorloginScreen.
AuthGate(
controller: authGateController, // Optional programmatic control
minSplashDuration: const Duration(milliseconds: 1200),
isAuthenticated: () async {
final token = await SecureStorage.read('jwt');
return token != null && token.isNotEmpty;
},
splashScreen: const SplashScreen(),
loginScreen: const LoginScreen(),
homeScreen: const HomeScreen(),
)
To update the auth state dynamically (e.g. on logout/login):
authGateController.setAuthenticated(false); // Transitions back to login
3. Inactivity & Session Timeout
Ideal for banking, medical, or security-sensitive apps:
AppInactivityDetector(
timeoutDuration: const Duration(minutes: 5),
onTimeout: () {
// Auto logout or prompt PIN dialog
AppForgeNav.toAndClearStack(const LockScreen());
},
child: const MyApp(),
)
4. Context-Less Navigation
Navigate from your BLoC, Riverpod notifier, service, or repository without BuildContext:
// Push a screen
AppForgeNav.to(const ProfileScreen());
// Replace screen
AppForgeNav.replace(const DashboardScreen());
// Clear stack and push
AppForgeNav.toAndClearStack(const LoginScreen());
// Pop
AppForgeNav.back();
5. AppForge Logger
AppForgeLogger.d('Debug info');
AppForgeLogger.i('Connected to API');
AppForgeLogger.w('Token expiring soon');
AppForgeLogger.e('Request failed', error: exception, stackTrace: trace);
๐งช Testing
Run test suite:
flutter test
๐ License
MIT License.
Libraries
- appforge_kit
- AppForge Kit - Production-ready foundation kit for Flutter applications. Provides Multi-Environment Management, AuthGate, Crash Boundary, Inactivity Session Guards, and Context-less Navigation.