Last active
December 9, 2024 14:10
-
-
Save rizumita/f2928f6d4ec5a76530f129f255194356 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import 'package:flutter/material.dart'; | |
void main() { | |
runApp( | |
MaterialApp( | |
home: Scaffold( | |
appBar: AppBar( | |
title: Text('Text Widget サンプル'), | |
), | |
body: SingleChildScrollView( // スクロール可能にする | |
child: Center( | |
child: Padding( | |
padding: const EdgeInsets.all(20.0), | |
child: Column( | |
mainAxisAlignment: MainAxisAlignment.center, | |
children: <Widget>[ | |
Text('シンプルなテキスト'), | |
SizedBox(height: 20), | |
Text( | |
'スタイル付きテキスト', | |
style: TextStyle( | |
fontSize: 24, | |
fontWeight: FontWeight.bold, | |
color: Colors.blue, | |
fontStyle: FontStyle.italic, | |
decoration: TextDecoration.underline, | |
), | |
), | |
SizedBox(height: 20), | |
Container( | |
width: 200, | |
child: Text( | |
'左寄せテキスト', | |
textAlign: TextAlign.left, | |
), | |
), | |
SizedBox(height: 20), | |
Container( | |
width: 200, | |
child: Text( | |
'中央寄せテキスト', | |
textAlign: TextAlign.center, | |
), | |
), | |
SizedBox(height: 20), | |
Container( | |
width: 200, | |
child: Text( | |
'右寄せテキスト', | |
textAlign: TextAlign.right, | |
), | |
), | |
SizedBox(height: 20), | |
Container( | |
width: 200, | |
child: Text( | |
'これは複数行に渡って表示されるテキストです。自動的に折り返されます。', | |
softWrap: true, | |
), | |
), | |
SizedBox(height: 20), | |
Container( | |
width: 200, | |
child: Text( | |
'これは複数行に渡って表示されるテキストですが、最大3行までしか表示されません。残りは「...」で省略されます。', | |
maxLines: 3, | |
overflow: TextOverflow.ellipsis, | |
), | |
), | |
SizedBox(height: 20), | |
Text.rich( | |
TextSpan( | |
text: 'リッチ ', | |
style: TextStyle(fontSize: 20), | |
children: <TextSpan>[ | |
TextSpan( | |
text: 'テキスト', | |
style: TextStyle( | |
fontWeight: FontWeight.bold, | |
color: Colors.red, | |
decoration: TextDecoration.underline, | |
), | |
), | |
TextSpan( | |
text: ' の例', | |
), | |
], | |
), | |
), | |
], | |
), | |
), | |
), | |
), | |
), | |
), | |
); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment