Some flag emoji seem to have extra padding. See the image below:
You can see the Danish flag is taking double width, but the British flag has the correct width.
Here is the complete project code:
import 'package:flutter/material.dart';
import 'package:flutter/rendering.dart';
void main() {
debugPaintSizeEnabled = true;
runApp(MyApp());
}
class MyApp extends StatelessWidget {
#override
Widget build(BuildContext context) {
return MaterialApp(
home: Scaffold(
appBar: AppBar(title: Text('My App')),
body: BodyWidget(),
),
);
}
}
class BodyWidget extends StatelessWidget {
#override
Widget build(BuildContext context) {
return Container(
width: 100,
margin: const EdgeInsets.all(50),
child: Column(
children: <Widget>[
Text('🇩🇰', style: TextStyle(fontSize: 30),),
Text('🇬🇧', style: TextStyle(fontSize: 30),),
],
),
);
}
}
Is this a bug or am I doing something wrong? I want all of the flags to have the same width.
It is making alignment problems for me in a bigger project.
This appear to be a bug rather than a programming problem. Make sure you have upgraded to the latest version of Flutter. As of Flutter 1.12.13+hotfix.6 • channel beta I am no longer seeing this issue.
Related GitHub issues:
https://github.com/flutter/flutter/issues/43230
https://github.com/flutter/flutter/issues/41792
Related
Is there any proper method to write responsive app without any additional package? I usually use MediaQuery but I feel it's not proper enough because it's hard to measure the size from figma since figma use number so i have to calculate it but im afraid everytime i calculate it's not precise and for the font size what is used to make it responsive?
var height = MediaQuery.of(context).size.height;
var width = MediaQuery.of(context).size.width;
By using Sizer plugin we can make flutter app responsive.
https://pub.dev/packages/sizer
See the example below:
add into pubspec.yaml
dependencies:
flutter:
sdk: flutter
sizer: ^2.0.15
add import statement to code
import 'package:sizer/sizer.dart';
Wrap MaterialApp with ResponsiveSizer widget
main.dart
import 'package:flutter/material.dart';
import 'package:mediaquerydemo/sizer_demo.dart';
import 'package:sizer/sizer.dart';
void main() {
runApp(MyApp());
}
class MyApp extends StatelessWidget {
#override
Widget build(BuildContext context) {
return Sizer(
builder: (context, orientation, deviceType) {
return MaterialApp(
title: 'Flutter Demo',
theme: ThemeData(
primarySwatch: Colors.blue,
),
home: SizerDemo(),
);
}
);
}
}
Your actual code where you can show UI
SizerDemo.dart
import 'package:flutter/material.dart';
import 'package:sizer/sizer.dart';
class SizerDemo extends StatelessWidget {
#override
Widget build(BuildContext context) {
final deviceInfo = MediaQuery.of(context);
late var h = deviceInfo.size.height;
late var w = deviceInfo.size.width;
return Scaffold(
appBar: AppBar(
title: Text("Responsive App"),
),
body: deviceInfo.orientation == Orientation.portrait
? SizedBox(
width:30.w,
height: 20.h,
child: Container(
child: Center(child: Text("HELLO", style: TextStyle(fontSize: 20.sp),)),
color: Colors.green,
),
)
: SizedBox(
width:30.w,
height: 20.h,
child: Container(
child: Center(child: Text("World!", style: TextStyle(fontSize: 20.sp),)),
color: Colors.red,
),
)
);
}
}
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.
I have faced the flutter tooltip problem
Here is my code:
import 'package:flutter/material.dart';
import 'dart:async';
void main() {
runApp(MaterialApp(
home: MyApp(),
));
}
class MyApp extends StatefulWidget {
#override
_State createState() => _State();
}
class _State extends State<MyApp> {
String _value = 'Hello again';
void _onClicked() => setState(() => _value = new DateTime.now().toString());
#override
Widget build(BuildContext context) {
return Scaffold(
// key: _scaffoldstate,
appBar: AppBar(
title: Text('Name here'),
),
body: Container(
padding: EdgeInsets.all(32.0),
child: Center(
child: Column(
children: <Widget>[
Text(_value),
IconButton(
icon: Icon(Icons.timer),
onPressed: _onClicked,
tooltip: "Hi I'm tooltip", // way one
),
Tooltip(
// way two
message: 'I am a Tooltip',
child: Text('Hover over the text to show a tooltip.'),
)
],
),
),
),
);
}
}
I have tried two way but doesn't work in any way, I don't know where is a problem.
Is it a problem with my column widget?
flutter version: 2.0.3
any suggestion, please.
ToolTips gets visible when you hover on those Widgets. In a mobile phone, it's not possible to hover on widgets without a mouse so try long pressing on those widgets to view tooltips.
ToolTips are visible when hovering on those widgets on the web. Check this DartPad
I want to display captcha image and do verify it. So Please guys suggest me any package or idea to implement text captcha in flutter. I have already search for this but i have not got proper idea and any accurate packages.
I want look like below view in flutter,
I got little similar packages,
flutter_recaptcha_v2
enter link description here
But not complete my requirement. Please help me or suggest me. Thanks.
You can copy paste run full code below
You can use package https://pub.dev/packages/hb_check_code
code snippet
Widget build(BuildContext context) {
String code = randomAlpha(5);
return Scaffold(
...
body: Column(
children: [
Row(
children: [
Container(
alignment: Alignment.center,
child: HBCheckCode(
code: code,
)),
InkWell(
onTap: () {
setState(() {});
},
child: Icon(Icons.refresh)),
],
working demo
full code
import 'package:hb_check_code/hb_check_code.dart';
import 'package:flutter/material.dart';
import 'package:random_string/random_string.dart';
void main() {
runApp(MyApp());
}
class MyApp extends StatelessWidget {
#override
Widget build(BuildContext context) {
return MaterialApp(
title: 'HBCheckCode Demo',
theme: ThemeData(
primarySwatch: Colors.blue,
),
home: CodeTestPage(),
);
}
}
class CodeTestPage extends StatefulWidget {
#override
_CodeTestPageState createState() => _CodeTestPageState();
}
class _CodeTestPageState extends State<CodeTestPage> {
#override
Widget build(BuildContext context) {
String code = randomAlpha(5);
return Scaffold(
appBar: AppBar(
title: Text("captcha"),
),
body: Column(
children: [
Row(
children: [
Container(
alignment: Alignment.center,
child: HBCheckCode(
code: code,
)),
InkWell(
onTap: () {
setState(() {});
},
child: Icon(Icons.refresh)),
],
),
],
));
}
}
I want to bring below image design in my app using flutter. I am using container and row widget to bring them inline.But didn't work. How can i bring them inline both the color filled box and the text?
You can just surround your Row and Container widgets with an additional Row. On the outer Row you then can set MainAxisAlignment to MainAxisAlignment.spaceAroundor MainAxisAlignment.spaceBetween. This creates the spacing between the different options.
Below a standalone example:
import 'package:flutter/material.dart';
void main() => runApp(MyApp());
class MyApp extends StatelessWidget {
#override
Widget build(BuildContext context) {
return MaterialApp(
home: Scaffold(
body: Center(
child: Row(
mainAxisAlignment: MainAxisAlignment.spaceAround,
children: <Widget>[
ColoredBox(color: Colors.grey, text: 'Booked'),
ColoredBox(color: Colors.green, text: 'Available'),
ColoredBox(color: Colors.red, text: 'Selected'),
],),
),
),
);
}
}
class ColoredBox extends StatelessWidget {
final String text;
final Color color;
ColoredBox({this.text, this.color});
#override
Widget build(BuildContext context) {
return Row(children: <Widget>[
Container(
width: 10.0,
height: 10.0,
color: this.color,
),
Text(this.text)
],);
}
}