import 'package:flutter/material.dart';
import 'package:flutter_map_tile_caching/flutter_map_tile_caching.dart';
import 'package:flutter_riverpod/flutter_riverpod.dart';
import 'package:rogapp/nrog/pages/permission_page.dart';

void main() async {
  WidgetsFlutterBinding.ensureInitialized();

  await FlutterMapTileCaching.initialise();
  final StoreDirectory instanceA = FMTC.instance('OpenStreetMap (A)');
  await instanceA.manage.createAsync();
  await instanceA.metadata.addAsync(
    key: 'sourceURL',
    value: 'https://cyberjapandata.gsi.go.jp/xyz/std/{z}/{x}/{y}.png',
  );
  await instanceA.metadata.addAsync(
    key: 'validDuration',
    value: '14',
  );
  await instanceA.metadata.addAsync(
    key: 'behaviour',
    value: 'cacheFirst',
  );
  runApp(
    const ProviderScope(child: MyApp()),
  );
}

class MyApp extends StatefulWidget {
  const MyApp({super.key});

  @override
  State<MyApp> createState() => _MyAppState();
}

class _MyAppState extends State<MyApp> with WidgetsBindingObserver {
  @override
  void initState() {
    super.initState();
    WidgetsBinding.instance.addObserver(this);
  }

  @override
  void dispose() {
    WidgetsBinding.instance.removeObserver(this);
    super.dispose();
  }

  @override
  Widget build(BuildContext context) {
    return MaterialApp(
        debugShowCheckedModeBanner: false,
        title: 'Flutter Demo',
        theme: ThemeData(
          colorScheme: ColorScheme.fromSeed(
              seedColor: const Color.fromARGB(255, 124, 156, 9)),
          useMaterial3: true,
        ),
        home: const PermissionPage());
  }
}
