text
stringlengths
1
372
use a TextStyle to change the appearance of text.
to use package fonts, declare which font you’d like to use and
which package the font belongs to.
<code_start>
child: text(
'using the raleway font from the awesome_package',
style: TextStyle(
fontFamily: 'raleway',
),
),
<code_end>
<topic_end>
<topic_start>
complete example
<topic_end>
<topic_start>
fonts
the raleway and RobotoMono fonts were downloaded from
google fonts.
<topic_end>
<topic_start>
pubspec.yaml
<topic_end>
<topic_start>
main.dart
<code_start>
import 'package:flutter/material.dart';
void main() => runApp(const MyApp());
class MyApp extends StatelessWidget {
const MyApp({super.key});
@override
widget build(BuildContext context) {
return const MaterialApp(
title: 'package fonts',
home: MyHomePage(),
);
}
}
class MyHomePage extends StatelessWidget {
const MyHomePage({super.key});
@override
widget build(BuildContext context) {
return scaffold(
// the AppBar uses the app-default font.
appBar: AppBar(title: const Text('Package fonts')),
body: const center(
// this text widget uses the raleway font.
child: text(
'using the raleway font from the awesome_package',
style: TextStyle(
fontFamily: 'raleway',
),
),
),
);
}
}
<code_end>
<topic_end>
<topic_start>
custom drawing and graphics
<topic_end>
<topic_start>
topics
<topic_end>
<topic_start>
writing and using fragment shaders
info note
both the skia and impeller backends support writing a
custom shader. except where noted, the same
instructions apply to both.
custom shaders can be used to provide rich graphical effects
beyond those provided by the flutter SDK.
a shader is a program authored in a small,
dart-like language, known as GLSL,
and executed on the user’s GPU.
custom shaders are added to a flutter project
by listing them in the pubspec.yaml file,
and obtained using the FragmentProgram API.
<topic_end>
<topic_start>
adding shaders to an application
shaders, in the form of GLSL files with the .frag extension,
must be declared in the shaders section of your project’s pubspec.yaml file.
the flutter command-line tool compiles the shader
to its appropriate backend format,
and generates its necessary runtime metadata.
the compiled shader is then included in the application just like an asset.
when running in debug mode,
changes to a shader program trigger recompilation
and update the shader during hot reload or hot restart.
shaders from packages are added to a project
with packages/$pkgname prefixed to the shader program’s name
(where $pkgname is the name of the package).
<topic_end>
<topic_start>
loading shaders at runtime
to load a shader into a FragmentProgram object at runtime,
use the FragmentProgram.fromAsset constructor.
the asset’s name is the same as the path to the shader