Skip to content

Instantly share code, notes, and snippets.

@malibayram
Last active June 21, 2023 00:03
Show Gist options
  • Select an option

  • Save malibayram/75cae6714fa83c549e486c27aa2b6de1 to your computer and use it in GitHub Desktop.

Select an option

Save malibayram/75cae6714fa83c549e486c27aa2b6de1 to your computer and use it in GitHub Desktop.
// Copyright (c) 2019, the Dart project authors. Please see the AUTHORS file
// for details. All rights reserved. Use of this source code is governed by a
// BSD-style license that can be found in the LICENSE file.
// calback => başka bir fonksiyona parametre olarak gönderilen fonksiyon
// Birinci yönü kullanım şekli
// İkinci yönü ise tanımlanma şekli
import 'dart:io';
import 'package:flutter/material.dart';
void main() => runApp(MyApp());
class MyApp extends StatelessWidget {
@override
Widget build(BuildContext context) {
return MaterialApp(
title: 'Flutter Demo',
debugShowCheckedModeBanner: false,
theme: ThemeData(
primarySwatch: Colors.blue,
),
home: const MyHomePage(title: 'Flutter Demo Home Page'),
);
}
}
class MyHomePage extends StatefulWidget {
final String title;
const MyHomePage({
Key? key,
required this.title,
}) : super(key: key);
@override
_MyHomePageState createState() => _MyHomePageState();
}
class _MyHomePageState extends State<MyHomePage> {
int _counter = 0;
void _incrementCounter() {
setState(() {
_counter++;
});
}
@override
Widget build(BuildContext context) {
return Scaffold(
appBar: AppBar(
title: Text(widget.title),
),
body: Center(
child: Column(
mainAxisAlignment: MainAxisAlignment.center,
children: [
const Text(
'You have pushed the button this many times:',
),
Text(
'$_counter',
style: Theme.of(context).textTheme.headline4,
),
YeniButton(
buttonText: "Yeni Button",
buttonFunction: (int volume) {
_counter += volume;
setState(() {});
_incrementCounter; // bu şekilde yazıldığında işlem tetiklenmez
},
),
],
),
),
floatingActionButton: FloatingActionButton(
// onPressed: _incrementCounter, // Burada biz herhangi bir fonksiyon ÇAĞIRmıyoruz
onPressed: () {
_incrementCounter();
},
tooltip: 'Increment',
child: const Icon(Icons.add),
),
);
}
}
// typedef => takma isim
// type definition => yeni bir tip tanımlama
typedef Increment = Function(int);
class YeniButton extends StatelessWidget {
final String buttonText;
final Increment buttonFunction;
const YeniButton({
Key? key,
required this.buttonText,
required this.buttonFunction,
}) : super(key: key);
@override
Widget build(BuildContext context) {
return TextButton(
child: Text(buttonText),
onPressed: () {
buttonFunction(3);
},
);
}
}
class DosyaOkuyucu<I> {
static DosyaOkuyucu? _okuyucu;
final File dosya;
late String icerik;
factory DosyaOkuyucu(File gelenDosya) {
_okuyucu ??= DosyaOkuyucu<I>._(gelenDosya);
return _okuyucu! as DosyaOkuyucu<I>;
}
DosyaOkuyucu._(this.dosya) {
print("yeni DosyaOkuyucu oluşturuldu");
if (!dosya.existsSync()) {
dosya.createSync(recursive: true);
}
icerik = dosya.readAsStringSync();
}
void ogrenciEkle(I i) {
icerik = "$icerik\n${i.toString()}";
dosya.writeAsStringSync(icerik);
}
}
class Ogrenci {
final String isim;
final String soyisim;
Ogrenci(this.isim, this.soyisim);
@override
String toString() {
return "İsim: $isim, soyisim: $soyisim";
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment