Copyright 2024 - Custom text here

การใช้ Google Fonts บน Theme บน Flutter

Screen Shot 2021 12 06 at 43852 AM

ส่งแรกไปที่นี่ครับ https://pub.dev/packages/google_fonts ติดตั้ง package ก่อน

ต่อไป ก็ไปหาด font สวยๆ ที่นี่ครับ https://fonts.google.com

Screen Shot 2021 11 22 at 34409 PM

 

กำหนด การใช้งาน Google Fonts ใน fontFamily ที่ ThemeData

 

 class MyApp extends StatelessWidget {
  const MyApp({Key? key}) : super(key: key);

  @override
  Widget build(BuildContext context) {
    return MaterialApp(
      routes: map,
      initialRoute: firstState,
      theme: ThemeData(
        brightness: Brightness.light,
        primaryColor: Colors.green,
        fontFamily: GoogleFonts.mali().fontFamily,
      ),
    );
  }
}

 

Screen Shot 2021 11 22 at 34416 PM 

 

ส่วนของค่าคงที่

 

 class MyConstant {
  TextStyle h1Style() => const TextStyle(
        fontSize: 30,
        fontWeight: FontWeight.bold,
      );

  TextStyle h2Style() => const TextStyle(
        fontSize: 18,
        fontWeight: FontWeight.w700,
      );

  TextStyle h3Style() => const TextStyle(
        fontSize: 14,
        fontWeight: FontWeight.normal,
      );
}

 

Screen Shot 2021 11 22 at 34424 PM

 

ส่วนของ Windget ที่จะแสดง Text

 

 class ShowTitle extends StatelessWidget {
  final String title;
  final TextStyle? textStyle;
  const ShowTitle({Key? key, required this.title, this.textStyle})
      : super(key: key);

  @override
  Widget build(BuildContext context) {
    return Text(
      title,
      style: textStyle ?? MyConstant().h3Style() ,
    );
  }
}

 

Screen Shot 2021 11 22 at 34437 PM

 

 ตัวอย่างโค้ด

 

 Container newText() {
    return Container(
      constraints: const BoxConstraints(maxWidth: 250),
      child: StreamBuilder<String>(
          stream: streamController.stream,
          builder: (context, snapshot) {
            return ShowTitle(
              title: '$word translate ==>> ${snapshot.data}',
              textStyle: MyConstant().h2Style(),
            );
          }),
    );
  }

 

Screenshot 1637570681

 

น่าจะได้นะครับ ลองทำดูครับ ติดปํญหาอะไร ? ทักถามมาสเตอร์ ได้เลยนะครับ หรือ จะหาวันที่สะดวก มาลุยคอร์ สอน Flutter Online กันครับ

รายละเอียด คอร์ส สอน Flutter ตัวต่อตัว แบบ ออนไลด์ เลือกหัวข้อเรียนได้ กับ มาสเตอร์​ อึ่งครับ เรียนกัน 9.00-16.00 บันทึ่กวีดีโอไว้ดูภายหลังได้นะ 

ดูรายละเอียดที่

https://www.flutterthailand.com

ไม่เข้าใจ อะไร ? โพสถามมาสเตอร์ ได้ หรือ จะโทรที่ 0818595309 ได้ครับ

 

 

 

คอร์ส สอนโปรเจ็คแอนดรอยด์ ตัวต่อตัว

privateProject2019v1

คอร์ส เบสิกแอนดรอยด์ สอน ตัวต่อตัว

privateAndroid2019v1

คอร์ส iOS สอน ตัวต่อตัว

privateIos2019V1

คอร์ส Flutter สอน ตัวต่อตัว

privateFlutter2019v1

f t g