Skip to content

Instantly share code, notes, and snippets.

@anilcancakir
Created March 5, 2018 21:55
Show Gist options
  • Save anilcancakir/25d7777dde8199fb1a79b1d0c04f56e2 to your computer and use it in GitHub Desktop.
Save anilcancakir/25d7777dde8199fb1a79b1d0c04f56e2 to your computer and use it in GitHub Desktop.
How to use dynamic home page in Flutter? - main
import 'package:app/pages/home.page.dart';
import 'package:app/pages/login.page.dart';
import 'package:app/services/auth.service.dart';
import 'package:flutter/material.dart';
AuthService appAuth = new AuthService();
void main() async {
// Set default home.
Widget _defaultHome = new LoginPage();
// Get result of the login function.
bool _result = await appAuth.login();
if (_result) {
_defaultHome = new HomePage();
}
// Run app!
runApp(new MaterialApp(
title: 'App',
home: _defaultHome,
routes: <String, WidgetBuilder>{
// Set routes for using the Navigator.
'/home': (BuildContext context) => new HomePage(),
'/login': (BuildContext context) => new LoginPage()
},
));
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment