refactored routes to use onGenerateRoute
This commit is contained in:
parent
5bde7ee9c2
commit
3b0c87328c
3 changed files with 37 additions and 18 deletions
|
@ -1,5 +1,6 @@
|
|||
import 'package:flutter/material.dart';
|
||||
import 'package:ohthatsa/pages/YearsPage.dart';
|
||||
import 'package:ohthatsa/pages/practice/PracticeSetup.dart';
|
||||
|
||||
import 'package:ohthatsa/pages/practice/PracticeSetupPage.dart';
|
||||
import 'package:ohthatsa/pages/practice/month/MonthPracticePage.dart';
|
||||
|
@ -15,15 +16,31 @@ class OhThatsA extends StatelessWidget {
|
|||
Widget build(BuildContext context) {
|
||||
return MaterialApp(
|
||||
title: "OhThatsA",
|
||||
initialRoute: '/years',
|
||||
routes: {
|
||||
'/monthValues': (context) => MonthValuesPage(),
|
||||
'/years': (context) => YearsPage(),
|
||||
'/practice/setup': (context) => PracticeSetupPage(),
|
||||
'/practice/month/practice': (context) => MonthPracticePage(),
|
||||
}
|
||||
onGenerateRoute: RouteGenerator.generateRoute,
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
class RouteGenerator {
|
||||
static Route<dynamic> generateRoute(RouteSettings settings){
|
||||
switch(settings.name){
|
||||
case "/monthValues": {
|
||||
return MaterialPageRoute(builder: (context) => MonthValuesPage());
|
||||
}
|
||||
case "/years": {
|
||||
return MaterialPageRoute(builder: (context) => YearsPage());
|
||||
}
|
||||
case "/practice/setup": {
|
||||
return MaterialPageRoute(builder: (context) => PracticeSetupPage());
|
||||
}
|
||||
case "/practice/month/practice": {
|
||||
return MaterialPageRoute(builder: (context) => MonthPracticePage(settings.arguments));
|
||||
}
|
||||
default: {
|
||||
return MaterialPageRoute(builder: (context) => YearsPage());
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
|
|
@ -1,7 +1,7 @@
|
|||
import 'package:flutter/material.dart';
|
||||
import 'package:numberpicker/numberpicker.dart';
|
||||
import 'package:ohthatsa/AppDrawer.dart';
|
||||
import 'file:///D:/dev/projects/ohthatsa/lib/pages/practice/PracticeSetup.dart';
|
||||
import 'package:ohthatsa/pages/practice/PracticeSetup.dart';
|
||||
|
||||
class PracticeSetupPage extends StatefulWidget {
|
||||
@override
|
||||
|
|
|
@ -1,29 +1,34 @@
|
|||
import 'package:flutter/material.dart';
|
||||
import 'package:ohthatsa/pages/practice/PracticeGenerator.dart';
|
||||
import 'package:ohthatsa/pages/practice/PracticeSetup.dart';
|
||||
import 'package:ohthatsa/pages/practice/month/MonthPracticeGenerator.dart';
|
||||
import 'file:///D:/dev/projects/ohthatsa/lib/pages/practice/PracticeSetup.dart';
|
||||
import 'package:ohthatsa/util/DayCalculator.dart';
|
||||
import 'package:ohthatsa/AppDrawer.dart';
|
||||
import 'package:ohthatsa/util/Months.dart';
|
||||
import 'package:ohthatsa/util/Extensions.dart';
|
||||
import "dart:math";
|
||||
|
||||
import 'MonthPracticeAnswer.dart';
|
||||
|
||||
class MonthPracticePage extends StatefulWidget {
|
||||
final PracticeSetup practiceSetup;
|
||||
MonthPracticePage(
|
||||
this.practiceSetup
|
||||
);
|
||||
@override
|
||||
_MonthPracticeState createState() => _MonthPracticeState();
|
||||
_MonthPracticeState createState() => _MonthPracticeState(practiceSetup);
|
||||
}
|
||||
|
||||
class _MonthPracticeState extends State<MonthPracticePage> {
|
||||
int _startCount = 0;
|
||||
bool _showCorrect = true;
|
||||
|
||||
int _count = 0;
|
||||
int _correct = 0;
|
||||
int _incorrect = 0;
|
||||
bool _showCorrect = true;
|
||||
static final practiceGenerator = MonthPracticeGenerator();
|
||||
List<MonthPracticeAnswer> answers = List<MonthPracticeAnswer>();
|
||||
|
||||
_MonthPracticeState(PracticeSetup practiceSetup){
|
||||
_startCount = practiceSetup.count;
|
||||
_showCorrect = practiceSetup.showCorrect;
|
||||
}
|
||||
Widget getAnswerRow(){
|
||||
List<Widget> answerBoxes = List<Widget>();
|
||||
for(MonthPracticeAnswer answer in answers){
|
||||
|
@ -202,9 +207,6 @@ class _MonthPracticeState extends State<MonthPracticePage> {
|
|||
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
PracticeSetup setup = ModalRoute.of(context).settings.arguments;
|
||||
_startCount = setup.count;
|
||||
_showCorrect = setup.showCorrect;
|
||||
return Scaffold(
|
||||
drawer: AppDrawer(),
|
||||
appBar: AppBar(
|
||||
|
|
Loading…
Add table
Reference in a new issue