-
Notifications
You must be signed in to change notification settings - Fork 23
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Navigation between screens with generated Route
- Loading branch information
Showing
9 changed files
with
103 additions
and
83 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
class Res{ | ||
static const home = "/"; | ||
static const gamePage = "game"; | ||
static const rateUs = "rate"; | ||
static const settings = "settings"; | ||
static const about = "The game is a side-scroller where the player" | ||
" controls a bird, attempting to fly between " | ||
" columns of green pipes without hitting them"; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,38 @@ | ||
// ignore_for_file: prefer_const_constructors | ||
import 'package:flappy_bird/Layouts/Pages/page_game.dart'; | ||
import 'package:flappy_bird/Layouts/Pages/page_settings.dart'; | ||
import 'package:flutter/material.dart'; | ||
import '../Layouts/Pages/page_rate_us.dart'; | ||
import '../Layouts/Pages/page_start_screen.dart'; | ||
import '../Resources/strings.dart'; | ||
|
||
class AppRoute{ | ||
Route? generateRoute(RouteSettings settings){ | ||
switch(settings.name){ | ||
case Res.home: | ||
return MaterialPageRoute(builder: (_) => StartScreen()); | ||
case Res.gamePage: | ||
return MaterialPageRoute(builder: (_) => GamePage()); | ||
case Res.rateUs: | ||
return MaterialPageRoute(builder: (_) => RateUs()); | ||
case Res.settings: | ||
return MaterialPageRoute(builder: (_) => Settings()); | ||
default: | ||
_errorRoute(); | ||
} | ||
} | ||
|
||
static Route<dynamic> _errorRoute (){ | ||
return MaterialPageRoute(builder: (context) { | ||
return Scaffold( | ||
appBar: AppBar( | ||
title: Text("Error Page"), | ||
backgroundColor: Colors.redAccent, | ||
), | ||
body: Center( | ||
child: Text("Error"), | ||
), | ||
); | ||
},); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,46 +1,32 @@ | ||
// ignore_for_file: prefer_const_constructors, unnecessary_import, unused_local_variable | ||
|
||
import 'package:flappy_bird/Routes/app_routes.dart'; | ||
import 'package:flutter/material.dart'; | ||
import 'package:flutter/services.dart'; | ||
import 'package:hive_flutter/hive_flutter.dart'; | ||
import '../Layouts/Pages/page_start_screen.dart'; | ||
import 'Layouts/Pages/page_start_screen.dart'; | ||
import 'Resources/strings.dart'; | ||
|
||
void main() async{ | ||
await Hive.initFlutter(); | ||
var box = await Hive.openBox('user'); | ||
runApp( | ||
MaterialApp( | ||
home: MyApp(), | ||
debugShowCheckedModeBanner: false, | ||
), | ||
); | ||
runApp(MyApp()); | ||
} | ||
|
||
class MyApp extends StatefulWidget { | ||
class MyApp extends StatelessWidget { | ||
const MyApp({Key? key}) : super(key: key); | ||
|
||
@override | ||
State<MyApp> createState() => _MyAppState(); | ||
} | ||
|
||
class _MyAppState extends State<MyApp> { | ||
|
||
@override | ||
void initState() { | ||
super.initState(); | ||
} | ||
|
||
@override | ||
void dispose() { | ||
super.dispose(); | ||
} | ||
|
||
@override | ||
Widget build(BuildContext context) { | ||
SystemChrome.setPreferredOrientations([ | ||
DeviceOrientation.portraitUp, | ||
DeviceOrientation.portraitDown, | ||
]); | ||
return StartScreen(); | ||
return MaterialApp( | ||
home: StartScreen(), | ||
debugShowCheckedModeBanner: false, | ||
initialRoute: Res.home, | ||
onGenerateRoute: AppRoute().generateRoute, | ||
); | ||
} | ||
} | ||
} |