Feat: add pages and navigation between them; random mass
This commit is contained in:
@ -1,36 +1,23 @@
|
|||||||
import 'package:flutter/material.dart';
|
import 'package:flutter/material.dart';
|
||||||
|
import 'package:fitneschi/pages/home.dart';
|
||||||
|
import 'package:fitneschi/pages/gain_room.dart';
|
||||||
|
import 'package:fitneschi/pages/lose_room.dart';
|
||||||
|
|
||||||
void main(){
|
void main(){
|
||||||
runApp(TheApp());
|
runApp(TheApp());
|
||||||
|
// runApp(
|
||||||
|
// MaterialApp(
|
||||||
|
// title: "title",
|
||||||
|
// home: TheApp(),
|
||||||
|
// ),
|
||||||
|
// );
|
||||||
}
|
}
|
||||||
|
|
||||||
class TheApp extends StatelessWidget {
|
class TheApp extends StatelessWidget {
|
||||||
const TheApp({super.key});
|
|
||||||
|
|
||||||
@override
|
@override
|
||||||
Widget build(BuildContext context) {
|
Widget build(BuildContext context) {
|
||||||
return MaterialApp(
|
return MaterialApp(
|
||||||
// theme:,
|
home: Home(),
|
||||||
home: Scaffold(
|
|
||||||
appBar: AppBar(
|
|
||||||
backgroundColor: Colors.deepPurple,
|
|
||||||
title: const Text("Tamagochi 2.0"),
|
|
||||||
centerTitle: true,
|
|
||||||
),
|
|
||||||
body: Column(
|
|
||||||
children: [
|
|
||||||
Row(
|
|
||||||
mainAxisAlignment: MainAxisAlignment.center,
|
|
||||||
children: [
|
|
||||||
Icon(Icons.scale),
|
|
||||||
Text("Body Mass"),
|
|
||||||
],
|
|
||||||
),
|
|
||||||
Text("Fat Pct"),
|
|
||||||
Text("Daily Caloric Norm"),
|
|
||||||
],
|
|
||||||
),
|
|
||||||
)
|
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
43
lib/pages/gain_room.dart
Normal file
43
lib/pages/gain_room.dart
Normal file
@ -0,0 +1,43 @@
|
|||||||
|
import 'package:flutter/material.dart';
|
||||||
|
import 'dart:math';
|
||||||
|
|
||||||
|
int randomInRange(int min, int max) {
|
||||||
|
final random = Random();
|
||||||
|
return min + random.nextInt(max - min + 1);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
class GainRoom extends StatefulWidget {
|
||||||
|
const GainRoom({super.key});
|
||||||
|
|
||||||
|
@override
|
||||||
|
State<GainRoom> createState() => _GainRoomState();
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
class _GainRoomState extends State<GainRoom>{
|
||||||
|
//vars
|
||||||
|
int _mass = randomInRange(40, 80);
|
||||||
|
//methods
|
||||||
|
void _gainMass(){
|
||||||
|
setState(() {
|
||||||
|
_mass += randomInRange(1, 3);
|
||||||
|
});
|
||||||
|
}
|
||||||
|
//ui
|
||||||
|
@override
|
||||||
|
Widget build(BuildContext context){
|
||||||
|
return Scaffold(
|
||||||
|
appBar: AppBar(title: Text("Gain Room")),
|
||||||
|
body: Center(
|
||||||
|
child: Column(
|
||||||
|
mainAxisAlignment: MainAxisAlignment.center,
|
||||||
|
children: [
|
||||||
|
Text("Current mass:"),
|
||||||
|
Text(_mass.toString()),
|
||||||
|
],
|
||||||
|
),
|
||||||
|
),
|
||||||
|
);
|
||||||
|
}
|
||||||
|
}
|
68
lib/pages/home.dart
Normal file
68
lib/pages/home.dart
Normal file
@ -0,0 +1,68 @@
|
|||||||
|
import 'package:flutter/material.dart';
|
||||||
|
import 'package:fitneschi/pages/gain_room.dart';
|
||||||
|
import 'package:fitneschi/pages/lose_room.dart';
|
||||||
|
import 'dart:math';
|
||||||
|
|
||||||
|
int randomInRange(int min, int max) {
|
||||||
|
final random = Random();
|
||||||
|
return min + random.nextInt(max - min + 1);
|
||||||
|
}
|
||||||
|
|
||||||
|
class Home extends StatefulWidget{
|
||||||
|
const Home({super.key});
|
||||||
|
|
||||||
|
@override
|
||||||
|
State<Home> createState() => _HomeState();
|
||||||
|
}
|
||||||
|
|
||||||
|
class _HomeState extends State<Home>{
|
||||||
|
//vars
|
||||||
|
int _mass = randomInRange(40, 80);
|
||||||
|
//methods
|
||||||
|
void _gainMass(){
|
||||||
|
setState(() {
|
||||||
|
_mass += randomInRange(1, 3);
|
||||||
|
});
|
||||||
|
}
|
||||||
|
//ui
|
||||||
|
@override
|
||||||
|
Widget build(BuildContext context) {
|
||||||
|
return Scaffold(
|
||||||
|
appBar: AppBar(
|
||||||
|
backgroundColor: const Color.fromARGB(255, 38, 34, 46),
|
||||||
|
title: const Text("Tamagochi 2.0"),
|
||||||
|
centerTitle: true,
|
||||||
|
),
|
||||||
|
body: Column(
|
||||||
|
children: [
|
||||||
|
Row(
|
||||||
|
mainAxisAlignment: MainAxisAlignment.center,
|
||||||
|
children: [
|
||||||
|
Icon(Icons.scale),
|
||||||
|
Text("Body Mass: "),
|
||||||
|
Text(_mass.toString()),
|
||||||
|
],
|
||||||
|
),
|
||||||
|
Text("Fat Pct"),
|
||||||
|
Text("Daily Caloric Norm"),
|
||||||
|
ElevatedButton(
|
||||||
|
child: Text("Gain Mass"),
|
||||||
|
onPressed: (){
|
||||||
|
Navigator.push(context,
|
||||||
|
MaterialPageRoute(builder: (context) => GainRoom()),
|
||||||
|
);
|
||||||
|
},
|
||||||
|
),
|
||||||
|
ElevatedButton(
|
||||||
|
child: Text("Lose Mass"),
|
||||||
|
onPressed: (){
|
||||||
|
Navigator.push(context,
|
||||||
|
MaterialPageRoute(builder: (context) => LoseRoom()),
|
||||||
|
);
|
||||||
|
},
|
||||||
|
),
|
||||||
|
],
|
||||||
|
),
|
||||||
|
);
|
||||||
|
}
|
||||||
|
}
|
43
lib/pages/lose_room.dart
Normal file
43
lib/pages/lose_room.dart
Normal file
@ -0,0 +1,43 @@
|
|||||||
|
import 'package:flutter/material.dart';
|
||||||
|
import 'dart:math';
|
||||||
|
|
||||||
|
int randomInRange(int min, int max) {
|
||||||
|
final random = Random();
|
||||||
|
return min + random.nextInt(max - min + 1);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
class LoseRoom extends StatefulWidget {
|
||||||
|
const LoseRoom({super.key});
|
||||||
|
|
||||||
|
@override
|
||||||
|
State<LoseRoom> createState() => _LoseRoomState();
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
class _LoseRoomState extends State<LoseRoom>{
|
||||||
|
//vars
|
||||||
|
int _mass = randomInRange(40, 80);
|
||||||
|
//methods
|
||||||
|
void _loseMass(){
|
||||||
|
setState(() {
|
||||||
|
_mass -= randomInRange(1, 3);
|
||||||
|
});
|
||||||
|
}
|
||||||
|
// ui
|
||||||
|
@override
|
||||||
|
Widget build(BuildContext context){
|
||||||
|
return Scaffold(
|
||||||
|
appBar: AppBar(title: Text("Lose Room")),
|
||||||
|
body: Center(
|
||||||
|
child: Column(
|
||||||
|
mainAxisAlignment: MainAxisAlignment.center,
|
||||||
|
children: [
|
||||||
|
Text("Current mass:"),
|
||||||
|
Text(_mass.toString()),
|
||||||
|
],
|
||||||
|
),
|
||||||
|
),
|
||||||
|
);
|
||||||
|
}
|
||||||
|
}
|
@ -13,7 +13,7 @@ import 'package:fitneschi/main.dart';
|
|||||||
void main() {
|
void main() {
|
||||||
testWidgets('Counter increments smoke test', (WidgetTester tester) async {
|
testWidgets('Counter increments smoke test', (WidgetTester tester) async {
|
||||||
// Build our app and trigger a frame.
|
// Build our app and trigger a frame.
|
||||||
await tester.pumpWidget(const MyApp());
|
await tester.pumpWidget(const TheApp());
|
||||||
|
|
||||||
// Verify that our counter starts at 0.
|
// Verify that our counter starts at 0.
|
||||||
expect(find.text('0'), findsOneWidget);
|
expect(find.text('0'), findsOneWidget);
|
||||||
|
Reference in New Issue
Block a user