import 'dart:io'; import 'dart:math'; import…
- User
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 createState() => _MyAppState(); }
class _MyAppState extends State { static const platform = MethodChannel('device/info');
@override void initState() { super.initState(); _getDeviceName();
}
// Function to invoke the native Android method Future _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';
- Assistant
- User
well i used it consumerwidget now i want to save the response of api calling in variable
- Assistant
- User
well when i try final version = ref.watch(screenSaverViewModelProvider).version; String? appVersion = version?.application?.id; in main.dart always return appVersion by null
- Assistant
- User
important note the application didn't see the repo or viemodel of screensaver without appVersion
- Assistant
- User
- Assistant
- User
- Assistant
- User
i don't want to clean code i want to solve the issue that version returned by null
- Assistant
- User
can i call this API baseURL/api/tenant/resolver/application?token=" + ServicesConstants.headerToken in Future _getDeviceName() async { final String result = await platform.invokeMethod('deviceName'); ServicesConstants.headerToken = result; print('device name'); print("Device name = " + ServicesConstants.headerToken); WidgetsBinding.instance.addPostFrameCallback((timeStamp) async { await ref .read(screenSaverViewModelProvider.notifier) .getApplicationId(ServiceUrls.getApplicationId); }); print('appUrl' + ServiceUrls.getApplicationId); } without using screensaver
- Assistant
- User
slowly, now i want to call this baseURL/api/tenant/resolver/application?token=" + ServicesConstants.headerToken after headerToken returned from this function Future _getDeviceName() async { final String result = await platform.invokeMethod('deviceName'); ServicesConstants.headerToken = result; print('device name'); print("Device name = " + ServicesConstants.headerToken);}
- Assistant
Other models, same or similar prompt
Responses were produced in different, uncontrolled contexts (system prompts, settings, prior turns). This is not a benchmark.