chinese_font_library 0.2.0 copy "chinese_font_library: ^0.2.0" to clipboard
chinese_font_library: ^0.2.0 copied to clipboard

Dedicated package for rendering Chinese fonts in Flutter.

example/lib/main.dart

import 'package:chinese_font_library/chinese_font_library.dart';
import 'package:flutter/material.dart';

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

class MyApp extends StatefulWidget {
  const MyApp({super.key});

  @override
  State<MyApp> createState() => _MyAppState();
}

class _MyAppState extends State<MyApp> {
  bool useCustomFont = false;

  @override
  Widget build(BuildContext context) {
    const customFontFamily = "CustomFontFromWeb";

    return MaterialApp(
      debugShowCheckedModeBanner: false,
      theme: ThemeData.dark(useMaterial3: true),
      home: Scaffold(
        appBar: AppBar(
          leading: IconButton(
            onPressed: () {
              DynamicFont.url(
                fontFamily: customFontFamily,
                url:
                    'https://raw.githubusercontent.com/LastMonopoly/chinese_font_library/master/example/assets/SmileySans-Oblique.ttf',
              ).load().then((success) {
                if (success) {
                  setState(() {
                    useCustomFont = true;
                  });
                }
              });
            },
            icon: const Icon(Icons.download),
          ),
        ),
        body: Center(
          child: FontWeightDemo(
            fontFamily: useCustomFont ? customFontFamily : null,
          ),
        ),
      ),
    );
  }
}

class FontWeightDemo extends StatelessWidget {
  final String? fontFamily;
  const FontWeightDemo({super.key, required this.fontFamily});

  @override
  Widget build(BuildContext context) {
    return ListView(
      padding: const EdgeInsets.symmetric(horizontal: 20),
      shrinkWrap: true,
      children: FontWeight.values
          .map(
            (weight) => FittedBox(
              child: Text(
                '你好世界 hello world',
                style: TextStyle(
                  fontFamily: fontFamily,
                  fontWeight: weight,
                ).useSystemChineseFont(),
              ),
            ),
          )
          .toList(),
    );
  }
}
48
likes
0
pub points
91%
popularity

Publisher

verified publisherhanshi.tech

Dedicated package for rendering Chinese fonts in Flutter.

Repository (GitHub)
View/report issues

License

unknown (license)

Dependencies

flutter, http, path_provider

More

Packages that depend on chinese_font_library