From 374728da45a4e0555c033e0fc07616cb67f9b54a Mon Sep 17 00:00:00 2001 From: Grail Finder Date: Sun, 27 Apr 2025 08:41:23 +0300 Subject: [PATCH] Feat: add pages and navigation between them; random mass --- lib/main.dart | 33 ++++++------------- lib/pages/gain_room.dart | 43 +++++++++++++++++++++++++ lib/pages/home.dart | 68 ++++++++++++++++++++++++++++++++++++++++ lib/pages/lose_room.dart | 43 +++++++++++++++++++++++++ test/widget_test.dart | 2 +- 5 files changed, 165 insertions(+), 24 deletions(-) create mode 100644 lib/pages/gain_room.dart create mode 100644 lib/pages/home.dart create mode 100644 lib/pages/lose_room.dart diff --git a/lib/main.dart b/lib/main.dart index 89335bf..1b558bc 100644 --- a/lib/main.dart +++ b/lib/main.dart @@ -1,36 +1,23 @@ 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(){ runApp(TheApp()); + // runApp( + // MaterialApp( + // title: "title", + // home: TheApp(), + // ), + // ); } class TheApp extends StatelessWidget { - const TheApp({super.key}); - @override Widget build(BuildContext context) { return MaterialApp( - // theme:, - 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"), - ], - ), - ) + home: Home(), ); } } diff --git a/lib/pages/gain_room.dart b/lib/pages/gain_room.dart new file mode 100644 index 0000000..c6723d3 --- /dev/null +++ b/lib/pages/gain_room.dart @@ -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 createState() => _GainRoomState(); +} + + +class _GainRoomState extends State{ + //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()), + ], + ), + ), + ); + } +} \ No newline at end of file diff --git a/lib/pages/home.dart b/lib/pages/home.dart new file mode 100644 index 0000000..d732d4d --- /dev/null +++ b/lib/pages/home.dart @@ -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 createState() => _HomeState(); +} + +class _HomeState extends State{ + //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()), + ); + }, + ), + ], + ), + ); + } +} diff --git a/lib/pages/lose_room.dart b/lib/pages/lose_room.dart new file mode 100644 index 0000000..400ab48 --- /dev/null +++ b/lib/pages/lose_room.dart @@ -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 createState() => _LoseRoomState(); +} + + +class _LoseRoomState extends State{ + //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()), + ], + ), + ), + ); + } +} \ No newline at end of file diff --git a/test/widget_test.dart b/test/widget_test.dart index fb0f8b1..95c2097 100644 --- a/test/widget_test.dart +++ b/test/widget_test.dart @@ -13,7 +13,7 @@ import 'package:fitneschi/main.dart'; void main() { testWidgets('Counter increments smoke test', (WidgetTester tester) async { // Build our app and trigger a frame. - await tester.pumpWidget(const MyApp()); + await tester.pumpWidget(const TheApp()); // Verify that our counter starts at 0. expect(find.text('0'), findsOneWidget);