How do you show a random string in Flutter - flutter

I am beginner in dart with flutter and I need to display a random string on the app screen.
I know how to get a random string but I am facing problems in trying to display it on the app screen.
So how do I display this string on the user's screen? Sorry, I am only a beginner and can't find this anywhere.
Thank you.

Just create a Text widget with the string as the content.
For Example:
import 'package:flutter/material.dart';
void main() => runApp(MyApp());
class MyApp extends StatelessWidget {
#override
Widget build(BuildContext context) {
return MaterialApp(
title: 'Welcome to Flutter',
home: Scaffold(
appBar: AppBar(
title: Text('Welcome to Flutter'),
),
body: Center(
child: Text('Random String is $yourstring'), // use $ sign to use content of a variable
),
),
);
}
}

Related

The constructor being called isn't a const constructor?

I am brand new to flutter and programming in general -so please bear with me-, so I am taking a course on udemy and I stumbled with this error (The constructor being called isn't a const constructor)
This is the code :
import 'package:flutter/material.dart';
void main() {
runApp(MyApp());
}
class MyApp extends StatelessWidget {
#override
Widget build(BuildContext context) {
return MaterialApp(
home: Scaffold(
appBar:AppBar(
title: Text('My First App'),
),
body: Text('This is my default text'),
),
);
}
}
Try below code hope its help to you. remove const keyword
import 'package:flutter/material.dart';
void main() {
runApp(MyApp());
}
class MyApp extends StatelessWidget {
#override
Widget build(BuildContext context) {
return MaterialApp(
home: Scaffold(
appBar: AppBar(
title: Text('My First App'),
),
body: Text('This is my default text'),
),
);
}
}
Your result screen->

Emojis on flutter web are not displayed

I try to use emojis on flutter web, for example 😀, on a Text() widget, but the emoji does not appear and I get a cross instead.
Screenshot:
Code:
void main() {
runApp(MyApp());
}
class MyApp extends StatelessWidget {
// This widget is the root of your application.
#override
Widget build(BuildContext context) {
return MaterialApp(
title: 'Flutter Demo',
theme: ThemeData(),
home: Scaffold(body: Text('This is an emoji 😀')),
);
}
}
Do you know how to solve it on flutter web ?
can try flutter_emoji package : https://pub.dev/packages/flutter_emoji
I think this issue is already solved on Flutter 2.8 😀
I just copy pasted the emoji on the Text string as follows.
Center(
child: AppCard(
child: Text(
'Hi there 👋',
style: Theme.of(context).textTheme.bodyText1,
),
),
),

The method 'Text' isn't defined for the type '_MyHomePageState'

i am new to flutter and as i try creating a new project, here is the error i am getting:
The method 'Text' isn't defined for the type '_MyHomePageState'.
import 'package:flutter/material.dart';
void main() => runApp(MyApp());
class MyApp extends StatelessWidget {
#override
Widget build(BuildContext context) {
return MaterialApp(
title: 'Material App',
home: Scaffold(
appBar: AppBar(
title: Text('Material App Bar'),
),
body: Center(
child: Container(
child: Text('Hello World'),
),
),
),
);
}
}
Try to use hot restart, your code works fine.
The main flutter folder is distorted by some extensions installed, the solution is just to delete and download it again and still in the same previous directory, the you can install it back from the terminal

How to avoid open status bar and bottom buttons bar when app is opened?

My app is used for recognize face and it is put on public place in company, so I don't want anyone to close my app or open anything else in the android device.
Is there anyway to avoid using status bar and 3 bottom buttons in flutter when the app is opened or it only can be used when I allow it?
Thanks for advance.
SystemChrome.setSystemUIOverlayStyle(SystemUiOverlayStyle());
This line help you, and how you can use, see example explained below:
import 'package:flutter/material.dart';
void main() => runApp(MyApp());
class MyApp extends StatelessWidget {
#override
Widget build(BuildContext context) {
// Add this line
SystemChrome.setSystemUIOverlayStyle(SystemUiOverlayStyle());
return MaterialApp(
title: 'Welcome to Flutter',
home: Scaffold(
appBar: AppBar(
title: Text('Welcome to Flutter'),
),
body: Center(
child: Text('Hello World'),
),
),
);
}
}

what is the error ? and how can i solve it?

I am learning flutter. i have made one app name chat x(title). the code is below
import 'package:flutter/material.dart';
void main() => runApp(MyApp());
class MyApp extends StatelessWidget {
#override
Widget build(BuildContext context) {
return MaterialApp(
home: Scaffold(
appBar: AppBar(
title: Text('Chat X'),
),
body: Card(child: Column(children: <Widget>[
Text('hey! this one is new');
],),),
),
);
}
}
when ever i want to debug this code i get this error
Expected to find ']'.
Remove ; from Text('hey! this one is new'); or you can place a , if you want to have more widgets inside Column
class MyApp extends StatelessWidget {
#override
Widget build(BuildContext context) {
return MaterialApp(
home: Scaffold(
appBar: AppBar(
title: Text('Chat X'),
),
body: Card(child: Column(children: <Widget>[
Text('hey! this one is new'),
Text('hey! this one is second new'),
],),),
),
);
}
}
You shoud not have the ; after the Text widget. Like this:
Text('hey! this one is new')