Emojis on flutter web are not displayed - flutter

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,
),
),
),

Related

Dart Flutter display Icons

Im writing my first code and I want to display a Icon, and I try to use the command Icon (Icons.star, color: Colors.red, size: 100, ),. But it doesn't work. Can somebody help me. Thx
Welcome to Stackoverflow.
Try the following code. Your above code is also correct.
Try to check below line in your pubspec.yaml file
flutter:
uses-material-design: true
Refer Flutter Icons
Full Example:
import 'package:flutter/material.dart';
void main() {
runApp(
MyApp(),
);
}
class MyApp extends StatelessWidget {
#override
Widget build(BuildContext context) {
return MaterialApp(
debugShowCheckedModeBanner: false,
home: Scaffold(
body: Center(
child: MyWidget(),
),
),
);
}
}
class MyWidget extends StatelessWidget {
#override
Widget build(BuildContext context) {
return Center(
child: Icon(
Icons.star,
color: Colors.red,
size: 100,
),
);
}
}
Result screen->
You can also test the code on Dartpad.

cupertino equivalent of `Material`

I've conducted a long research on the internet about this (what I think is mischievous) use of Material widget in flutter, Any flutter developer faced the No Material widget found. exception even when using cupertino design widgets.
A simple example to produce is
import 'package:flutter/cupertino.dart';
import 'package:flutter/material.dart';
class Example extends StatelessWidget {
const Example({Key key}) : super(key: key);
#override
Widget build(BuildContext context) {
return CupertinoPageScaffold(
navigationBar: CupertinoNavigationBar(
middle: Text('Example'),
leading: IconButton(
onPressed: () {},
icon: Icon(
Icons.close,
color: Colors.black54,
),
),
),
child: Center(
child: IconButton(
onPressed: () {},
icon: Icon(
Icons.close,
color: Colors.black54,
),
),
),
);
}
}
Neither the navigationBar nor the body IconButton will work resulting in the same exception.
When facing this exception I always wrap it inside a Material to bypass it, but I think am doing it wrong.IconButton is not the only widget and I've searched a lot with no avail.
Please tell me what am I missing ? and thanks in advance.
You need to wrap your root Widget in MaterialApp() so that you can access Material components.
For example,
import 'package:flutter/material.dart';
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(
primarySwatch: Colors.blue,
),
home: MyHomePage(title: 'Flutter Demo Home Page'),
);
}
}
Not sure about the Cupertino part, but (afaik) you need to wrap your app in MaterialApp() to access Material widgets and other methods etc.
For MaterialApp you have to use IconButton, for CupertinoApp you have to use CupertinoButton but instead of icon use child

Flutter TextField doesn't respect maxLength limit even when using LengthLimitingTextInputFormatter after version 1.20.0

Testing the same code with Flutter 1.20.0 we have different behavior (the correct one). I also believe maxLength should be respected all the time.
sample code:
import 'package:flutter/material.dart';
void main() => runApp(MyApp());
class MyApp extends StatelessWidget {
#override
Widget build(BuildContext context) {
return MaterialApp(
title: 'Flutter Demo',
home: Scaffold(
body: Center(
child: TextField(
inputFormatters: [
LengthLimitingTextInputFormatter(5),
],
maxLength: 5,
),
),
),
);
}
}

How do you show a random string in 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
),
),
);
}
}

Browser top bar does not scroll with content

When displaying a flutter app from a browser (chrome in this example) on a mobile device, the browser's app bar does not scroll off screen when the content of the page is scrolled. Is there a way to achieve that scroll?
This question regards to Flutter Web only
Demo
Here is a comparison between a flutter demo app and a simple search results page on Google. You can see how the app bar doesn't move in the first example but does move on the search results page.
Code
import 'package:flutter/material.dart';
void main() {
runApp(MyApp());
}
final List<ListTile> _list = List.generate(50, (index) {
return ListTile(
title: Text('Hello World $index'),
);
});
class MyApp extends StatelessWidget {
#override
Widget build(BuildContext context) {
return MaterialApp(
title: 'Test',
theme: ThemeData(
primarySwatch: Colors.blue,
visualDensity: VisualDensity.adaptivePlatformDensity,
),
home: Material(
child: ListView(
children: _list,
),
),
);
}
}