owntracks-viewer/lib/main.dart
2024-03-14 20:50:30 +01:00

89 lines
2.2 KiB
Dart

import 'package:flutter/foundation.dart';
import 'package:flutter/material.dart';
import 'package:flutter_bloc/flutter_bloc.dart';
import 'package:hydrated_bloc/hydrated_bloc.dart';
import 'package:ot_viewer_app/global_location_store.dart';
import 'package:ot_viewer_app/settings_page.dart';
import 'package:path_provider/path_provider.dart';
import 'map_page.dart';
import 'package:get_it/get_it.dart';
import 'owntracks_api.dart';
Future<void> main() async {
WidgetsFlutterBinding.ensureInitialized();
HydratedBloc.storage = await HydratedStorage.build(
storageDirectory: kIsWeb
? HydratedStorage.webStorageDirectory
: await getApplicationDocumentsDirectory(),
);
GetIt.I
.registerSingleton<GlobalLocationStoreCubit>(GlobalLocationStoreCubit());
runApp(MyApp());
}
class MyApp extends StatelessWidget {
@override
Widget build(BuildContext context) {
return MaterialApp(
title: 'OwnTracks Data Viewer',
theme: ThemeData.dark(),
home: Scaffold(
appBar: AppBar(title: const Text('OwnTrakcs Data Viewer')),
body: const MainPage(),
),
);
}
}
class MainPage extends StatefulWidget {
const MainPage({super.key});
@override
createState() => _MainPageState();
}
class _MainPageState extends State<MainPage> {
int _currentIndex = 0;
final List<Widget> _pages = [
const MapPage(),
const SettingsPage(), // Assume this is your settings page widget
];
void _onItemTapped(int index) {
setState(() {
_currentIndex = index;
});
}
@override
Widget build(BuildContext context) {
return BlocProvider(
lazy: false,
create: (BuildContext context) => SettingsCubit(),
child: Scaffold(
body: IndexedStack(
index: _currentIndex,
children: _pages,
),
bottomNavigationBar: BottomNavigationBar(
items: const <BottomNavigationBarItem>[
BottomNavigationBarItem(
icon: Icon(Icons.map),
label: 'Map',
),
BottomNavigationBarItem(
icon: Icon(Icons.settings),
label: 'Settings',
),
],
currentIndex: _currentIndex,
onTap: _onItemTapped,
),
),
);
}
}