Helllo, can somebody clarify it to me, why after I press the buttons so as to add/take away a brand new process (elevated buttons on the finish of the primary code) the display isn’t up to date? I must hit scorching reload to see the brand new process, after I print the taskList I see the brand new process
Helllo, can somebody clarify it to me, why after I press the buttons so as to add/take away a brand new process (elevated buttons on the finish of the primary code) the display isn’t up to date? I must hit scorching reload to see the brand new process, after I print the taskList I see the brand new process
void most important() {
runApp(MyApp());
}
class MyApp extends StatefulWidget {
const MyApp({tremendous.key});
@override
State<MyApp> createState() => _MyAppState();
}
class _MyAppState extends State<MyApp> {
Checklist<Activity> taskList = [
Task(
nome: "Aprender Flutter",
imageSrc: "assets/images/fluttericon.png",
diff: 5),
Task(nome: "Meditar", imageSrc: "assets/images/ying.jpg", diff: 4),
Task(nome: "Task 3", diff: 3),
];
bool opacidade = true;
// This widget is the foundation of your software.
@override
Widget construct(BuildContext context) {
return MaterialApp(
residence: Scaffold(
appBar: AppBar(title: const Textual content("Flutter App")),
physique: AnimatedOpacity(
opacity: opacidade ? 1 : 0,
length: const Length(milliseconds: 500),
youngster: ListView(
kids: taskList,
),
),
persistentFooterButtons: [
ElevatedButton(
onPressed: () {
setState(() {
opacidade = !opacidade;
});
},
child: opacidade
? const Icon(Icons.remove_red_eye_outlined)
: const Icon(Icons.remove_red_eye)),
ElevatedButton(
onPressed: () {
setState(() {
taskList.add(Task(nome: 'New Task', diff: 1));
});
},
child: const Icon(Icons.add_task)),
ElevatedButton(
onPressed: () {
setState(() {
int i = taskList.length - 1;
taskList.removeAt(i);
print(taskList);
});
},
child: const Icon(Icons.delete_sharp))
],
),
);
}
}
class Activity extends StatefulWidget {
closing String nome;
closing String? imageSrc;
closing int diff;
const Activity({Key? key, required this.nome, required this.diff, this.imageSrc})
: tremendous(key: key);
@override
State<Activity> createState() => _TaskState();
}
class _TaskState extends State<Activity> {
int nivel = 0;
@override
Widget construct(BuildContext context) {
return Padding(
padding: const EdgeInsets.all(6.0),
youngster: Stack(
kids: [
Container(
height: 140,
decoration: BoxDecoration(
borderRadius: BorderRadius.circular(5), color: Colors.blue),
),
Column(
children: [
Container(
decoration: BoxDecoration(
borderRadius: BorderRadius.circular(5),
color: Colors.grey.shade200),
height: 100,
child: Row(
mainAxisAlignment: MainAxisAlignment.spaceBetween,
children: [
Container(
decoration: BoxDecoration(
borderRadius: BorderRadius.circular(5),
color: Colors.black),
width: 85,
height: 100,
child: ClipRRect(
borderRadius: BorderRadius.circular(5),
child: Image.asset(
widget.imageSrc ??
"assets/images/no.png",
fit: BoxFit.fill,
),
),
),
Container(
width: 200,
alignment: Alignment.centerLeft,
child: Column(
mainAxisAlignment: MainAxisAlignment.spaceEvenly,
crossAxisAlignment: CrossAxisAlignment.start,
children: [
Text(widget.nome,
style: const TextStyle(
fontSize: 25,
overflow: TextOverflow.ellipsis)),
Difficulty(difficulty: widget.diff)
],
),
),
Padding(
padding: const EdgeInsets.all(8.0),
youngster: SizedBox(
top: 50,
width: 58,
youngster: ElevatedButton(
onPressed: () {
setState(() {
nivel++;
if (nivel >= (widget.diff * 10)) {
nivel = (widget.diff * 10);
}
});
},
youngster: Column(
crossAxisAlignment: CrossAxisAlignment.heart,
mainAxisAlignment: MainAxisAlignment.spaceEvenly,
kids: const [
Icon(Icons.keyboard_double_arrow_up),
Text(
"Up",
style: TextStyle(
color: Colors.white, fontSize: 10),
)
],
)),
),
)
],
),
),
Padding(
padding: const EdgeInsets.all(8.0),
youngster: Row(
mainAxisAlignment: MainAxisAlignment.spaceBetween,
kids: [
SizedBox(
width: 200,
child: LinearProgressIndicator(
color: Colors.white,
value: (nivel / widget.diff) / 10,
)),
Text("Nível: $nivel",
style:
const TextStyle(color: Colors.white, fontSize: 15)),
],
),
)
],
)
],
),
);
}
}