Open berkeresvan opened 6 months ago
import 'package:flutter/material.dart';
class sayacWidget extends StatefulWidget { const sayacWidget({super.key});
@override
State
class sayacWidgetState extends State
@override Widget build(BuildContext context) { return Text( _sayac.toString(), style: Theme.of(context).textTheme.headlineLarge, ); } }
import 'package:flutter/material.dart'; import 'package:textfield/sayac_state.dart';
class globalkeykullanimi extends StatefulWidget { const globalkeykullanimi({super.key});
@override State createState() => globalkeykullanimiState();
}
class globalkeykullanimiState extends State {
final sayacWidgetkey = GlobalKey();
@override
Widget build(BuildContext context) {
return Scaffold(
appBar: AppBar(
title: Text("Global Key Kullanımı"),
),
body: Center(
child: Column(
mainAxisAlignment: MainAxisAlignment.center,
children: [
Text("Butonaa basılma miktarı"),
sayacWidget(
key: sayacWidgetkey,
),
],
),
),
floatingActionButton: FloatingActionButton(
onPressed: () {
sayacWidgetkey.currentState!.arttir();
},
child: Icon(Icons.add),
),
);
}
}