Notice
Recent Posts
Recent Comments
Link
일 | 월 | 화 | 수 | 목 | 금 | 토 |
---|---|---|---|---|---|---|
1 | 2 | 3 | 4 | 5 | ||
6 | 7 | 8 | 9 | 10 | 11 | 12 |
13 | 14 | 15 | 16 | 17 | 18 | 19 |
20 | 21 | 22 | 23 | 24 | 25 | 26 |
27 | 28 | 29 | 30 |
Tags
- ML
- List
- Collection
- texttheme
- import
- package
- kotlin
- pushnamed
- DART
- 클래스
- textstyle
- 함수
- 웹크롤러
- Class
- set
- crawler
- Android
- 콜렉션
- text
- Flutter
- map
- 크롤러
- function
- animation
- variable
- 플러터
- python
- 코틀린
- 파이썬
- 다트
Archives
- Today
- Total
조용한 담장
Flutter : SelectableText 본문

SelectableText
flutter Text 위젯은 화면에 글자를 그리지만 사용자가 텍스트를 복사는 할 수 없다.
TextField 위젯 처럼 텍스트를 복사할 수 있는 위젯을 보자.
SelectableText
SelectableText(String text, { Key key, InputlessFocusNode focusNode, TextStyle style, TextAlign textAlign: TextAlign.start, TextDirection textDirection, Radius cursorRadius, Color cursorColor, DragStartBehavior dragStartBehavior: DragStartBehavior.down, bool enableInteractiveSelection: true, GestureTapCallback onTap })
복사할 수 있는 텍스트를 그릴 수 있는 위젯이다. Text 와 비슷하게 사용할 수 있다.
TextStyle 을 적용하거나 cursor 를 설정할 수 있다.

This file contains 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
class MySelectableText extends StatelessWidget { | |
@override | |
Widget build(BuildContext context) { | |
return Scaffold( | |
appBar: AppBar( | |
title: Text('Selectable Text'), | |
), | |
body: SingleChildScrollView( | |
child: Center( | |
child: Column( | |
children: <Widget>[ | |
// picture from https://www.pexels.com/photo/dog-with-brown-faux-fur-headband-800330/ | |
Image.asset('images/adorable-animal-canine-800330.jpg'), | |
Padding( | |
padding: EdgeInsets.only(top: 10.0), | |
child: SelectableText('Me, a dog'), | |
), | |
Padding( | |
padding: EdgeInsets.only(top: 10.0), | |
child: SelectableText( | |
'noticed that I\'m', | |
style: TextStyle( | |
color: Colors.blue, | |
backgroundColor: Colors.red[100].withOpacity(0.6), | |
fontSize: 20, | |
fontWeight: FontWeight.bold, | |
), | |
), | |
), | |
Padding( | |
padding: EdgeInsets.only(top: 10.0), | |
child: SelectableText.rich( | |
TextSpan( | |
text: 'not ' , | |
style: Theme.of(context).textTheme.display1, | |
children: <TextSpan>[ | |
TextSpan( | |
text: 'a ', | |
style: Theme.of(context).textTheme.display2, | |
), | |
TextSpan( | |
text: 'lion', | |
style: Theme.of(context).textTheme.display3, | |
), | |
], | |
), | |
showCursor: true, | |
cursorWidth: 3.0, | |
cursorColor: Colors.green, | |
), | |
), | |
Padding( | |
padding: EdgeInsets.only(top: 50.0), | |
child: Container( | |
width: 200.0, | |
height: 50.0, | |
child: TextField( | |
decoration: InputDecoration( | |
border: OutlineInputBorder(), | |
), | |
), | |
), | |
) | |
], | |
), | |
), | |
) | |
); | |
} | |
} |
Reference
'Flutter' 카테고리의 다른 글
Flutter : DataTable (3) | 2019.11.04 |
---|---|
Flutter : Draggable (0) | 2019.10.28 |
Flutter : Navigator (0) | 2019.10.17 |
Flutter : Text Widgets (0) | 2019.10.14 |
Flutter : State management (Provider) (1) | 2019.10.11 |