Flutter ramka uchun qo'llanma 1-bob. Flutterga kirish Flutter nima. O'rnatish


Download 1.13 Mb.
bet17/27
Sana03.12.2023
Hajmi1.13 Mb.
#1798657
1   ...   13   14   15   16   17   18   19   20   ...   27
Bog'liq
Flutter ramka uchun qo\'llanma 1-bob. Flutterga kirish Flutter ni

Tasvir va tasvir chiqishi

Tasvir vidjeti tasvirlarni ko'rsatish imkonini beradi.


Rasm barcha keng tarqalgan rasm fayl formatlarini qo'llab-quvvatlaydi: JPEG, PNG, GIF (jumladan, animatsiyali), BMP, WebP, WBMP.


Tasvir vidjeti turli manbalardan tasvirlarni olishni qo‘llab-quvvatlaydi. Va manbaga qarab, Image sinfining tegishli konstruktori qo'llaniladi:

Image (): ImageProvider yordamida rasm olish uchun

Image.asset (): AssetBundle va aktiv kaliti yordamida rasm olish uchun


Image.network (): tarmoq manzili yordamida tasvirni olish uchun


Image.file (): File sinfidan foydalanib fayldan rasm olish uchun


Image.memory (): Uint8List klassi yordamida tasvirni olish uchun

Keling, ba'zi konstruktorlarni ko'rib chiqaylik.

Tarmoq orqali tasvirlarni olish


Internetning biron bir joyida joylashgan rasmni ko'rsatish uchun siz tasvir manzili kiritilgan Image.network () konstruktoridan foydalanishingiz kerak:


1
2
3
4
5
6
7
8

import 'package:flutter/material.dart';
void main() {
runApp(Container(
color: Colors.white,
child: Image.network("https://picsum.photos/250?image=9"),
));
}


Mahalliy tasvirni olish


Rasmni ko'rsatishning yana bir varianti Image.asset () konstruktoridir. Bu sizga ilova ichida saqlangan mahalliy tasvirdan foydalanish imkonini beradi.

Tasvirlarni saqlash uchun loyihaga yangi papka qo'shing, biz uni aktivlar deb ataymiz. Ushbu papkada to'g'ridan-to'g'ri tasvir fayllari uchun tasvirlar deb nomlangan yangi papka yarating. Va unga bir nechta rasm faylini qo'ying:



Mening holimda rasm fayli forest.png deb nomlanadi va loyiha ildiziga nisbatan unga boradigan yo'l assets / images / forest.png dir.


Tasvirni yuklash uchun loyiha ildiziga nisbatan faylning mahalliy yoʻli Image.asset () konstruktoriga uzatiladi:



1
2
3
4
5
6
7
8
9
10
11
12

import 'package:flutter/material.dart';
void main() {
runApp(MaterialApp(
home: Scaffold(
body: Image.asset("assets/images/forest.png"),
appBar: AppBar(
title: const Text("METANIT.COM"),
),
),
));
}

Ammo qo'shimcha ravishda, biz loyihamizda bunday tasvir resursi mavjudligini ko'rsatishimiz kerak. Buni amalga oshirish uchun pubspec.yaml faylini oching, u sukut bo'yicha quyidagicha ko'rinadi:




1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76

name: hello_app
description: A new Flutter application.
# The following line prevents the package from being accidentally published to
# pub.dev using `pub publish`. This is preferred for private packages.
publish_to: 'none' # Remove this line if you wish to publish to pub.dev
# The following defines the version and build number for your application.
# A version number is three numbers separated by dots, like 1.2.43
# followed by an optional build number separated by a +.
# Both the version and the builder number may be overridden in flutter
# build by specifying --build-name and --build-number, respectively.
# In Android, build-name is used as versionName while build-number used as versionCode.
# Read more about Android versioning at https://developer.android.com/studio/publish/versioning
# In iOS, build-name is used as CFBundleShortVersionString while build-number used as CFBundleVersion.
# Read more about iOS versioning at
# https://developer.apple.com/library/archive/documentation/General/Reference/InfoPlistKeyReference/Articles/CoreFoundationKeys.html
version: 1.0.0+1
environment:
sdk: ">=2.7.0 <3.0.0"
dependencies:
flutter:
sdk: flutter
# The following adds the Cupertino Icons font to your application.
# Use with the CupertinoIcons class for iOS style icons.
cupertino_icons: ^1.0.2
dev_dependencies:
flutter_test:
sdk: flutter
# For information on the generic Dart part of this file, see the
# following page: https://dart.dev/tools/pub/pubspec
# The following section is specific to Flutter.
flutter:
# The following line ensures that the Material Icons font is
# included with your application, so that you can use the icons in
# the material Icons class.
uses-material-design: true
# To add assets to your application, add an assets section, like this:
# assets:
# - images/a_dot_burr.jpeg
# - images/a_dot_ham.jpeg
# An image asset can refer to one or more resolution-specific "variants", see
# https://flutter.dev/assets-and-images/#resolution-aware.
# For details regarding adding assets from package dependencies, see
# https://flutter.dev/assets-and-images/#from-packages
# To add custom fonts to your application, add a fonts section here,
# in this "flutter" section. Each entry in this list should have a
# "family" key with the font family name, and a "fonts" key with a
# list giving the asset and other descriptors for the font. For
# example:
# fonts:
# - family: Schyler
# fonts:
# - asset: fonts/Schyler-Regular.ttf
# - asset: fonts/Schyler-Italic.ttf
# style: italic
# - family: Trajan Pro
# fonts:
# - asset: fonts/TrajanPro.ttf
# - asset: fonts/TrajanPro_Bold.ttf
# weight: 700
#
# For details regarding fonts from package dependencies,
# see https://flutter.dev/custom-fonts/#from-packages

Xususan, biz quyidagi bo'limni topamiz:




1
2
3
4

# To add assets to your application, add an assets section, like this:
# assets:
# - images/a_dot_burr.jpeg
# - images/a_dot_ham.jpeg

# belgisi izoh belgisini bildiradi. Keling, ushbu bo'limni quyidagicha o'zgartiramiz:




1
2
3

# To add assets to your application, add an assets section, like this:
assets:
- assets/images/forest.png

Mening holimda rasm fayli forest.png deb ataladi va aktivlar / tasvirlar pastki papkasida joylashganligi sababli, men aniqlayman - assets / images / forest.png


Shundan so'ng Flutter tasvirni olishi kerak:



Rasm o'lchamlari


Barcha Image vidjet konstruktorlarida mavjud boʻlgan qoʻshimcha kenglik va balandlik parametrlari bilan siz mos ravishda tasvirning kengligi va balandligini belgilashingiz mumkin.


1
2
3
4
5
6
7
8
9
10
11
12

import 'package:flutter/material.dart';
void main() {
runApp(MaterialApp(
home: Scaffold(
body: Image.asset("assets/images/forest.png", width: 320, height: 240),
appBar: AppBar(
title: const Text("METANIT.COM"),
),
),
));
}

BoxFit
Barcha Tasvir konstruktorlari konteyner ichidagi tasvirning o'rnini sozlash imkonini beruvchi mos parametrga ega. Qiymat sifatida BoxFit raqamlash qiymatlaridan birini oladi:

BoxFit.contain: Tasvir konteynerning minimal tomoniga (kenglik yoki balandlik) nisbatan masshtablangan. BoxFit bilan bir xil (1)

BoxFit.cover: Tasvir konteynerning maksimal tomoniga (kenglik yoki balandlik) nisbatan masshtablangan. BoxFit bilan bir xil (2)


BoxFit.fill: Tasvir konteynerning butun maydonini to'ldiradi. BoxFit bilan bir xil (0)


BoxFit.fitHeight: Tasvir balandlikda cho'zilgan. BoxFit bilan bir xil (4)


BoxFit.fitWidth: Tasvir kenglikka mos ravishda cho'zilgan. BoxFit bilan bir xil (3)

BoxFit.none: Tasvir konteynerda hizalanadi (sukut bo'yicha markazlashtirilgan), kenglik va balandlik nisbati hisobga olinmaydi. BoxFit bilan bir xil (5)

BoxFit.scaleDown: Tasvir konteynerda hizalanadi (sukut bo'yicha markazlashtirilgan) va agar kerak bo'lsa, konteyner chegarasiga sig'ishi uchun masshtablanadi. BoxFit bilan bir xil (6)


To'ldirishga misol:




1
2
3
4
5
6
7
8
9
10

import 'package:flutter/material.dart';
void main() {
runApp(Container(
color: Colors.white,
padding: EdgeInsets.only(top:25),
child: Image.asset("assets/images/forest.png", fit:BoxFit.fill),
),
);
}





Download 1.13 Mb.

Do'stlaringiz bilan baham:
1   ...   13   14   15   16   17   18   19   20   ...   27




Ma'lumotlar bazasi mualliflik huquqi bilan himoyalangan ©fayllar.org 2024
ma'muriyatiga murojaat qiling