av激情亚洲男人的天堂国语,日韩欧美精品一中文字幕,无码av一区二区三区无码,国产又色又爽又刺激的a片,国产又色又爽又刺激的a片

創(chuàng)新互聯(lián)Flutter教程:Flutter 自定義字體

介紹

你可以在你的Flutter應(yīng)用程序中使用不同的字體。例如,您可能會使用您的設(shè)計人員創(chuàng)建的自定義字體,或者您可能會使用Google Fonts(需翻墻))中的字體。

10余年的延津網(wǎng)站建設(shè)經(jīng)驗(yàn),針對設(shè)計、前端、開發(fā)、售后、文案、推廣等六對一服務(wù),響應(yīng)快,48小時及時工作處理。營銷型網(wǎng)站建設(shè)的優(yōu)勢是能夠根據(jù)用戶設(shè)備顯示端的尺寸不同,自動調(diào)整延津建站的顯示方式,使網(wǎng)站能夠適用不同顯示終端,在瀏覽器中調(diào)整網(wǎng)站的寬度,無論在任何一種瀏覽器上瀏覽網(wǎng)站,都能展現(xiàn)優(yōu)雅布局與設(shè)計,從而大程度地提升瀏覽體驗(yàn)。成都創(chuàng)新互聯(lián)從事“延津網(wǎng)站設(shè)計”,“延津網(wǎng)站推廣”以來,每個客戶項目都認(rèn)真落實(shí)執(zhí)行。

本頁介紹如何為Flutter應(yīng)用配置字體,并在渲染文本時使用它們。

使用字體

在Flutter應(yīng)用程序中使用字體分兩步完成。首先在pubspec.yaml中聲明它們,以確保它們包含在應(yīng)用程序中。然后通過TextStyle屬性使用字體。

在asset中聲明

要在應(yīng)用中包含字體,請先在pubspec.yaml中聲明它。然后將字體文件復(fù)制到您在pubspec.yaml中指定的位置。

flutter:
  fonts:
    - family: Raleway
      fonts:
        - asset: assets/fonts/Raleway-Regular.ttf
        - asset: assets/fonts/Raleway-Medium.ttf
          weight: 500
        - asset: assets/fonts/Raleway-SemiBold.ttf
          weight: 600
    - family: AbrilFatface
      fonts:
        - asset: assets/fonts/abrilfatface/AbrilFatface-Regular.ttf

使用字體

// declare the text style
const textStyle = const TextStyle(
  fontFamily: 'Raleway',
);

// use the text style
var buttonText = const Text(
  "Use the font for this text",
  style: textStyle,
);

依賴包中的字體{#from-packages}

要使用依賴包中定義的字體,必須提供package參數(shù)。例如,假設(shè)上面的字體聲明位于pubspec.yaml中聲明的my_package包中。然后創(chuàng)建TextStyle的過程如下:

const textStyle = const TextStyle(
  fontFamily: 'Raleway',
  package: 'my_package',
);

如果包內(nèi)部使用它定義的字體,則也應(yīng)該在創(chuàng)建文本樣式時指定package參數(shù),如上例所示。

一個包也可以提供字體文件而不需要在pubspec.yaml中聲明。 這些文件應(yīng)該包的lib/文件夾中。字體文件不會自動綁定到應(yīng)用程序中,應(yīng)用程序可以在聲明字體時有選擇地使用這些字體。假設(shè)一個名為my_package的包中有一個:

lib/fonts/Raleway-Medium.ttf

然后,應(yīng)用程序可以聲明一個字體,如下面的示例所示:

 flutter:
   fonts:
     - family: Raleway
       fonts:
         - asset: assets/fonts/Raleway-Regular.ttf
         - asset: packages/my_package/fonts/Raleway-Medium.ttf
           weight: 500

這lib/是隱含的,所以它不應(yīng)該包含在asset路徑中。

在這種情況下,由于應(yīng)用程序本地定義了字體,所以創(chuàng)建的TextStyle沒有package參數(shù):

const textStyle = const TextStyle(
  fontFamily: 'Raleway',
);

使用Material Design字體圖標(biāo)

如果要使用Material Design字體圖標(biāo),可以通過向pubspec.yaml文件添加屬性uses-material-design: true來簡單包含它。

flutter:
  # The following line ensures that the Material Icons font is
  # included with your application, so that you can use the icons in
  # the Icons class.
  uses-material-design: true

pubspec.yaml 選項定義

family 是字體的名稱, 你可以在TextStyle的 fontFamily 屬性中使用.

asset 是相對于 pubspec.yaml 文件的路徑.這些文件包含字體中字形的輪廓。在構(gòu)建應(yīng)用程序時,這些文件會包含在應(yīng)用程序的asset包中。

可以給字體設(shè)置粗細(xì)、傾斜等樣式

  • weight屬性指定字體的粗細(xì),取值范圍是100到900之間的整百數(shù)(100的倍數(shù)). 這些值對應(yīng) FontWeight, 可以用于 TextStyle的fontWeight屬性
  • style 指定字體是傾斜還是正常,對應(yīng)的值為italic和 normal. 這些值對應(yīng) FontStyle 可以用于TextStyle的 fontStyle TextStyle 屬性

TextStyle

如果一個 TextStyle 對象指定了一個沒有確切字體文件的weight或style,那么引擎會為該字體使用一個通用的文件,并嘗試為指定的weight和style推斷一個輪廓。

例子

以下是在應(yīng)用程序中聲明和使用字體的示例。

iOSAndroid

在pubsec.yaml中聲明字體。

name: my_application
description: A new Flutter project.

dependencies:
  flutter:
    sdk: flutter
    
flutter:
  # Include the Material Design fonts.
  uses-material-design: true

  fonts:
    - family: Rock Salt
      fonts:
        # https://fonts.google.com/specimen/Rock+Salt
        - asset: fonts/RockSalt-Regular.ttf
    - family: VT323
      fonts:
        # https://fonts.google.com/specimen/VT323
        - asset: fonts/VT323-Regular.ttf
    - family: Ewert
      fonts:
        # https://fonts.google.com/specimen/Ewert
        - asset: fonts/Ewert-Regular.ttf

源碼是:

import 'package:flutter/material.dart';

const String words1 = "Almost before we knew it, we had left the ground.";
const String words2 = "A shining crescent far beneath the flying vessel.";
const String words3 = "A red flair silhouetted the jagged edge of a wing.";
const String words4 = "Mist enveloped the ship three hours out from port.";

void main() {
  runApp(new MyApp());
}

class MyApp extends StatelessWidget {
  @override
  Widget build(BuildContext context) {
    return new MaterialApp(
      title: 'Flutter Fonts',
      theme: new ThemeData(
        primarySwatch: Colors.blue,
      ),
      home: new FontsPage(),
    );
  }
}

class FontsPage extends StatefulWidget {
  @override
  _FontsPageState createState() => new _FontsPageState();
}

class _FontsPageState extends State {
  @override
  Widget build(BuildContext context) {
    // Rock Salt - https://fonts.google.com/specimen/Rock+Salt
    var rockSaltContainer = new Container(
      child: new Column(
        children: [
          new Text(
            "Rock Salt",
          ),
          new Text(
            words2,
            textAlign: TextAlign.center,
            style: new TextStyle(
              fontFamily: "Rock Salt",
              fontSize: 17.0,
            ),
          ),
        ],
      ),
      margin: const EdgeInsets.all(10.0),
      padding: const EdgeInsets.all(10.0),
      decoration: new BoxDecoration(
        color: Colors.grey.shade200,
        borderRadius: new BorderRadius.all(new Radius.circular(5.0)),
      ),
    );

    // VT323 - https://fonts.google.com/specimen/VT323
    var v2t323Container = new Container(
      child: new Column(
        children: [
          new Text(
            "VT323",
          ),
          new Text(
            words3,
            textAlign: TextAlign.center,
            style: new TextStyle(
              fontFamily: "VT323",
              fontSize: 25.0,
            ),
          ),
        ],
      ),
      margin: const EdgeInsets.all(10.0),
      padding: const EdgeInsets.all(10.0),
      decoration: new BoxDecoration(
        color: Colors.grey.shade200,
        borderRadius: new BorderRadius.all(new Radius.circular(5.0)),
      ),
    );

    // https://fonts.google.com/specimen/Ewert
    var ewertContainer = new Container(
      child: new Column(
        children: [
          new Text(
            "Ewert",
          ),
          new Text(
            words4,
            textAlign: TextAlign.center,
            style: new TextStyle(
              fontFamily: "Ewert",
              fontSize: 25.0,
            ),
          ),
        ],
      ),
      margin: const EdgeInsets.all(10.0),
      padding: const EdgeInsets.all(10.0),
      decoration: new BoxDecoration(
        color: Colors.grey.shade200,
        borderRadius: new BorderRadius.all(new Radius.circular(5.0)),
      ),
    );

    // Material Icons font - included with Material Design
    String icons = "";

    // https://material.io/icons/#ic_accessible
    // accessible:  or 0xE914 or E914
    icons += "\u{E914}";

    // https://material.io/icons/#ic_error
    // error:  or 0xE000 or E000
    icons += "\u{E000}";

    // https://material.io/icons/#ic_fingerprint
    // fingerprint:  or 0xE90D or E90D
    icons += "\u{E90D}";

    // https://material.io/icons/#ic_camera
    // camera:  or 0xE3AF or E3AF
    icons += "\u{E3AF}";

    // https://material.io/icons/#ic_palette
    // palette:  or 0xE40A or E40A
    icons += "\u{E40A}";

    // https://material.io/icons/#ic_tag_faces
    // tag faces:  or 0xE420 or E420
    icons += "\u{E420}";

    // https://material.io/icons/#ic_directions_bike
    // directions bike:  or 0xE52F or E52F
    icons += "\u{E52F}";

    // https://material.io/icons/#ic_airline_seat_recline_extra
    // airline seat recline extra:  or 0xE636 or E636
    icons += "\u{E636}";

    // https://material.io/icons/#ic_beach_access
    // beach access:  or 0xEB3E or EB3E
    icons += "\u{EB3E}";

    // https://material.io/icons/#ic_public
    // public:  or 0xE80B or E80B
    icons += "\u{E80B}";

    // https://material.io/icons/#ic_star
    // star:  or 0xE838 or E838
    icons += "\u{E838}";

    var materialIconsContainer = new Container(
      child: new Column(
        children: [
          new Text(
            "Material Icons",
          ),
          new Text(
            icons,
            textAlign: TextAlign.center,
            style: new TextStyle(
              inherit: false,
              fontFamily: "MaterialIcons",
              color: Colors.black,
              fontStyle: FontStyle.normal,
              fontSize: 25.0,
            ),
          ),
        ],
      ),
      margin: const EdgeInsets.all(10.0),
      padding: const EdgeInsets.all(10.0),
      decoration: new BoxDecoration(
        color: Colors.grey.shade200,
        borderRadius: new BorderRadius.all(new Radius.circular(5.0)),
      ),
    );

    return new Scaffold(
      appBar: new AppBar(
        title: new Text("Fonts"),
      ),
      body: new ListView(
        children: [
          rockSaltContainer,
          v2t323Container,
          ewertContainer,
          materialIconsContainer,
        ],
      ),
    );
  }
}

網(wǎng)頁名稱:創(chuàng)新互聯(lián)Flutter教程:Flutter 自定義字體
文章鏈接:http://uogjgqi.cn/article/cdjdsds.html
掃二維碼與項目經(jīng)理溝通

我們在微信上24小時期待你的聲音

解答本文疑問/技術(shù)咨詢/運(yùn)營咨詢/技術(shù)建議/互聯(lián)網(wǎng)交流