text:
Q: Como redirigir al usuario si el API te da un código 401 en Flutter Tengo una pantalla principal, que muestra cinco registros de un usuario, para eso, tengo una función que hace la petición del usuario enviando un userToken y un UserID que me provee el servidor previamente y los guardo en SharedPreferences, pero el token, cuenta con tiempo de expiración, y necesito gestionar que si el token no está vigente (me devuelva un error 401 o un mensaje como se ve en el código), lo envíe al login nuevamente (mostrando una alerta al usuario, que le notifique que debe iniciar sesión de nuevo) , pero el código no entra a esa parte y se va directamente a la excepción.
Anexo código de la función, agradeceré cualquier sugerencia o ayuda.
//HTTP Request
Future<List<Record>> fetchRecord() async {
  // final userid = ModalRoute.of(context)!.settings.arguments;
  UserPreferences userPreferences = UserPreferences();
        //Consultas el dato almacenado y la asignas a la variable userId
  var userId = await userPreferences.getUserId();
  var userid = userId;
  var userToken = await userPreferences.getUserToken();
  var usertoken = userToken;
  var s = userid.toString() + '/' + usertoken.toString();
  print('esta es una prueba user' + s);
  //final response = await http.get(Uri.parse('https://e5ac-45-65-152-57.ngrok.io/get/fiverecords/1'));
  final response = await http
      .get(Uri.parse('https://f6a1-45-65-152-57.ngrok.io/get/fiverecords/$s'));

  if (response.statusCode == 200) {
    final parsed = json.decode(response.body).cast<Map<dynamic, dynamic>>();

    return parsed.map<Record>((json) => Record.fromMap(json)).toList();
  } else if (response.statusCode == 401) {
     showDialog(
                  context: context,
                  builder: (BuildContext context) {
                    AlertDialog(
        title: Row(mainAxisAlignment: MainAxisAlignment.center, children: [
          Image.asset(
            'assets/error.png',
            width: 80,
            height: 80,
            fit: BoxFit.contain,
          ),
        ]),
        content: SingleChildScrollView(
          child: ListBody(
            children: const [
              Text('Sesión expirada. \nInicie sesión. ')
            ],
          ),
        ),
        actions: [
          TextButton(
              onPressed: () async {
                final SharedPreferences sharedPreferences = await SharedPreferences.getInstance();
                sharedPreferences.clear(); //Para borrar T O D O.
                Navigator.pushNamed(context, '/LoginScreen');
              },
              child: const Text('Aceptar'))
        ]);
        throw new Exception('interno');

                  }
                  );
        throw Exception("Token is Expired"); // you may want to implement different exception class
      }
  throw Exception('Failed to load records.');
  }


Although it's Black History Month, Valentine's Day is next week and where would we be without Black love? Black love has not only given birth to generations of world-changing heroes. It's also provided inspiration, courage, and joy for the Black community. If you have a special person in your life who will be your Valentine's Day this year, then you need to go all out for them. Show them how special they are--show them how special Black love is--with these beautiful Black-owned products.
Who remembers the hit '90s TV show, Living Single? Who doesn't? If the corny relationship between Synclaire and Overton, or the rocky, on-again-off-again-relationship between Khadijah and Scooter didn't make you laugh, cry, and gasp in shock, then surely, the tumultuous relationship between Max and Kyle did. Who doesn't want a love where you can take sarcastic jabs at one another but still "get a little freaky sneaky" afterward? Click here to buy this Maxine and Kyle card for your Valentine before they're sold out.
Nothing expresses your love more than something handmade. Let's be real, though. Not everyone is an artist. Perhaps you'd like to give your significant other a beautiful painting but one that isn't abstract simply because you lack talent. That's both understandable and relatable. Not to worry. TruArtist83 is selling this fantastic piece titled IAmValentine. Let a professional artist create the handmade masterpiece that you want for your true love. Click here to get your copy today.
Perhaps you're one of the few people who didn't like Living Single--no judgment. Or, perhaps you simply don't want to buy a humorous card for your Valentine. Either way, We Buy Black has you covered. This Black Love Greeting Card from Adeyemi Artistry is a culmination of the two previous items: an embodiment of Black Love and handmade. This card will enable you to celebrate Black love with a beautifully written poem by Adeyemi himself. Click here to purchase this card.
Finally, check out this Rose Bear by T. L. Dowell's Sew 4 U ATL. This intricately designed teddy bear is made from synthetic roses. They come in three sizes: 8 inches, 12 inches, and 20 inches. The best part is that they're customizable and come in a variety of romantic colors, like pink or red. You can select an arrangement that you know your significant other will cherish forever. Click here to start customizing your Rose Bear right now.


text:
Q: Twitter no longer authorizes old Android devices / webview? I noticed this when I re-ran my app on 2.2 and 2.3.4 devices. Basically I have a WebView which is loaded with twitter4j's client getAuthenticationURL.

If everything is correct and "Sign In" is clicked, webview will load another page asking for user's authorization. From there, "Authorize app" will return the app's custom callback and user tokens.

Clicking that "Sign In" button will no longer send the webview to the authorization page. It will just stay there. When I debugged my WebViewClient and probed onPageStarted, I noticed that a request was sent. But there's just no response from Twitter. Also, in my 4.4 Nexus tablet, there's no authorization page. "Sign in" will both authorize and immediately return the callback.
So far I found three workarounds for it (all these tests were done from clean install):

*

*Click cancel, restart the app, and reload the same url + request token. This time there's no login. It will get webview to directly load the Authorization page.

*This is the complete hack of all. Basically I need to enter a wrong password and I will get sent to a Password reconfirm page. If I enter the right password this time, I will see that authorization page. In fact the second snapshot above was obtained this way.

*If I paste that url + request token on a browser, it will also skip the authorization page and immediately return my callback. I haven't made a thorough research if this works on startActivity-for-browser scheme, not embedded webview.
EDIT : it works, upon Sign In, browser will fire a warning and then return the callback which my app intercepts in onNewIntent. There is no authorization page. Also callback url needs to have callback host like bla://callback

I am pretty sure I was able to navigate the login pages including authorization with my older devices not long ago. Is this authorization thing broken or obsolete ?

A: In the absence of better answer then the current solution will have to do: separate login methods. I use Intent to browser for pre-ICS and WebView for the rest.

redpajama_set_name: RedPajamaStackExchange


Di Cairano, S., Goldsmith, A.M., Kalabić, U., Bortoff, S.A., "Cascaded Reference Governor-MPC for Motion Control of Two-Stage Manufacturing Machine", IEEE Transactions on Control Systems Technology, DOI: 10.1109/TCST.2018.2847627, July 11, 2018.
Kalabić, U., Di Cairano, S., "Inner-Loop Reference Governor Design with an Application to Human-in-the-Loop Control", European Control Conference (ECC), July 11, 2018.
Malyshev, A., Quirynen, R., Knyazev, A., Di Cairano, S., "A regularized Newton solver for linear model predictive control", European Control Conference (ECC), July 11, 2018.