mirror of
https://github.com/cyberbread-ru/notepad.git
synced 2026-07-14 12:51:01 +03:00
54 lines
1.6 KiB
Dart
54 lines
1.6 KiB
Dart
import 'package:flutter/material.dart';
|
|
import 'package:provider/provider.dart';
|
|
|
|
import 'repositories/local_note_repository.dart';
|
|
import 'repositories/remote_note_repository.dart';
|
|
import 'screens/note_list_screen.dart';
|
|
import 'screens/settings_screen.dart';
|
|
import 'services/api_client.dart';
|
|
import 'services/note_service.dart';
|
|
import 'services/sync_service.dart';
|
|
import 'viewmodels/note_view_model.dart';
|
|
|
|
void main() async {
|
|
WidgetsFlutterBinding.ensureInitialized();
|
|
final settings = await AppSettings.load();
|
|
runApp(App(settings: settings));
|
|
}
|
|
|
|
class App extends StatelessWidget {
|
|
final ({String url, String apiKey}) settings;
|
|
|
|
const App({super.key, required this.settings});
|
|
|
|
@override
|
|
Widget build(BuildContext context) {
|
|
final localRepo = LocalNoteRepository();
|
|
|
|
SyncService? syncService;
|
|
if (AppSettings.isConfigured(url: settings.url, apiKey: settings.apiKey)) {
|
|
final apiClient = ApiClient(
|
|
baseUrl: settings.url,
|
|
apiKey: settings.apiKey,
|
|
);
|
|
final remoteRepo = RemoteNoteRepository(api: apiClient);
|
|
syncService = SyncService(local: localRepo, remote: remoteRepo);
|
|
}
|
|
|
|
final noteService = NoteService(local: localRepo, sync: syncService);
|
|
|
|
return ChangeNotifierProvider(
|
|
create: (_) => NoteViewModel(service: noteService)..loadNotes(),
|
|
child: MaterialApp(
|
|
title: 'Notepad',
|
|
debugShowCheckedModeBanner: false,
|
|
theme: ThemeData(
|
|
colorScheme: ColorScheme.fromSeed(seedColor: Colors.indigo),
|
|
useMaterial3: true,
|
|
),
|
|
home: const NoteListScreen(),
|
|
),
|
|
);
|
|
}
|
|
}
|