Olá, fiz um projeto simples, está tudo funcionando até as funções, só não consigo trazer as informações. Se alguém souber uma forma mais simples para eu aprender, estou usando nesse projeto inherited.
main.dart
import 'package:flutter/material.dart';
import 'package:google_fonts/google_fonts.dart';
import 'database/inherited_planet.dart';
import 'screen/initial_screen_planet.dart';
void main() {
runApp(const MyAppPlanet());
}
class MyAppPlanet extends StatefulWidget {
const MyAppPlanet({Key? key}) : super(key: key);
@override
State<MyAppPlanet> createState() => _MyAppPlanetState();
}
class _MyAppPlanetState extends State<MyAppPlanet> {
@override
Widget build(BuildContext context) {
return MaterialApp(
title: 'Calculadora Peso-Planetas',
theme: ThemeData(
primarySwatch: Colors.grey,
appBarTheme: const AppBarTheme(
elevation: 0,
backgroundColor: Colors.black,
titleTextStyle: TextStyle(color: Colors.white),
),
textTheme: GoogleFonts.bitterTextTheme(),
),
darkTheme: ThemeData.dark(),
themeMode: ThemeMode.light,
home: InheritedPlanet(
child: InitialScreenPlanet(taskPlanetContext: context)),
// //home: InheritedPlanet(child: MainScreenWight(taskPlanetContext: context)),
// ),
);
}
}
initial_screen_planet.dart
import 'package:flutter/material.dart';
import '../database/inherited_planet.dart';
import 'main_screen_wight.dart';
class InitialScreenPlanet extends StatefulWidget {
InitialScreenPlanet({Key? key, required BuildContext taskPlanetContext})
: super(key: key);
@override
State<InitialScreenPlanet> createState() => _InitialScreenPlanetState();
}
class _InitialScreenPlanetState extends State<InitialScreenPlanet> {
@override
Widget build(BuildContext context) {
return Scaffold(
appBar: AppBar(
title: Text('Planet Calculator', style: TextStyle(fontSize: 20)),
//Botão para colocar seu peso
actions: [
Padding(
padding: const EdgeInsets.all(10.0),
child: IconButton(
onPressed: () {
Navigator.push(
context,
MaterialPageRoute(
builder: (contextNew) => MainScreenWight(
taskPlanetContext: context,
)),
).then((value) => setState(() {}));
},
icon: Icon(
Icons.add,
size: 30,
color: Colors.white,
)),
)
],
),
body: Container(
height: double.infinity,
width: double.infinity,
color: Colors.black,
//color: Color.fromRGBO(137, 171, 184, 1),
child: Padding(
padding: const EdgeInsets.all(8.0),
child: ListView(
children: InheritedPlanet.of(context).planetTaskFixa,
),
),
),
);
}
}