You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

229 lines
6.5 KiB

import 'package:flutter/material.dart';
import 'config/config_loader.dart';
import 'data/local/local_storage_service.dart';
import 'data/local/models/item.dart';
void main() {
// Load configuration based on environment
// In a real app, this would come from environment variables or build config
const String environment = String.fromEnvironment(
'ENV',
defaultValue: 'dev',
);
final config = ConfigLoader.load(environment);
if (config.enableLogging) {
debugPrint('App initialized with config: $config');
}
runApp(const MyApp());
}
/// The root widget of the application.
class MyApp extends StatefulWidget {
const MyApp({super.key});
@override
State<MyApp> createState() => _MyAppState();
}
class _MyAppState extends State<MyApp> {
late LocalStorageService _storageService;
int _itemCount = 0;
bool _isInitialized = false;
@override
void initState() {
super.initState();
_initializeStorage();
}
Future<void> _initializeStorage() async {
try {
_storageService = LocalStorageService();
await _storageService.initialize();
final items = await _storageService.getAllItems();
setState(() {
_itemCount = items.length;
_isInitialized = true;
});
} catch (e) {
debugPrint('Failed to initialize storage: $e');
}
}
Future<void> _addTestItem() async {
if (!_isInitialized) return;
final item = Item(
id: 'test-${DateTime.now().millisecondsSinceEpoch}',
data: {
'name': 'Test Item',
'timestamp': DateTime.now().toIso8601String(),
},
);
await _storageService.insertItem(item);
final items = await _storageService.getAllItems();
setState(() {
_itemCount = items.length;
});
}
@override
void dispose() {
_storageService.close();
super.dispose();
}
@override
Widget build(BuildContext context) {
// Load config to display in UI
const String environment = String.fromEnvironment(
'ENV',
defaultValue: 'dev',
);
final config = ConfigLoader.load(environment);
return MaterialApp(
title: 'App Boilerplate',
theme: ThemeData(
colorScheme: ColorScheme.fromSeed(seedColor: Colors.blue),
useMaterial3: true,
),
home: Scaffold(
appBar: AppBar(
title: const Text('App Boilerplate'),
backgroundColor: Theme.of(context).colorScheme.inversePrimary,
),
body: Center(
child: Column(
mainAxisAlignment: MainAxisAlignment.center,
children: [
const Icon(
Icons.check_circle_outline,
size: 64,
color: Colors.green,
),
const SizedBox(height: 24),
const Text(
'Flutter Modular App Boilerplate',
style: TextStyle(
fontSize: 24,
fontWeight: FontWeight.bold,
),
),
const SizedBox(height: 32),
Card(
margin: const EdgeInsets.symmetric(horizontal: 32),
child: Padding(
padding: const EdgeInsets.all(16),
child: Column(
crossAxisAlignment: CrossAxisAlignment.start,
children: [
Text(
'Configuration',
style: Theme.of(context).textTheme.titleMedium?.copyWith(
fontWeight: FontWeight.bold,
),
),
const SizedBox(height: 12),
_ConfigRow(
label: 'Environment',
value: environment.toUpperCase(),
),
const SizedBox(height: 8),
_ConfigRow(
label: 'API Base URL',
value: config.apiBaseUrl,
),
const SizedBox(height: 8),
_ConfigRow(
label: 'Logging',
value: config.enableLogging ? 'Enabled' : 'Disabled',
),
],
),
),
),
const SizedBox(height: 32),
if (_isInitialized) ...[
Card(
margin: const EdgeInsets.symmetric(horizontal: 32),
child: Padding(
padding: const EdgeInsets.all(16),
child: Column(
children: [
Text(
'Local Storage',
style: Theme.of(context).textTheme.titleMedium?.copyWith(
fontWeight: FontWeight.bold,
),
),
const SizedBox(height: 12),
Text(
'Items in database: $_itemCount',
style: Theme.of(context).textTheme.bodyLarge,
),
const SizedBox(height: 12),
ElevatedButton(
onPressed: _addTestItem,
child: const Text('Add Test Item'),
),
],
),
),
),
const SizedBox(height: 16),
],
Text(
'Phase 2: Immich Integration Complete ✓',
style: Theme.of(context).textTheme.bodyMedium?.copyWith(
color: Colors.grey,
),
),
],
),
),
),
);
}
}
/// Widget to display a configuration row.
class _ConfigRow extends StatelessWidget {
final String label;
final String value;
const _ConfigRow({
required this.label,
required this.value,
});
@override
Widget build(BuildContext context) {
return Row(
crossAxisAlignment: CrossAxisAlignment.start,
children: [
SizedBox(
width: 100,
child: Text(
'$label:',
style: Theme.of(context).textTheme.bodySmall?.copyWith(
color: Colors.grey,
),
),
),
Expanded(
child: Text(
value,
style: Theme.of(context).textTheme.bodyMedium,
),
),
],
);
}
}

Powered by TurnKey Linux.