https://github.com/flutter/samples github sayfasından bütün numunelik programları indirdim, 104.2 MB’lik bir zip dosyası.
zip file içindeki
game_template
klasörünü bütünüyle kendi çalışma yerime transfer ettim.O klasörü VS Code’da açınca, VS Code kendi kendine bazı yeni indirimler gerektiğine hükmetti ve
game_template
klasörüne yeni bir kaç dosya daha ekledi. Ne olduklarını farkedemedim.
English or Turkish
Halim’in Günlüğü, Türkçe bir blog. O yüzden, Flutter sayfalarını da Türkçe başladım. Ama zor oldu. Şimdilik İngilizce devam edeceğim. İleride vakit olursa Türkçe’ye çeviririm diye umuyorum🤓
On my Windows Computer
Occasionally, I duplicate my macOS work on my Windows computer. When I did a flutter doctor in VS Code, it gave two errors:
install cmd-lines tools
sort out the Android licenses
I also had an additional error in the VS Code. All my “package:” imports could not be found with the error note that “target uri does not exist“. Here is how I resolved these three issues.
Installing cmd-line tools
I had to the following on my Windows computer:
Start Android Studio
Select Tools/SDK Manager
Click on the SDK Tools
Install Command-line Tool
I had to restart VS Code after this.
Android licenses
This was easy to fix.
flutter doctor --android-licenses
Review licenses yet not accepted
Accept all
Target uri does not exist
From VS Code terminal run
flutter packages get
This removed the red lines from the ‘package:…’ imports for me. There was a warning: “Building with plugins requires symlink support”, which I am ignoring.
running it as an macOS app
When I run it for macOS (not a mobile phone emulator), it gives an xcode warning as
objc[5039]: Class AMSupportURLConnectionDelegate is implemented in both /usr/lib/libauthinstall.dylib (0x20017b788) and /System/Library/PrivateFrameworks/MobileDevice.framework/Versions/A/MobileDevice (0x11043c2c8). One of the two will be used. Which one is undefined.
objc[5039]: Class AMSupportURLSession is implemented in both /usr/lib/libauthinstall.dylib (0x20017b7d8) and /System/Library/PrivateFrameworks/MobileDevice.framework/Versions/A/MobileDevice (0x11043c318). One of the two will be used. Which one is undefined.
--- xcodebuild: WARNING: Using the first of multiple matching destinations:
{ platform:macOS, arch:arm64, id:00008103-001C50A40A53001E }
{ platform:macOS, arch:x86_64, id:00008103-001C50A40A53001E }
This is only a warning because the flutter game start after a while as seen below:
This xcode warning issue is being addressed on this github page:
It is something to consider in the future. For the time being, I ignore it.
running it as pixel 5 API 32 emulator
Click on the bottom right corner:
Then Run/Without Debugging
while the editor window is on main.dart
.
Unlike macOS run, there are no warnings when the Pixel 5 phone emulator screen is starting. I continue with the emulator.
Logging
This is important for debugging purposes. game_template uses a logger
import 'package:logging/logging.dart'; // Line 10
Logger.root.level = Level.WARNING; // Line 63
Logger _log = Logger('main.dart'); // Line 122
Filip who I think posted the game_plate example that I am using here also has a good YouTube video on logging.
Installing the logger
The logger dependency is defined in pubspec.yaml
:
If using VS Code, adding this line to the pubspec.yaml
file is equivalent to adding the package using flutter pub add logging
.
Best Practice
Declare a different logger for each widget file ,
Logger _log = Logger('xxxx'); //
New Logger named xxxx
Set the logging level in main.dart. This will apply to all loggers in all widgets because the Logger is a singleton. For example,
Logger.root.level = Level.INFO;
Logger.root.onRecord.listen((record) {
debugPrint('${record.level.name}: ${record.time}: '
'${record.loggerName}: '
'${record.message}');
});
_log.info("Example info level message");
_log.fine("This will not appear if LEVEL is set as FINE");
_log.shout("Always iutout unless Level is set OFF");
In the logging pane, use filtering to bring out only the messages from the widgets you want.
The Level was set to INFO in the above code block. This means all messages at or above the INFO level are sent to the
onRecord
stream. Available levels are:Level.OFF
Level.SHOUT
Level.SEVERE
Level.WARNING
Level.INFO
Level.CONFIG
Level.FINE
Level.FINER
Level.FINEST
For example, you can sprinkle your code with messages at the level
FINE
knowing that they would not appear unless you setLogger.root.level
toLevel.FINE
.
Ignore the rest of this post. They are the notes I took when I am trying to figure out how Logger
worked. The “Best Practice” section above is the last section I wrote in this post.
Working with the logger
https://pub.dev/packages/logging
VS Code içinde, Dart : OpenDev Tools
içinde Open Logging Page
opsiyonu seçilirse (see https://docs.flutter.dev/development/tools/devtools/logging for info on this panel), VS Code yeni bir pano açıyor ve program işlerken logging
mesajları orda oluyor.
I set
Logger.root.level = Level.OFF; // Line 66
I added the following
debugPrint
line (Line 65)
debugPrint("$Logger, Level = ${Logger.root.level}");
This generated the following output on the Logging pane:
How to get rid of the other lines on the Logging pane
The debugPrint outputs to stdout. In the logging panel, flutter execution outputs other channels as well, e.g. gc, provider:provide…, etc. By clicking on them, one can see the details. For example, I clicked on gc:
I am sure gc and debugger messages on the logging pane are useful in some way but I do not know enough to make use of it.
I would like to be able to display only my own log messages but I do not know how to display ONLY stdout. The only options are:
Use the filter option (the upper right corner on the Logging pane):
Sort them out and put the stdout on the top using the kind tab at the top:
Use the Search option at the top of the logging pane to search for your messages (you should know what word to search for), e.g.
I think I prefer filtering.
Use the main.dart logger in other files of your application
I think the recommended practice is to declare a new logger variable for each widget. However, it is possible to use the same logger in all files.
The Logger
declared in main.dart file can be used in other files of your application. You have to import
it to those files. However, there is a trick to it. The game_template
example uses the name _log
. Variable names starting with ‘_
’ cannot be exported. Therefore, I define another logger called globallog
:
Logger globallog = Logger('global'); // I declare the variable
globallog.shout('Going full screen'); // Using it in main.dart
// import it to another file, e.g. player_progress.dart
import "package:game_template/main.dart" show globallog;
globallog.shout('player_progress: Level=$level'); // Use there
Dart language learning
game_template
dosyalarında dikkatimi çeken noktaları aşağıda kaydediyorum. Dosya adından sonraki numara satır numarasını temsil ediyor.
main.dart - 40
FirebaseCrashlytics? crashlytics;
Bu satırda yaratılan crashlytics,
null
değer alabilir. Soru işareti, bunu ifade ediyor. Aksi halde, Dart değişkenleri normal olarak null
değer alamaz. Mesela,
int a = null;
derseniz hata verir.
Eğer bir değişken null
olabilirse, onu deklare ederken isimden sonra ? kullanılır. Mesela, int a?;
Daha fazla bilgi için: https://dart.dev/codelabs/dart-cheatsheet#nullable-variables