import 'dart:io';
import 'dart:math';
import 'package:easy_localization/easy_localization.dart';
import 'package:flutter/material.dart';
import 'package:flutter/services.dart';
import 'package:flutter_riverpod/flutter_riverpod.dart';
import 'package:flutter_screenutil/flutter_screenutil.dart';
import 'package:product_selector/common/model/local_storage.dart';
import 'package:product_selector/network/constants.dart';
import 'package:product_selector/routes/app_routes.dart';
import 'package:product_selector/routes/navigation_observer.dart';
import 'package:product_selector/screens/screen_saver/view_model/screen_saver.view_model.dart';
import 'network/api_client.dart';
import 'package:shared_preferences/shared_preferences.dart';

import 'network/service_urls.dart';

void main() async {
  WidgetsFlutterBinding.ensureInitialized();
  SystemChrome.setPreferredOrientations(
      [DeviceOrientation.portraitUp, DeviceOrientation.portraitDown]);

  HttpOverrides.global = MyHttpOverrides();
  WidgetsFlutterBinding.ensureInitialized();
  await EasyLocalization.ensureInitialized();
  SharedPreferences preferences = await SharedPreferences.getInstance();
  preferences.getString('lang');
  String? _locale;
  await StorageUtil.init();

  if (preferences.getString('lang') == 'ar') {
    _locale = 'ar';
  } else {
    _locale = 'en';
  }
  runApp(
    ProviderScope(
      child: EasyLocalization(
        supportedLocales: const [Locale('en'), Locale('ar')],
        path: 'assets/translations',
        fallbackLocale: Locale(_locale),
        child: const MyApp(),
      ),
    ),
  );
}

class MyApp extends StatefulWidget {
  const MyApp({Key? key}) : super(key: key);

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

class _MyAppState extends State<MyApp> {
  static const platform = MethodChannel('device/info');

  @override
  void initState() {
    super.initState();
    _getDeviceName();
    
  }

  // Function to invoke the native Android method
  Future<void> _getDeviceName() async {
    final String result = await platform.invokeMethod('deviceName');
    ServicesConstants.headerToken = result;
    print("Device name = " + ServicesConstants.headerToken);
    WidgetsBinding.instance.addPostFrameCallback((timeStamp) async {
      await ref
          .read(screenSaverViewModelProvider.notifier)
          .getApplicationId(ServiceUrls.getApplicationId);
    });
  }

  @override
  Widget build(BuildContext context) {
    return ScreenUtilInit(
      designSize: const Size(1080, 1920),
      minTextAdapt: true,
      splitScreenMode: true,
      builder: (context, child) => MaterialApp(
          debugShowCheckedModeBanner: false,
          theme: ThemeData(
            fontFamily:
                context.locale.languageCode == 'ar' ? 'GE_SS' : 'Vodafone',
          ),
          navigatorObservers: [NavigationObserver()],
          localizationsDelegates: context.localizationDelegates,
          supportedLocales: context.supportedLocales,
          locale: context.locale,
          onGenerateRoute: AppRoutes().controller,
          initialRoute: AppRoutes.defaultRoute),
    );
  }
}
i have this main file in flutter project i try to call the api     await ref
          .read(screenSaverViewModelProvider.notifier)
          .getApplicationId(baseURL/api/tenant/resolver/application?token=" +
          ServicesConstants.headerToken);
    }); inside function getDeviceName  give me error on ref as undefined despite i imported  import 'package:flutter_riverpod/flutter_riverpod.dart';