Last active
May 12, 2020 22:06
-
-
Save stegrams/953a6104fc471d164c8d421c005871b5 to your computer and use it in GitHub Desktop.
Funny state behavior that I can't reproduce
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import 'package:flutter/material.dart'; | |
void main() => runApp(MyApp()); | |
class MyApp extends StatelessWidget { | |
@override | |
Widget build(BuildContext context) { | |
return MaterialApp( | |
title: 'Flutter Demo', | |
home: MyHomePage(), | |
); | |
} | |
} | |
class MyHomePage extends StatefulWidget { | |
MyHomePage({Key key}) : super(key: key); | |
@override | |
_MyHomePageState createState() => _MyHomePageState(); | |
} | |
class _MyHomePageState extends State<MyHomePage> { | |
List<int> productQtys = [10]; | |
String status = 'Status:\n'; | |
@override | |
Widget build(BuildContext context) { | |
return Scaffold( | |
appBar: AppBar( | |
title: Text("Demo"), | |
), | |
body: Center( | |
child: Text( | |
status, | |
), | |
), | |
floatingActionButton: FloatingActionButton( | |
onPressed: () { | |
setState(() { | |
int index = 0; | |
// print(productQtys); | |
status += '\n$productQtys'; | |
if (productQtys[index] != 1) { | |
productQtys[index] = productQtys[index] - 1; | |
} | |
// print(index); | |
status += '\n$index'; | |
// print(productQtys); | |
status += '\n$productQtys'; | |
}); | |
}, | |
tooltip: 'Decrement', | |
child: Icon(Icons.remove), | |
), | |
); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment