Total de visualizações de página

Comandos para conectar automaticamente o firebase com o flutter.

    dart pub global activate flutterfire_cli\n

   export PATH="$PATH":"$HOME/.pub-cache/bin"\n


   flutterfire configure --project=babas-cb587   --out=lib/firebase_options.dart --account=xxxxxxx@gmail.com --platforms=ios,android,web --android-package-name=ao.co.a2x.xxx—ios-bundle-id=ao.co.a2x.xxx --yes\n

widget cannot be marked as needing to build because the framework is already in the process of building widgets


======== Exception caught by foundation library ====================================================

The following assertion was thrown while dispatching notifications for XXProvider:

setState() or markNeedsBuild() called during build.


This _InheritedProviderScope<XXProvider?> widget cannot be marked as needing to build because the framework is already in the process of building widgets. A widget can be marked as needing to be built during the build phase only if one of its ancestors is currently building. This exception is allowed because the framework builds parent widgets before children, which means a dirty descendant will always be built. Otherwise, the framework might not visit this widget during this build phase.

The widget on which setState() or markNeedsBuild() was called was: _InheritedProviderScope<XXProvider?>

  value: Instance of 'XXProvider'

  listening to value

The widget which was currently being built when the offending call was made was: Builder

When the exception was thrown, this was the stack: 

#0      Element.markNeedsBuild.<anonymous closure> (package:flutter/src/widgets/framework.dart:5047:9)

#1      Element.markNeedsBuild (package:flutter/src/widgets/framework.dart:5059:6)

#2      _InheritedProviderScopeElement.markNeedsNotifyDependents (package:provider/src/inherited_provider.dart:577:5)

#3      ChangeNotifier.notifyListeners (package:flutter/src/foundation/change_notifier.dart:433:24)


PROBLEMA:


O erro que você está enfrentando ocorre porque o método setState está sendo chamado durante a fase de construção do widget, o que não é permitido. O erro é gerado quando o setState é chamado enquanto o framework está construindo os widgets. Isso pode acontecer se você tentar modificar o estado ou notificar ouvintes (listeners) de um ChangeNotifier enquanto a árvore de widgets está sendo montada.



@override
void initState() {
super.initState();
_check();
}
Future<void> _checkSegurados() async {

setState(() {
_isLoading =
false; // Oculta o indicador de progresso quando o carregamento é concluído
});

}


SOLUÇÃO:


@override
void initState() {
super.initState();
// Use addPostFrameCallback to avoid calling setState during build
WidgetsBinding.instance.addPostFrameCallback((_) {
_checkSegurados();
});
}



Setup two environments for flutter firebase (existing project) - Dois google-services.json - firebase

 For Android:

  • create a folder "staging" at /android/app/src and put your google-services.json for dev
  • create a folder "production" at /android/app/src and put your google-services.jsonfor production
  • in your /android/app/build.graddle:

add

task switchToStaging(type: Copy) {
    description = 'Switches to Staging google-services.json'
    from "src/staging"
    include "google-services.json"
    into "."
}

task switchToProduction(type: Copy) {
    description = 'Switches to Production google-services.json'
    from "src/production"
    include "google-services.json"
    into "."
}

afterEvaluate {
    processStagingDebugGoogleServices.dependsOn switchToStaging
    processStagingReleaseGoogleServices.dependsOn switchToStaging
    processProductionDebugGoogleServices.dependsOn switchToProduction
    processProductionReleaseGoogleServices.dependsOn switchToProduction
}

You can replace "staging" and "production" by your flavors name. When you will build it will copy google-services.json from the created folder to /android/app

For iOS:

  • the same way as Android, create a folder Firebase/staging and Firebase/productionat Runner/Runner/ and put your respective GoogleService-Info.plist

then, (assuming you have created your scheme that match to your flavors name), in Build Phases section in xcode:

replace if statement with your needs

if [ "${CONFIGURATION}" == "Debug-production" ] || [ "${CONFIGURATION}" == "Release-production" ] || [ "${CONFIGURATION}" == "Release" ]; then

cp -r "${PROJECT_DIR}/Runner/Firebase/production/GoogleService-Info.plist" "${PROJECT_DIR}/Runner/GoogleService-Info.plist"

elif [ "${CONFIGURATION}" == "Debug-profile" ] || [ "${CONFIGURATION}" == "Release-profile" ] || [ "${CONFIGURATION}" == "Profile" ]; then

cp -r "${PROJECT_DIR}/Runner/Firebase/staging/GoogleService-Info.plist" "${PROJECT_DIR}/Runner/GoogleService-Info.plist"

elif [ "${CONFIGURATION}" == "Debug-staging" ] || [ "${CONFIGURATION}" == "Release-staging" ] || [ "${CONFIGURATION}" == "Debug" ]; then

cp -r "${PROJECT_DIR}/Runner/Firebase/staging/GoogleService-Info.plist" "${PROJECT_DIR}/Runner/GoogleService-Info.plist"

fi

Fonte: https://stackoverflow.com/questions/77884297/setup-two-environments-for-flutter-firebase-existing-project

Comandos para conectar automaticamente o firebase com o flutter.

     dart pub global activate flutterfire_cli\n    export PATH="$PATH":"$HOME/.pub-cache/bin"\n    flutterfire configu...