image full screen with Text (_getTellText(text) Expanded flutter - flutter

Trying to make the image full screen with
Text (_getTellText(text) end the screen, inside the screen.
the buttons start and next in Other Expanded .
Can't expand the image although I've tried several methods
The image is not sized to a full screen has a space
and i dont know how put _getTellText(text) bottom .
_getPage({Color bgColor, Image image, String text, int index, String hint}) {
return Scaffold(
body: Container(
color: bgColor,
child: Column(
children: <Widget>[
Expanded(
flex: 8,
child: image,
),
Expanded(
flex: 1,
child: Column(
mainAxisAlignment: MainAxisAlignment.spaceAround,
children: <Widget>[
Padding(
padding: EdgeInsets.all(15),
child: _getPageNav(),
),
],
),
)
],
),
),
);
}

Hopefully, this will work for you. As I didn't completely understand your question but as far as I understood, you meant, you wanted to set an Image to occupy complete screen with text on bottom, here I have used an image that was not at all portrait and have it fit the entire screen.
import 'package:flutter/material.dart';
final Color darkBlue = Color.fromARGB(255, 18, 32, 47);
void main() {
runApp(MyApp());
}
class MyApp extends StatelessWidget {
#override
Widget build(BuildContext context) {
return MaterialApp(
debugShowCheckedModeBanner: false,
home: Scaffold(
body: Center(
child: FullScreenImage('https://flutter.dev/images/flutter-logo-sharing.png','Flutter'),
),
),
);
}
}
class FullScreenImage extends StatelessWidget {
final String image;
final String text;
FullScreenImage(this.image,this.text);
#override
Widget build(BuildContext context) {
return Stack(
children: [
Container(
height: MediaQuery.of(context).size.height,
width: MediaQuery.of(context).size.width,
child:Image.network(
image,
fit: BoxFit.cover,
), ),
Positioned(
bottom:0,
child:Text(text,),),
],
);
}
}

Related

flutter code to divide the vertical space of the screen in 3 different equal parts with different colors

i want to divide my screen vertically in three equal parts with three diffrent color and i am getting only white screen in output.
import 'package:flutter/material.dart';
void main() {
runApp(const DivideVertically3EqualParts());
}
class DivideVertically3EqualParts extends StatefulWidget {
const DivideVertically3EqualParts({super.key});
#override
State<DivideVertically3EqualParts> createState() =>
_DivideVertically3EqualPartsState();
}
class _DivideVertically3EqualPartsState
extends State<DivideVertically3EqualParts> {
#override
Widget build(BuildContext context) {
return Row(
children: [
Expanded(
child: Container(
color: Colors.orange,
)),
Expanded(
child: Container(
color: Colors.white,
)),
Expanded(
child: Container(
color: Colors.green,
))
],
);
}
}
here is code , i am getting white screen it should be orange , white and green.
You are seeing white screen probably because of the following error
Horizontal RenderFlex with multiple children has a null textDirection,
so the layout order is undefined.
You can check Flutter error: RenderFlex with multiple children has a null textDirection to learn more about solutions of this error.
The easiest way to fix this is to wrap your widget with MaterialApp.
void main() async {
runApp(
MaterialApp(
home: DivideVertically3EqualParts(),
),
);
}
class DivideVertically3EqualParts extends StatefulWidget {
const DivideVertically3EqualParts({super.key});
#override
State<DivideVertically3EqualParts> createState() =>
_DivideVertically3EqualPartsState();
}
class _DivideVertically3EqualPartsState
extends State<DivideVertically3EqualParts> {
#override
Widget build(BuildContext context) {
return Row(
children: [
Expanded(
child: Container(
color: Colors.orange,
)),
Expanded(
child: Container(
color: Colors.white,
)),
Expanded(
child: Container(
color: Colors.green,
))
],
);
}
}
Your code need little bit changes.
double width = MediaQuery.of(context).size.width;
Row(
children: [
Expanded(
child: Container(
width : width : width /3
color: Colors.orange,
)),
Expanded(
child: Container(
width : width /3
color: Colors.white,
)),
Expanded(
child: Container(
width : width /3
color: Colors.green,
))
],
);
Btw your code is perfect. And it's working for me as well,

How to put logo a little bit higher and add text above it

I'm new in flutter world. I'm trying to put a little bit this logo up and add text above it.
I found that I need Stack and Positioned Widget to position my logo and sure I can position this logo with i.e: top: 20, bottom: 20 etc but then I thought, I'm positioning it versus my emulator with certain height and weidth, what about devices with other resolutions? It should be dynamic I guess?
Could you tell me how can I achieve it?
Here is how it should looks:
How it looks now (dont mind about this logo, it's just an example)
And my another question. How can I add some text above this logo?
The code I wrote:
import 'package:flutter/material.dart';
void main() {
runApp(
MaterialApp(
home: Scaffold(
backgroundColor: const Color(0xFEC2C2C2),
body: Stack(
children: <Widget>[
Positioned.fill(
child: Image(
image: AssetImage('assets/images/logo.png'),
),
),
],
),
),
),
);
}
try this code
import 'package:flutter/material.dart';
void main() {
runApp(MyApp());
}
class MyApp extends StatelessWidget {
#override
Widget build(BuildContext context) {
return MaterialApp(
home: MyHomePage(),
);
}
}
class MyHomePage extends StatelessWidget {
#override
Widget build(BuildContext context) {
return Scaffold(
body: Container(
padding: EdgeInsets.all(50.0),
width: MediaQuery.of(context).size.width,
height: MediaQuery.of(context).size.height,
child: Column(
crossAxisAlignment: CrossAxisAlignment.center,
children: [
Text('This is My Brand Name',
style: Theme.of(context).textTheme.headline5),
SizedBox(
height: 20.0,
),
FlutterLogo(
size: 150,
)
],
),
),
);
}
}
Demo: https://i.stack.imgur.com/FTPqh.jpg

How to align widgets in a GridView in Flutter?

I want to align the contents of a GridView item to the center (both vertically and horizontally) without changing the size of the widget.
This code creates a GridView with an item in it, it has a default top-center alignment and the size is a default square.
GridView.count(
crossAxisCount: 3,
children: [
Container(
// alignment: Alignment.center,
child: RaisedButton(
child: Column(
children: [
Text("Top text"),
Text("Bottom text"),
],
),
onPressed: (){}
),
),
],
);
And it looks like this:
When I uncomment the alignment, it doesn't align the items correctly and the size of the item changes, I don't want neither of them.
Note that I need multiple Widgets in that GridView item, so I can't remove the Column (but maybe I can replace it?).
I don't see any size change after adding mainAxisAlignment to the Column. Please run the code below :
import 'package:flutter/material.dart';
final Color darkBlue = Color.fromARGB(255, 18, 32, 47);
void main() {
runApp(MyApp());
}
class MyApp extends StatelessWidget {
#override
Widget build(BuildContext context) {
return MaterialApp(
theme: ThemeData.dark().copyWith(scaffoldBackgroundColor: darkBlue),
debugShowCheckedModeBanner: false,
home: Scaffold(
body: Center(
child: MyWidget(),
),
),
);
}
}
class MyWidget extends StatelessWidget {
#override
Widget build(BuildContext context) {
return GridView.count(
crossAxisCount: 3,
children: [
Container(
// alignment: Alignment.center,
child: RaisedButton(
child: Column(
mainAxisAlignment: MainAxisAlignment.center,
children: [
Text("Top text"),
Text("Bottom text"),
],
),
onPressed: () {}),
),
],
);
}
}

How to positioned widget toLeftOf or toRightOf in Flutter

I first want to center one widget and then add another widget to the right of the center widget.
Currently, flutter APIs are not feasible for this. In android, it can be easily done in relative layout or constraint layout.
I tried with some hack with MediaQuery,
Stack(
children: [
Center(child: Text(17)),
Positioned(
bottom: 0,
left: (screenWidth / 2) + (screenWidth / 3),
child: Column(
children: []
)
)
How to try this in an easy way or a proper way.
You can use the Align widget for this.
Code Example
import 'package:flutter/material.dart';
class SandBox extends StatelessWidget {
#override
Widget build(BuildContext context) {
return Scaffold(
body: Center(
child: Container(
width: 300,
height: 300,
color: Colors.blue,
child: Align(
alignment: Alignment.centerRight, //aligns the child widget to the right center
child: Text('17'),
),
),
),
);
}
}
Maybe, it can help you to achieve what you want:
import 'package:flutter/material.dart';
final Color darkBlue = Color.fromARGB(255, 18, 32, 47);
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 Container(
height: 30,
child: Row(
mainAxisAlignment: MainAxisAlignment.center,
children: [
Center(
child: Text('17'),
),
Align(
alignment: Alignment.bottomRight,
child: Container(
width: 10,
height: 10,
decoration: BoxDecoration(
color: Colors.black,
shape: BoxShape.circle,
),
),
),
],
),
);
}
}
Or you can adjust it using some calculations using MediaQuery and Stack.
You can use badges package to achieve this goal.
Finally, I found used https://pub.dev/packages/align_positioned
AlignPositioned.relative(
Text(day.englishDate.toString(),
textScaleFactor: 3, style: dayTextStyle),
Column(
crossAxisAlignment: CrossAxisAlignment.start,
children: [
....
],
),
moveByChildWidth: 1.1,
minChildWidthRatio: 1,
moveByChildHeight: 0.3)
Please use Align along with Row.
here is simple code to achieve this.
import 'package:flutter/material.dart';
final Color darkBlue = Color.fromARGB(255, 18, 32, 47);
void main() {
runApp(MyApp());
}
class MyApp extends StatelessWidget {
#override
Widget build(BuildContext context) {
return MaterialApp(
theme: ThemeData.dark().copyWith(scaffoldBackgroundColor: darkBlue),
debugShowCheckedModeBanner: false,
home: Scaffold(
body: Stack(
children:[
Align(
child : Row(
mainAxisAlignment: MainAxisAlignment.center,
children:[
Padding(child: Text('Left'),padding: EdgeInsets.all(5)),
Text('Center widget'),
Padding(child: Text('Right'),padding: EdgeInsets.all(5))
]) ,
alignment: Alignment.center),
]
),
),
);
}
}
Here is the output:

Image not covering full device dimensions in flutter

I am trying to add an image covering the device width and height, also this image needs have text over it. At first when adding the image I used fit: BoxFit.fill on the Image.dart file so that the image covers the whole screen and it worked. Then for having the text over the image I added Stack widget wrapping the image and the text, as soon as I did this, the the text was over the image but now the image was not covering the full screen height. Why is this problem happening?
// main.dart
void main() {
runApp(MaterialApp(home: MyApp()));
}
class MyApp extends StatelessWidget {
Widget build(BuildContext context) {
return Scaffold(
backgroundColor: Colors.white,
body: ImageContainer(),
);
}
}
// ImageContainer.dart
class ImageContainer extends StatelessWidget {
Widget build(BuildContext context) {
return Container(
child: Column(
mainAxisAlignment: MainAxisAlignment.center,
children: [
Stack(
children: [
MainImage("assets/images/startwars.jpg"),
Positioned(
bottom: 0,
left: 0,
child: Container(
child: Text(
"someText",
style: TextStyle(fontSize: 18, fontWeight: FontWeight.bold, color: Colors.white),
)
),
)
],
)
],
),
);
}
}
// Image.dart
class MainImage extends StatelessWidget {
final String _assetPath;
MainImage(this._assetPath);
#override
Widget build(BuildContext context) {
return Container(
decoration: BoxDecoration(color: Colors.red,),
child: Expanded(
child: Image.asset(
_assetPath,
fit: BoxFit.fill,
),
),
);
}
}
If you have any questions please let me know in the comments;)
Set your Stack fit to expand:
Stack(
fit: StackFit.expand,
children: [],
);
I fixed this problem by adding constraints to the container in the Image.dart file, all I did was adding this line. After lots and lots of investigation I realized that adding MediaQuery to the height tells the app to cover the screen's height, this can be also done with width.
Widget build(BuildContext context) {
return Container(
decoration: BoxDecoration(color: Colors.red,),
constraints: BoxConstraints.expand(height: MediaQuery.of(context).size.height), // add this line
child: Expanded(
child: Image.asset(
_assetPath,
fit: BoxFit.fill,
),
),
);
}
You can set Stack fit ..
Stack(
fit: StackFit.expand, ... )
An also you can add Container ( child:Image( ... ), width: double.infinity, heigh:...)