Show Two Languages at once - flutter

Fisrt of all i am following this guide for localization which is the official guideline of flutter but at
AppLocalizations.of(context)!.helloWorld
It gives error as null
I think this is maybe because I recently updated flutter to 2.10 please confirm if that is the case
I want to achieve this kind of results like English on right and Urdu Language of Left which i don't know how to do that because in samples and guides they just show how to change overall app language not just for some strings
Also for time being, I have used easy_localization: 3.0.0 but still the problem is how i support multiple language at once with this package

Don't use localization for this part - drawer widget - text items
wrap drawer widget with Directionality widget to prevent it from mirroring and make text in the same place.
pop the drawer after using switch widget.
Example:
import 'package:flutter/material.dart' as ltr;
drawer: Directionality(
textDirection: ltr.TextDirection.ltr,
child: Container(
color: Colors.lightGreen,
child: Column(
children: [
Row(
mainAxisAlignment: MainAxisAlignment.spaceBetween,
children: [
Text('English'),
Text('عربي'),
],
),
Row(
mainAxisAlignment: MainAxisAlignment.spaceBetween,
children: [
Text('English'),
Text('عربي'),
],
),
],
),
),
),

Related

How to change color of Flutter ButtonBar in a Scaffold?

How can I change the color of a ButtonBar in Flutter? There isn't a color in ButtonBarTheme as far as I can tell. I am trying to do something like this:
return Scaffold(
backgroundColor: Colors.red,
body: Center(child: Text('foo')),
// Somehow get the color of these buttons different to backgroundColor
persistentFooterButtons: _buildTextButtons(),
);
The best I can think of at the moment is to somehow reimplement the persistent footer buttons myself, but that is ugly. The problem seems to be that the Scaffold backgroundColor property is used in multiple places, yet is defined in a single widget. This means I can't wrap it in a Theme and override it piecemeal either, as far as I can tell.
Oh, I might have found an answer. I had been using both the bottomNavigationBar and the persistentFooterButtons. persistentFooterButtons are wrapped in a ButtonBar, which appears to limit your styling options.
bottomNavigationBar is a single widget, though, so you can fiddle with it. I switched to just build my own persistentFooterButtons after all.
(I had to edit this from my app, so it might not be copy/paste ready.)
Widget _buildNavigationBar(BuildContext ctx, Color barColor) {
List<Widget> actions = [
// We need the first element to be big, to push everything to the right.
Expanded(
child: Container(),
),
];
actions.addAll(_buildTextButtons(ctx));
Widget actionContainer = ColoredBox(
color: barColor,
child: Padding(
padding: const EdgeInsets.all(8.0),
child: Row(
mainAxisSize: MainAxisSize.min,
mainAxisAlignment: MainAxisAlignment.end,
children: actions,
),
),
);
return Column(
mainAxisSize: MainAxisSize.min,
children: [
actionContainer,
// I use this to make space for ads.
Container(
color: barColor,
height: 50,
),
],
);
}
return Scaffold(
backgroundColor: Colors.red,
body: Center(child: Text('foo')),
// removed this persistentFooterButtons: _buildTextButtons(),
// and replaced with this:
bottomNavigationBar: _buildNavigationBar(ctx),
);
you can also wrap that ButtonBar into Container and After that, you can make any type of changes to that ButtonBar, like coloring etc

Flutter Row not taking full Scaffold height

I am working on the skeleton of a tablet app with flutter and I am facing, probably a very simple issue, but it is getting tricky for me to figure out what is going on here.
Basically the skeleton of the app should look something like this:
For that, I have written a simple Stateless class like this:
class BaseDetailsRoute extends StatelessWidget {
#override
Widget build(BuildContext context) {
return Scaffold(
backgroundColor: Colors.grey,
body: Row(
mainAxisAlignment: MainAxisAlignment.center,
children: <Widget>[
Flexible(flex: 1, child: _selectionColumn()),
Flexible(flex: 7, child: _contentArea())
],
),
);
}
Widget _contentArea() => Container(color: Colors.orange,);
Column _selectionColumn() => Column(
children: <Widget>[
Expanded(child: Container(color: Colors.blue,))
],
);
}
Which is giving me ALMOST the expected result:
The little issue here is on the bottom of the screen, as you can see, in the Scaffold, I have put backgroundColor: Colors.grey, and, after rendering the Row in the screen, it seems like for some reason I cannot make it take the whole available height, and I still see a bit of the grey background color of the Scaffold on the bottom.
I have tried wrapping the whole Scaffold inside a SafeArea widget, but it did not work.
How can I fix this in an easy way, meaning not having to add a bunch of other widgets?
It's kind of weird but your code is working as intended on my side (For both Portrait and Landscape). What emulator are you using?
See Picture: Pixel 2 API 29 Emulator Portrait
Pixel 2 API 29 Emulator Lanscape
could you Please try
child: Column(
mainAxisSize: MainAxisSize.max,
children: <Widget>[
and let me know is it working

How to display text on top of containers?

I'm creating a card game and my UI has a Column() with various combinations of children widgets. One child is a Row
Row(
mainAxisAlignment: MainAxisAlignment.center,
children: <Widget>[
Container(),
Container(),
],
),
The Container() widgets each display what looks like playing cards. They have BoxDecorationsto provide a border + a child that's a Row(). The Row's children display a number (text) and a suit (image).
I would like to flash text over the two playing cards, something that's visible for just a couple seconds, e.g., "Well done." Although I'm always open to help, I assume this will amount to (Rich)Text() widgets and some sort of timer or Duration object, and that I can figure it out.
What I'm struggling with is figuring out how to create a text overlay that is both on top of and spans the two images. Do I have to do something like wrap the higher level Row() object in a Stack()? I hate all that nesting, plus I don't know how to have the text always be on top of everything else.
I think you are looking for Overlay widget:
Scaffold(
body: Container(child: Overlay(initialEntries: [
OverlayEntry(builder: (_) => Image.network("https://source.unsplash.com/random", fit: BoxFit.cover,)),
OverlayEntry(builder: (_) => Center(child: Text("Overlay", style: TextStyle(color: Colors.yellow),))),
])),
),
For now I am going with (pseudocode):
Stack(
children: <Widget>[
Row(
mainAxisAlignment: MainAxisAlignment.center,
children: <Widget>[
Container(),
Container(),
],
),
Center(
child: Text(),
),
],
),
With the Row() centered and the child:Text() centered, everything lines up and looks good. I do, however, think I need to spend time and learn about Positioned() widgets. I think that will ultimately be a better solution.

Flutter layout with circular image icons

I am a web dev in MS stack trying flutter for a personal project of mine. I want to create a layout like in the below URL in the meeve app with circular images with text below the image button/icon.
https://www.thedroidsonroids.com/blog/apps-made-with-flutter#meeve
I tried the layout given in the example on flutter docs below but it is not what I am looking for and I am not able to re purpose this for my case. https://flutter.dev/docs/cookbook/lists/grid-lists
Any leads in this respect is appreciated.
You can use CircleAvatar in a Column.
#override
Widget build(BuildContext context) {
return Scaffold(
body: Center(
child: Column(
mainAxisAlignment: MainAxisAlignment.center,
children: <Widget>[
CircleAvatar(backgroundImage: AssetImage("assets/images/chocolate_pic.png"), radius: 40),
SizedBox(height: 12),
Text("Chocolate"),
],
),
),
);
}

Flutter equivalent of layout_gravity="bottom"

I am trying to render a dribbble sample.
In normal android using XML, I can make any part stick to any side of another view. If I were using ConstraintLayout, I could make the bottom part stick to the bottom of the parent and let the top part expand to available height.
The design on both emulators is Flutter code.
On larger screens, there is some empty space on the bottom. How do I remove that?
Currently, I am using Flexible with flex values but it doesn't look right. How to make this reactive?. Is the use of Flexible correct?
The code can found here on pastebin
There is nothing like android:layout_gravity in Flutter, however you can pretty much achieve anything in Flutter. So, here you can use use Spacer(). Like:
return Column(
children: <Widget>[
Spacer(),
Align(alignment: Alignment.centerRight, child: Text("123")),
YourButtonsWidget(),
],
);
try to change CalculatorPrototype's build function like this
#override
Widget build(BuildContext context) {
return Scaffold(
body: Column(
mainAxisSize: MainAxisSize.min, // actually this line and the next one doesn't needed
mainAxisAlignment: MainAxisAlignment.spaceEvenly,
children: <Widget>[
Expanded(
child: display,
),
Container(
child: keypad,
),
],
),
);
}