본문 바로가기

Dart (Flutter)38

[Dart] Variables 이번 포스팅에서는 변수와 상수에 대해 가볍게 살펴보겠습니다. 다른 언어 경험이 있으시면 쉽게 사용하실 수 있을 거에요. Variables Dart에서 변수를 선언할 때는 var keyword를 사용하거나 type을 명시해서 선언합니다. var keyword를 사용하게 되면, 타입 추론을 통해 타입이 설정됩니다. Local 변수의 경우 일반적으로 var를 이용한 선언이 사용됩니다. void main() { var name = 'HoYa'; int age = 18; } 위의 예제에서 name은 String type으로 추론이 됩니다. 변수를 선언할 때는 기본적으로 초기값이 필요합니다. 만약, 초기값 없이 var keyword를 사용하여 선언한다면 null이 됩니다. void main() { var test;.. 2023. 1. 30.
[Flutter] Desktop Application using Flutter Flutter는 이제 "Build apps for any screen"을 표방하며 멀티 플랫폼 framework이 되었습니다. 기존의 mobile을 넘어 web, desktop은 물론 embedded까지 가능합니다. Install Flutter 기본적으로는 공식 홈페이지를 통하여 설치를 하시면 됩니다. https://docs.flutter.dev/get-started/install Install Install Flutter and get started. Downloads available for Windows, macOS, Linux, and Chrome OS operating systems. docs.flutter.dev 만약 패키지 매니저를 사용하신다면, 더욱 편하게 설치하실 수도 있어요. 전 MAC.. 2023. 1. 25.
[Flutter] Animation Animation makes applications look more gorgeous. AnimatedContainer Widget Flutter provides an AnimatedContainer widget for easy use of animation. Let's take a look at the full code first. import 'package:flutter/material.dart'; import 'dart:math'; void main() { runApp(const MyApp()); } class MyApp extends StatelessWidget { const MyApp({Key? key}) : super(key: key); @override Widget build(BuildCo.. 2022. 4. 3.
[Flutter] File Handling In this posting, we will learn about file handling. path_provider Package This package supports getting commonly used locations on the filesystem. It supports Android, iOS, Linux, macOS, and Windows, but not all methods are supported on all platforms. Refer to the below page for the detailed supported list. https://pub.dev/packages/path_provider Usage Directory tempDir = await getTemporaryDirect.. 2022. 4. 2.
[Flutter] Save Data using Shared Preferences Flutter provides SharedPreferences class that supports saving data to a shared preference file as key-value pair. Prerequisite If you want to use this feature on iOS, it needs cocoapods. Please find the materials on the official site. https://guides.cocoapods.org/using/getting-started.html#installation If you are using homebrew, you can simply install it. $ brew install cocoapods Register Packag.. 2022. 4. 1.
[Flutter] Navigation Flutter supports navigation in a similar way to web development. Register Routes First, let's see the main application. // lib/main.dart import 'package:flutter/material.dart'; void main() { runApp(const MyApp()); } class MyApp extends StatelessWidget { const MyApp({Key? key}) : super(key: key); @override Widget build(BuildContext context) { return MaterialApp( title: 'Navigation Example', theme.. 2022. 3. 30.
[Flutter] How to Use Tab Bar Widget Tab bar is a widely used widget when we make a mobile application. It can help to navigation between pages. Creating Pages First, create pages to navigate. // lib/tab_pages/first_page.dart import 'package:flutter/material.dart'; class FirstPage extends StatelessWidget { @override Widget build(BuildContext context) { return const Scaffold(body: Center(child: Text('This is a first page.'))); } } /.. 2022. 3. 27.
[Flutter] Adding Fonts to Flutter Application Adding fonts to the Flutter application is quite simple. Configuration Create a fonts folder in the project and push the font file that you want to use. Let's add the fonts to the project's configuration file. # pubspec.yaml ... # The following section is specific to Flutter. flutter: ... # To add custom fonts to your application, add a fonts section here, # in this "flutter" section. Each entry.. 2022. 3. 26.
[Flutter] Adding Image to Flutter Application Let's learn about how to add images to the Flutter application. Configuration Let's create an images folder in the project and push the prepared images. Now, open the project configuration file. Adding configurations by referring to the comments. # pubspec.yaml ... # The following section is specific to Flutter. flutter: ... # To add assets to your application, add an assets section, like this: .. 2022. 3. 26.
[Flutter] Life Cycle The only stateful widget has a 10-step life cycle. The stateless widget doesn't have a life cycle because it can't be updated once it is created. 1. createState() A class to inherit StatefulWidget class should call createState() function. This function returns State class that contains other life cycle functions. In other words, you can understand it as a function creating a state of a widget. 2.. 2022. 3. 23.
[Dart] Data Communication with Stream The Stream can guarantee the order of the data. Stream acts like a queue. Stream Example Let's take a look at a simple example. import 'dart:async'; void main() async { var stream = streamSend(10); var sum = await streamReceive(stream); print('Sum: $sum'); } Stream streamSend(int to) async* { for (int i = 1; i print('first: $value')); // 1 stream = Stream.fromIterable([1, 2, 3, 4, 5]); stream.la.. 2022. 3. 20.
[Dart] Handling JSON Dart supports handling JSON. You need to import convert library. Decoding JSON String jsonDecode() method converts JSON string into List that is dynamic type. import 'dart:convert'; void main() { var jsonString = ''' [{"key1": "value1"}, {"key2": "value2"}] '''; var decodedString = jsonDecode(jsonString); print(decodedString is List); // true print(decodedString[0]); // {key1: value1} print(deco.. 2022. 3. 12.