Skip to content

Instantly share code, notes, and snippets.

@romanejaquez
Last active March 9, 2022 21:42
Show Gist options
  • Save romanejaquez/196f4b64e7b135c7bb241e2ffbd28981 to your computer and use it in GitHub Desktop.
Save romanejaquez/196f4b64e7b135c7bb241e2ffbd28981 to your computer and use it in GitHub Desktop.
import 'package:flutter/material.dart';
const Color darkBlue = Color.fromARGB(255, 18, 32, 47);
void main() {
runApp(MyApp());
}
class MyApp extends StatelessWidget {
@override
Widget build(BuildContext context) {
return MaterialApp(
debugShowCheckedModeBanner: false,
home: Scaffold(
body: Center(
child: donateMain(),
),
),
);
}
}
class donateMain extends StatefulWidget {
const donateMain({Key? key}) : super(key: key);
@override
State<donateMain> createState() => _donateMainState();
}
class _donateMainState extends State<donateMain> {
int currentAmount = 0; //i want to call currentAmount
void _setAmount(int amount) {
setState(() {
currentAmount = amount;
});
}
@override
Widget build(BuildContext context) {
return Scaffold(
appBar: AppBar(
centerTitle: true,
title: Text('$currentAmount'),
),
body: ButtonsRow(
amount: currentAmount,
onSetAmount: _setAmount,
),
);
}
}
class ButtonsRow extends StatelessWidget {
const ButtonsRow({
Key? key,
required this.amount,
required this.onSetAmount,
}) : super(key: key);
final void Function(int) onSetAmount;
final int amount;
@override
Widget build(BuildContext context) {
return SafeArea(
child: SingleChildScrollView(
child: Column(children: [
GestureDetector(
onTap: () {
onSetAmount(100);
},
child: Container(
child: Center(
child: Text(
"€$amount", // this is where i want to access current amount
style: TextStyle(
fontSize: 35, color: Colors.black, fontWeight: FontWeight.bold),
textAlign: TextAlign.center,
),
)
)
)
]
)
)
);
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment