text stringlengths 1 372 |
|---|
child: text( |
'this is a custom font text', |
style: TextStyle(fontFamily: 'mycustomfont'), |
), |
), |
); |
} |
<code_end> |
<topic_end> |
<topic_start> |
how do i style my text widgets? |
along with fonts, you can customize other styling elements on a text widget. |
the style parameter of a text widget takes a TextStyle object, |
where you can customize many parameters, such as: |
<topic_end> |
<topic_start> |
form input |
<topic_end> |
<topic_start> |
how do i retrieve user input? |
Xamarin.Forms elements allow you to directly query the element |
to determine the state of its properties, |
or whether it’s bound to a property in a ViewModel. |
retrieving information in flutter is handled by specialized widgets |
and is different from how you are used to. |
if you have a TextFieldor a TextFormField, |
you can supply a TextEditingController |
to retrieve user input: |
<code_start> |
import 'package:flutter/material.dart'; |
class MyForm extends StatefulWidget { |
const MyForm({super.key}); |
@override |
State<MyForm> createState() => _MyFormState(); |
} |
class _MyFormState extends State<MyForm> { |
/// create a text controller and use it to retrieve the current value |
/// of the TextField. |
final TextEditingController myController = TextEditingController(); |
@override |
void dispose() { |
// clean up the controller when disposing of the widget. |
myController.dispose(); |
super.dispose(); |
} |
@override |
widget build(BuildContext context) { |
return scaffold( |
appBar: AppBar(title: const Text('Retrieve text input')), |
body: padding( |
padding: const EdgeInsets.all(16), |
child: TextField(controller: myController), |
), |
floatingActionButton: FloatingActionButton( |
// when the user presses the button, show an alert dialog with the |
// text that the user has typed into our text field. |
onPressed: () { |
showDialog( |
context: context, |
builder: (context) { |
return AlertDialog( |
// retrieve the text that the user has entered using the |
// TextEditingController. |
content: Text(myController.text), |
); |
}, |
); |
}, |
tooltip: 'show me the value!', |
child: const Icon(Icons.text_fields), |
), |
); |
} |
} |
<code_end> |
you can find more information and the full code listing in |
retrieve the value of a text field, |
from the flutter cookbook. |
<topic_end> |
<topic_start> |
what is the equivalent of a placeholder on an entry? |
in Xamarin.Forms, some elements support a placeholder property |
that you can assign a value to. for example: |
in flutter, you can easily show a “hint” or a placeholder text |
for your input by adding an InputDecoration object |
to the decoration constructor parameter for the text widget. |
<code_start> |
TextField( |
decoration: InputDecoration(hintText: 'this is a hint'), |
), |
<code_end> |
<topic_end> |
<topic_start> |
how do i show validation errors? |
with Xamarin.Forms, if you wished to provide a visual hint of a |
validation error, you would need to create new properties and |
VisualElements surrounding the elements that had validation errors. |
in flutter, you pass through an InputDecoration object to the |
decoration constructor for the text widget. |
however, you don’t want to start off by showing an error. |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.