Closed aljohara556 closed 3 years ago
Please share your flutter doctor -v
output and initialization code
this is the responce of flutter doctor ..
and the is the initialization code
void main() async { WidgetsFlutterBinding.ensureInitialized(); await translator.init( localeDefault: LocalizationDefaultType.device, languagesList: <String>['ar', 'en'], assetsDirectory: 'assets/langs/', );
okay, thanks for the details I will check it
Please test version 3.0.3, I believe it's solved
I still have the same issue using latest version localize_and_translate: ^3.0.3
Restarted application in 2,604ms.
flutter: --LocalizeAndTranslate : Google(false) | LangList[da, en] | Dir(language/) | Active(en.json)
[VERBOSE-2:ui_dart_state.cc(177)] Unhandled Exception: NoSuchMethodError: The method 'restart' was called on null.
Receiver: null
Tried calling: restart()
#0 Object.noSuchMethod (dart:core-patch/object_patch.dart:51:5)
#1 LocalizedApp.restart (package:localize_and_translate/src/main.class.dart:256:11)
#2 LocalizeAndTranslate.setNewLanguage (package:localize_and_translate/src/main.class.dart:196:20)
<asynchronous suspension>
#3 LoginPage.build.<anonymous closure> (package:minbolig/Presentation/ui/pages/login/login_page.dart:74:51)
#4 _InkResponseState._handleTap (package:flutter/src/material/ink_well.dart:993:19)
#5 _InkResponseState.build.<anonymous closure> (package:flutter/src/material/ink_well.dart:1111:38)
#6 GestureRecognizer.invokeCallback (package:flutter/src/gestures/recognizer.dart:183:24)
#7 TapGestureRecognizer.handleTapUp (package:flutter/src/gestures/tap.dart:598:11)
#8 BaseTapGestureRecognizer._checkUp (package:flutter/src/gestures/tap.dart:2<…>
[VERBOSE-2:ui_dart_state.cc(177)] Unhandled Exception: NoSuchMethodError: The method 'restart' was called on null.
Receiver: null
Tried calling: restart()
#0 Object.noSuchMethod (dart:core-patch/object_patch.dart:51:5)
#1 LocalizedApp.restart (package:localize_and_translate/src/main.class.dart:256:11)
#2 LocalizeAndTranslate.setNewLanguage (package:localize_and_translate/src/main.class.dart:196:20)
<asynchronous suspension>
#3 LoginPage.build.<anonymous closure> (package:minbolig/Presentation/ui/pages/login/login_page.dart:74:51)
#4 _InkResponseState._handleTap (package:flutter/src/material/ink_well.dart:993:19)
#5 _InkResponseState.build.<anonymous closure> (package:flutter/src/material/ink_well.dart:1111:38)
#6 GestureRecognizer.invokeCallback (package:flutter/src/gestures/recognizer.dart:183:24)
#7 TapGestureRecognizer.handleTapUp (package:flutter/src/gestures/tap.dart:598:11)
#8 BaseTapGestureRecognizer._checkUp (package:flutter/src/gestures/tap.dart:2<…>
[VERBOSE-2:ui_dart_state.cc(177)] Unhandled Exception: NoSuchMethodError: The method 'restart' was called on null.
Receiver: null
Tried calling: restart()
#0 Object.noSuchMethod (dart:core-patch/object_patch.dart:51:5)
#1 LocalizedApp.restart (package:localize_and_translate/src/main.class.dart:256:11)
#2 LocalizeAndTranslate.setNewLanguage (package:localize_and_translate/src/main.class.dart:196:20)
<asynchronous suspension>
#3 LoginPage.build.<anonymous closure> (package:minbolig/Presentation/ui/pages/login/login_page.dart:74:51)
#4 _InkResponseState._handleTap (package:flutter/src/material/ink_well.dart:993:19)
#5 _InkResponseState.build.<anonymous closure> (package:flutter/src/material/ink_well.dart:1111:38)
#6 GestureRecognizer.invokeCallback (package:flutter/src/gestures/recognizer.dart:183:24)
#7 TapGestureRecognizer.handleTapUp (package:flutter/src/gestures/tap.dart:598:11)
#8 BaseTapGestureRecognizer._checkUp (package:flutter/src/gestures/tap.dart:2<…>
Doctor summary (to see all details, run flutter doctor -v):
[✓] Flutter (Channel stable, 1.22.5, on macOS 11.1 20C69 darwin-x64,
locale en-PH)
[✓] Android toolchain - develop for Android devices (Android SDK
version 30.0.3)
[✓] Xcode - develop for iOS and macOS (Xcode 12.3)
[!] Android Studio (version 4.1)
✗ Flutter plugin not installed; this adds Flutter specific
functionality.
✗ Dart plugin not installed; this adds Dart specific
functionality.
[✓] VS Code (version 1.53.2)
[✓] Connected device (1 available)
! Doctor found issues in 1 category.
This is my code .
initialize
WidgetsFlutterBinding.ensureInitialized();
await translator.init(
localeDefault: LocalizationDefaultType.device,
languagesList: <String>['da', 'en'],
assetsDirectory: 'language/',
);
and the toggle
translator.setNewLanguage(
context,
newLanguage:
translator.currentLanguage == 'en' ? 'da' : 'en',
restart: true,
);
@mjmon did you wrap your main class inside runApp()
method with LocalizedApp()
!
LocalizedApp()
in main.dart fixed the error and converting the widget that contains the toggle button to a StatefulWidget
solves it.
you can close it now. Thank you for your help.
Glad to hear that, thanks for sharing..
I have a problem, when I try to converter the app language, I faced a problem,
[ERROR:flutter/lib/ui/ui_dart_state.cc(177)] Unhandled Exception: NoSuchMethodError: The method 'restart' was called on null. E/flutter ( 6490): Receiver: null E/flutter ( 6490): Tried calling: restart() E/flutter ( 6490): #0 Object.noSuchMethod (dart:core-patch/object_patch.dart:51:5) E/flutter ( 6490): #1 LocalizedApp.restart (package:localize_and_translate/src/main.class.dart:258:11) E/flutter ( 6490): #2 LocalizeAndTranslate.setNewLanguage (package:localize_and_translate/src/main.class.dart:197:20) E/flutter ( 6490): <asynchronous suspension> E/flutter ( 6490): #3 _settingsState._onBackPressed.<anonymous closure>.<anonymous closure>.<anonymous closure> (package:erp_accounting_app/drawer_pages/setting.dart:159:32) E/flutter ( 6490): #4 new Future.delayed.<anonymous closure> (dart:async/future.dart:326:39)
this is my code :
translator.setNewLanguage( context, newLanguage: translator.currentLanguage == 'ar' ? 'en' : 'ar', remember: true, restart: true, );
what is the problem ??