Change int value to 0 via button
142
Let's try
import 'dart:ui';
import 'package:flutter/material.dart';
void main() => runApp(MyApp());
class MyApp extends StatelessWidget {
// This widget is the root of your application.
@override
Widget build(BuildContext context) {
return MaterialApp(
title: 'Flutter Demo',
home: Test(),
);
}
}
class Test extends StatefulWidget {
@override
State<StatefulWidget> createState() {
return _TestState();
}
}
class _TestState extends State<Test> {
int counter = 0;
@override
Widget build(BuildContext context) {
return Scaffold(
floatingActionButton: FloatingActionButton(
child: InkWell(
child: Icon(Icons.add),
onTap: () {
setState(() {
counter++;
});
},
),
),
appBar: AppBar(
title: Text('My App'),
),
body: Center(
child: Column(
children: [
Text("$counter"),
TextButton(
onPressed: () {
setState(() {
counter = 0;
});
},
child: Text("Reset button"),
),
],
),
));
}
}
output:
Comments
-
Zoe stands with Ukraine over 1 year
I am developing an counter app, and I have this floating action button which displays the amount of times it's been clicked. I want to create a reset clicks button, where the amount of the current clicks of the floating action button changes into 0 via the button.
-
NirmalCode over 2 yearsInclude the code you tried, Errors that occurred, etc.
-
Jahidul Islam over 2 yearsplease check the answer
-