I am making an app which requires me an authentication and token check. I need to render Auth page if the user has no token & render Home if the token exists.
I am storing the token using flutter_secure_storage.
Flutter: 1.5.4
import 'package:flutter/material.dart';
import 'package:flutter/services.dart';
import 'package:provider/provider.dart';
import 'package:myapp/api.dart';
import 'package:myapp/router.dart';
class App extends StatelessWidget {
String _getInitialRoute(context) {
final hasToken = Provider.of<API>(context).token != null; // Returns Future<String> instead of string
return hasToken ? 'home' : 'auth';
}
// build async is throwing here an error.
build(context) {
return MaterialApp(
/**
* Disable debug banner.
*/
debugShowCheckedModeBanner: false,
/**
* Initial route.
*/
initialRoute: _getInitialRoute(context),
/**
* Routes.
*/
onGenerateRoute: Router.generateRoute,
/**
* Application title.
*/
title: 'My App',
);
}
}
I expect to get initialRoute based on token.