Y
Y
Yuri Sika2020-12-04 20:34:26
Dart
Yuri Sika, 2020-12-04 20:34:26

How to display text in Flutter/Dart?

Help me please!
I want to make an application that should: reflect any text in the center of the screen, and after clicking on any place on the screen, the background color should be changed to a random one.
I have already done that after clicking, the application changes the color to a random one.
How to add some text to all this?
Here is the code:

void main() {
runApp(MaterialApp(title:'Hello world',home: MyPage()));
}

class MyPage extends StatefulWidget {
@override
_MyPageState createState() => new _MyPageState();
}

class _MyPageState extends State {
final Random _random = Random();

Color _color = Color(0xFFFFFFFF);

void changeColor() {
setState(() {
_color = Color.fromARGB(
//or with fromRGBO with fourth arg as _random.nextDouble(),
_random.nextInt(256),
_random.nextInt(256),
_random.nextInt(256),
_random.nextInt(256),
) ;
});
}

@override
Widget build(BuildContext context) {
return Scaffold(
body: InkWell(
onTap: changeColor,
child: Container(
color: _color,
),
),
);
}
}

Answer the question

In order to leave comments, you need to log in

1 answer(s)
R
Roman Alexandrovich, 2020-12-04
@YuraSika25

Container(
color: _color,
child:Expanded(child:Center(
child:Text('123')
))
),

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question