firebase – Check authentication state using stream not working in Flutter

I’m using GoogleSignIn.

On my splash screen, I’m using StreamBuilder to check whether the user is logged in or not, and based on that data I’m trying to show the Login Screen or Home Screen.

When I uninstall and reinstall the app it shows the Login Screen for the first time. And then after it always shows me the Home Screen even if I logged out from the app.

Below is my code for Splash Screen:

class SplashScreen extends StatefulWidget {
  @override
  _SplashScreenState createState() => _SplashScreenState();
}

class _SplashScreenState extends State<SplashScreen> {
  @override
  Widget build(BuildContext context) {
    SizeConfig().init(context);
    return StreamBuilder(
      stream: FirebaseAuth.instance.authStateChanges(),
      builder: (BuildContext context, AsyncSnapshot<User> snapshot) {
        if (snapshot.hasData) {
          print(snapshot.hasData);
          return AnimatedSplashScreen(
            splashIconSize: SizeConfig.blockSizeVertical * 16,
            splashTransition: SplashTransition.fadeTransition,
            nextScreen: HomeScreen(),
            splash: kLogoImage,
            duration: 800,
          );
        } else {
          print(snapshot.hasData);
          return AnimatedSplashScreen(
            splashIconSize: SizeConfig.blockSizeVertical * 16,
            splashTransition: SplashTransition.fadeTransition,
            nextScreen: LoginScreen(),
            splash: kLogoImage,
            duration: 800,
          );
        }
      },
    );
  }
}

Below is my code for Home Screen:

class HomeScreen extends StatefulWidget {
  @override
  _HomeScreenState createState() => _HomeScreenState();
}

class _HomeScreenState extends State<HomeScreen> {
  final GoogleSignIn googleSignIn = GoogleSignIn();
  User firebaseUser;

  signOut() async {
    await googleSignIn.signOut();
    Navigator.pushReplacementNamed(context, MyRoutes.loginScreen);
  }

  @override
  Widget build(BuildContext context) {
    return Scaffold(
      body: Column(
        mainAxisAlignment: MainAxisAlignment.center,
        children: (
          Center(
            child: Text('Hello'),
          ),
          MaterialButton(
              child: Text('Log out'),
              color: Colors.red,
              onPressed: () {
                signOut();
              })
        ),
      ),
    );
  }
}

Stuck in orange state bootloop after only unlocking bootloader

I entered fastboot in my gionee F205 through ADB and entered the command ‘fastboot continue’ which I got a error FAILED (remote: not support on security).
So I tried to unlock OEM and did the same through fastboot. Now when I reboot my device it is stuck in a bootloop with a message ‘orange state your device has been unlocked and can’t be trusted your device will boot in 5 seconds’. It reboots after that 5 secs.Please help

mobile – Flashlight switch: display the desired state or the current state

Situation:
I need to design a view in a mobile application (iOS + android) to scan qr-codes. The view needs a toggle to switch the flashlight “on” and “off”.

Problem:
I first designed the switch that represented the current state of the flashlight (V1). This means that when the flashlight is “off” the icon shows a crossed out light bulb and when the flashlight is “on” the icon shows a glowing light bulb.

enter image description here

Like toggles work in settings for example:

enter image description here

When I tested my design in a prototype (Adobe XD) is feels very strange to turn on the flashlight by clicking on an icon that shows a crossed out light bulb.

For this reason I have created another variant that shows exactly the opposite:

  • When I want to turn “on” the light, I click on the icon with the light
    “on “
  • When I want to turn “off” the light, I click on the icon with the
    light “off”.

It’s like a play and pause button on a music player

  • When I want to play the song, I click on the play icon
  • When I want to pause the song, I click on the pause icon

enter image description here
enter image description here

enter image description here

I had a discussion with a colleague about whether it makes sense to display what the user wants to achieve, or the current state. Displaying the current state makes less sense to me in this context, because the user knows that the flashlight is off when sitting in the dark. And as I said it feels weird to click on this crossed out icon. Now I am successfully confused how to solve this problem. I think it’s not good to break the switch behavior everyone is used to know, even if it feels weird to me.

What do you guys think?

9 – Set a default integer value with #ajax, according to a form state value in the same form

JavaScript API / AJAX Forms is quite complete and good. Plus, there are many examples around.

Anyway, tthere are various errors.

  1. The ajax callback should be attached with code like $form('your_field')('widget')('#ajax')= (...);

  2. You should set the wrapper using an ID that’s kept the same even after AJAX calls. A common solution can be to set up it using #prefix and #suffix

    $form("field_second_field")("#prefix") = '<div id="my-id">';
    $form("field_second_field")("#suffix") = '</div>';
    
  3. The AJAX callback should return a renderable array or an AJAX command; in this case, return $form('field_second_field')

Written as the following, it should work.

function my_module_form_alter(&$form, DrupalCoreFormFormStateInterface $form_state, $form_id) {
  $form('your_field')('widget')('#ajax') = (
    'callback' => 'custom_callback',
    'event' => 'change',
    'wrapper' => 'custom-id',
  );

  $form("second_field")("#prefix") = "<div id='custom-id'>";
  $form("second_field")("#suffix") = "</div";
}

function custom_callback(&$form, DrupalCoreFormFormStateInterface $form_state, $form_id) {
  //your logic
  return $form("second_field");
}

Please note, I never changed the #default_value inside the AJAX callback, but I see no reason why it should not work.

lua – Play and Pause State

Problem

i want to implement a pause state and with a simple conditional inside the update of PlayState is very very simple.
However i think that the pause has to be another state in the StateMachine so i dont know how to call that PauseState and then resume the Play State without calling the init again, i mean, i dont want to start the PlayState from zero

Code

Main

 gStateMachine = StateMachine {
        ('title') = function() return TitleScreenState() end,
        ('countdown') = function() return CountdownState() end,
        ('play') = function() return PlayState() end,
        ('score') = function() return ScoreState() end,
        ('pause') = function() return PauseState() end,
    }
    gStateMachine:change('title')

StateMachine

function StateMachine:init(states)
    self.empty = {
        render = function() end,
        update = function() end,
        enter = function() end,
        exit = function() end
    }
    self.states = states or {} -- (name) -> (function that returns states)
    self.current = self.empty
end

function StateMachine:change(stateName, enterParams)
    assert(self.states(stateName)) -- state must exist!
    self.current:exit()
    self.current = self.states(stateName)()
    self.current:enter(enterParams)
end

PlaysState

 if love.keyboard.wasPressed('p') then
        self.paused = not self.paused //Here i pause the game
    end

Resume

Basically I want to make it more pro, and I understand that the correct way to do it according to the design patterns of video games is to incorporate a GameState that is PauseState.

My problem as I was telling you before is that when I make a change state from PlayState to PauseState, and then return to PlayState, the PlayState:init is called again, and I simply want its update not to be called and then resume correctly.

What I want to do is correct ?, Is there any way to do it right ?, I imagine something like stacking the States then Push and Pull them, but I do not know if it is correct

hooks – Drupal 9 Set a default integer value with #ajax, according to a form state value in the same form

There is an integer field: “Number of pitches”
Another integer field: “Maximum people allowed”.
These will usually be the same values.

I am trying to set the value of the field specified in the pitches, as the default value for the maximum number of people.Whatever combination I try, no results. In a hook_form_alter I try to realize this with Ajax.

function zaal_condities_form_alter(&$form, DrupalCoreFormFormStateInterface $form_state, $form_id) {
if($form_id == 'node_bedrijf_form' || $form_id == 'node_bedrijf_edit_form'){
   $form('field_staanplaatsen')('widget')(0)('value')('#ajax') = (
      'callback' => 'zaal_condities_AjaxCallback',
      'event' => 'change',
      'wrapper' => 'edit-field-staanplaatsen-0-value',
    );
  }
}

function zaal_condities_AjaxCallback(&$form, DrupalCoreFormFormStateInterface $form_state, $form_id) {
  if($form_state->getValue('field_staanplaatsen') != false){
    $inputValue = $form_state->getValue('field_staanplaatsen');
    return $form('field_bezetting_tot')('widget')(0)('value')('#default_value') = $inputValue;
  }
}

wi fi – Do all apps lose state when the phone is locked?

I use Rune for music. It takes Rune a bit of time to find its controller on the network. If, after starting some music playing, I then lock the phone, when I come back Rune starts all over to locate its controller. I had a similar experience with Sony’s ‘imaging edge’ app for remote-controlling my camera. As soon the phone locked, I had to go through the elaborate connection process all over again.

Is there any way to change this behavior?

blockchain – In case of private data collections how can the nodes that don’t have complete access to the transactions know about the world state?

Hyperledger Fabric offers the ability to create private data collections, which allow a defined subset of organizations on a channel the ability to endorse, commit, or query private data without having to create a separate channel.
In that case, how can the nodes that don’t have complete access to the transactions know about the world state?
Will the world state differ between the organization that has and doesn’t have the access to the private data?

automation – Application to save state of all open applications and windows for context switching

I’m looking for an application that is able to capture the state of my mac (open applications, open folders, open files, window sizes, etc) such that I may be able to restore it to this state using a hotkey or equivalent.

I want to be able to have different ‘mac states’ to switch to on command so that when I am switching contexts, I am no longer having to go through the process of opening each application along with the folder/file I was previously working on.

I’ve found some decent answers on here including an in-depth look at manipulating .savedState files using apple script but I was hoping for a less tedious solution.

8 – Programmatically add a translation with proper content moderation state

I am trying to add a node translation programmatically when a node is created (using hook_ENTITY_TYPE_insert). My code works fine except that the translation doesn’t really have a content moderation state. My code is the following.

function mymodule_add_translation($node) {
  // get the current language, and determine the translation language
  $lang = Drupal::languageManager()->getCurrentLanguage()->getId();
  $langcode = ($lang == 'en') ? 'fr' : $lang;
  $node->setRevisionTranslationAffected(TRUE);
  $node->addTranslation($langcode, ('title' => $node->getTitle()))->save();
}

This is what the content_moderation_state_field_revision table looks like for two nodes; one was manually translated it and the other one was translated using the above code.

content_moderation_state_field_revision table

I am clearly doing something incorrect. Any suggestion would be really appreciated.