How to write OR in between line in flutter - flutter

Hi everyone I am new to flutter and trying to write OR in a horizontal line like shown in figure but I do not know how to do that, I have tried to google it but that did not helped me
example demonstration
Note: OR is in center

Try below Code hope its help to you. You must use this(-- OR -- ) type of design Expanded or Flexible Widget
Go here For Expanded Widget and here for Flexible Widget
Padding(
padding: EdgeInsets.all(8.0),
child: Row(
children: [
Expanded(
child: Divider(
color: Colors.black,
thickness: 1,
),
),
Padding(
padding: const EdgeInsets.all(8.0),
child: Text('OR'),
),
Expanded(
child: Divider(
color: Colors.black,
thickness: 1,
),
),
],
),
),
Your result Screen like ->

Below is the solution using a row widget
Row(children: const [
Expanded(child: Divider(thickness: 1.5)),
Text("OR",
style: TextStyle(fontSize: 20, color: Colors.grey)),
Expanded(child: Divider(thickness: 1.5)),
]),
This is it when i tried to create Instagram login screen

Related

How to align widget in center and end in row without use of stack

How to do like this
image
code
Row(
children: [
SizedBox(width: 33.w),
Text(
StringRes.getStart,
style: TextStyle(
fontWeight: FontWeight.w500,
color: AppColors.backgroundColor,
fontSize: 13.sp,
),
),
Spacer(),
Icon(
Icons.arrow_forward,
color: AppColors.backgroundColor,
),
SizedBox(
width: 3.w,
),
],
),
i get diffrent diffrent spacing in diffrent device
like this image 2
image 3
I assume what you are looking for is something like this:
Padding(
padding: const EdgeInsets.all(8.0),
child: Row(
mainAxisAlignment: MainAxisAlignment.spaceBetween,
children: const [
SizedBox(width: 20),
Text('Get started'),
SizedBox(
width: 20,
child: Icon(Icons.arrow_forward),
),
],
),
),
In this example, the Text widget is centered by having equally large SizedBox widgets on both sides of it and by telling the Row widget to use MainAxisAlignment.spaceBetween. The padding around the Row contents is achieved with the Padding widget, so that it does not interfere with the content alignment.
I hope this helps you.

How to align an asset image responsive at bottom center in flutter

here is the UI that I'm trying to build
but this is the output
I tried alignment also , but that also didn't working
but when setting a fixed height this is working fine
but I can't fill this using the fit parameter,
here is the code
Scaffold(
backgroundColor: kDarkTheme,
body: SafeArea(
child: Column(
children: [
const SizedBox(height: 10),
Row(
//code for top button
),
const SizedBox(height: 150),
Stack(
children: [
Center(
child: CircleAvatar(
radius: radiusSize + 5,
backgroundColor: kDarkCounterColor,
child: CircleAvatar(
backgroundColor: kDarkTheme,
radius: radiusSize,
),
),
),
Center(
child: Padding(
padding: const EdgeInsets.only(top: 35),
child: Text(
'39',
style: GoogleFonts.italiana(
fontSize: 120, color: kDarkCounterColor),
),
),
),
],
),
const SizedBox(height: 15),
const Text(
'Tap To Count',
style: TextStyle(
fontFamily: 'Helvatica',
color: Color(0xff656158),
),
),
Expanded(
child: Align(
alignment: Alignment.bottomRight,
child: SvgPicture.asset(
kDarkThemeImage,
)),
)
],
),
))
this is the code
then the first error appears again. how could I fix this?
You are using the Expanded widget on a column that doesn't have a set size. Try adding MainAxisSize attribute to your column, like this:
Column(
mainAxisSize: MainAxisSize.max, // Add this like
children: [
...
This will make your column fit the whole available size on the previous widget (a scaffold for the whole screen). Then the expanded widget will fill the remaining space not used by the other widgets inside the column.

Flutter: flutter_signin_button overflow issue

I am using flutter_signin_button package to create Facebook and Apple Sign In buttons for login. However, I am facing overflow issue. Following is my code:
Container(
width: double.infinity,
child: SignInButton(
Buttons.FacebookNew,
onPressed: () => authBloc.loginFacebook(),
),
),
Container(
child: SignInButton(
Buttons.AppleDark,
onPressed: () {},
text: "Apple",
),
),
Padding(
padding: EdgeInsets.only(top: 10),
child: Text("OR",
style: TextStyle(
color: Colors.black,
fontSize: SizeConfig.textMultiplier * 2.2,
fontWeight: FontWeight.w800)),
),
Padding(
padding: EdgeInsets.only(bottom: 10),
),
Container(
width: 205,
child: ElevatedButton(
style: ElevatedButton.styleFrom(
primary: Color(0xFF1fd281),
),
onPressed: () => authBloc.loginAnonymous(),
child: Container(
width: 190,
child: Text(
"Play As Guest",
style: TextStyle(color: Colors.black),
textAlign: TextAlign.center,
),
),
),
),
The output is in the image below:
I even tried the make the container full width in an attempt to remove this overflow, but still doesn't work. Facing this issue on iPhone 7 Plus only. Not facing this issue on iOS simulator.
As per suggestion by #Sachin Liyanage, I added Expanded and the output is as follows:
Solution 1: Use Expanded or Flexible as a parent of your Container
Expanded(
child:Container(
width: double.infinity,
child: SignInButton(
Buttons.FacebookNew,
onPressed: () => authBloc.loginFacebook(),
),
),
),
Solution 2: Use Card like this, Change the following code according to your need.
Card(
child: Padding(
padding: EdgeInsets.all(16),
child: Row(
crossAxisAlignment: CrossAxisAlignment.start,
children: [
Image.asset('assets/fc-logo.png', width: 56, height: 56),
Padding(
padding: EdgeInsets.symmetric(horizontal: 16),
child: Column(
crossAxisAlignment: CrossAxisAlignment.start,
children: [
Text("Flutter Clutter", style: TextStyle(fontSize: 18)),
Text("Internationalization (i18n) in Flutter: an easy and quick approach")
]
),
),
Spacer(),
Text("03.03.2020"),
]
)
)
);
For more ways refer to this - https://www.flutterclutter.dev/flutter/troubleshooting/widget-overflowed-by-pixels/2020/461/
Solution 3: Use AutoSizeText widget for facebook text
Refer to this - https://pub.dev/packages/auto_size_text
no no Use a slivers with custom scrollview and set width via padding like
customScrollview(
slivers:[
SliverAppBar("yourAppBar"),
SliverPAdding(
padding: EdgeInsets.all(24) // give here padding for width you button
sliver:SliverToBoxAdapter(
child: "YourButtton"
)
)
]
);

How to make the page scrollable in the following structure (Flutter)

I'm building a product detail page. As the following piece of code and image shown, when there is a lot of content in the description part, the bottom overflow will occur. I'm wondering how to make the page scrollable, I've tried wrapping the Stack with SingleChildScrollView, but this is definitely not working in my case here. Can anyone help me with that? Thank you very much!!!!!
class DetailsScreen extends StatelessWidget {
#override
Widget build(BuildContext context) {
final size = MediaQuery.of(context).size;
return Scaffold(
backgroundColor: Colors.white,
body: Stack(
children: [
buildBody("path/to/image", size),
],
),
);
}
Positioned buildBody(String imagePath, Size size) {
return Positioned.fill(
child: Column(
children: [
Expanded(
child: Container(
padding: EdgeInsets.symmetric(vertical: 60, horizontal: 30),
color: Colors.green,
child: Stack(
children: [
Align(
alignment: Alignment.center,
child: Hero(
tag: 1,
child: Image.asset(
imagePath,
width: size.width * 0.7,
),
),
),
],
),
),
),
Expanded(
child: Container(
color: Colors.white,
child: Column(
children: [
SizedBox(
height: 100,
),
Container(
margin: EdgeInsets.symmetric(
horizontal: 20,
),
child: Row(
crossAxisAlignment: CrossAxisAlignment.start,
children: [
CircleAvatar(),
SizedBox(
width: 10,
),
Column(
crossAxisAlignment: CrossAxisAlignment.start,
children: [
Text(
'Anvesha Shandilya',
style: TextStyle(
fontWeight: FontWeight.bold, fontSize: 16),
),
Text(
'Owner',
style: TextStyle(
color: fadedBlack,
),
),
],
),
Expanded(child: Container()),
Text(
'Dec 16, 2020',
style: TextStyle(
color: fadedBlack,
fontSize: 12,
),
),
],
),
),
SizedBox(
height: 30,
),
Container(
margin: EdgeInsets.symmetric(
horizontal: 20,
),
child: Text(
'A lot of content..................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................',
style: TextStyle(
color: fadedBlack,
height: 1.7,
),
),
),
],
),
),
),
],
),
);
}
}
Error: Bottom Overflowed
To reproduce: Change the path/to/image, to this: A image can be used with the code:
tl;dr remove Expanded widgets -> remove Stack -> replace Column with ListView (for scrollability)
Start by removing Expanded widgets from the tree as you don't really need them. If possible, you should use mainAxisAlignment and crossAxisAlignment to position your widgets. That's exactly how you should handle placing the date next to user's name.
Expanded documentation states with which widgets you can use it:
Creates a widget that expands a child of a Row, Column, or Flex so
that the child fills the available space along the flex widget's main
axis.
Then remove Stack widget. If you don't then it will still work as Stack tries to get as big as its positioned children so it will just get as big as the Column you have inside. It's redundant.
Last but not least, replace Column with ListView. Column doesn't really care about whether it's overflowing or if it's being rendered. So if you create a Column that is bigger than the screen, it will simply display it which will cause the overflow. To fix that you could wrap it SingleChildScrollView, but I think it's more appropriate to just use ListView instead.
Here's an amazing explanation of layout system in Flutter: https://flutter.dev/docs/development/ui/layout/constraints

Flutter - Vertical Divider and Horizontal Divider

In Flutter, is there an option to draw a vertical lines between components as in the image.
Not as far as I know. However, it is quite simple to create one — if you look at the source for Flutter's Divider you'll see that it is simply a SizedBox with a single (bottom) border. You could do the same but with dimensions switched.
Update (Oct 4, 2018): a VerticalDivider implementation has been merged in by the Flutter team. Check out the docs but it's very simple to use — simply put it between two other items in a row.
Note: If you are using VerticalDivider as separator in Row widget then wrap Row with IntrinsicHeight , Container or SizedBox else VerticalDivider will not show up. For Container and SizedBox widget you need define height.
As of 10 days ago, flutter has merged a VerticalDivider implementation. It will be available in the default channel very soon, but for now you have to switch to the dev channel to use it: flutter channel dev.
Here is a example of how to use it:
IntrinsicHeight(
child: new Row(
mainAxisAlignment: MainAxisAlignment.spaceEvenly,
children: <Widget>[
Text('Foo'),
VerticalDivider(),
Text('Bar'),
VerticalDivider(),
Text('Baz'),
],
))
Vertical divider:
As a direct child:
VerticalDivider(
color: Colors.black,
thickness: 2,
)
In a Row:
IntrinsicHeight(
child: Row(
children: [
Text('Hello'),
VerticalDivider(
color: Colors.black,
thickness: 2,
),
Text('World'),
],
),
)
Horizontal divider:
As a direct child:
Divider(
color: Colors.black,
thickness: 2,
)
In a Column:
IntrinsicWidth(
child: Column(
children: [
Text('Hello'),
Divider(
color: Colors.black,
thickness: 2,
),
Text('World'),
],
),
)
import 'package:flutter/material.dart';
class VerticalDivider extends StatelessWidget {
#override
Widget build(BuildContext context) {
return new Container(
height: 30.0,
width: 1.0,
color: Colors.white30,
margin: const EdgeInsets.only(left: 10.0, right: 10.0),
);
}
}
Try to wrap it inside the Container with some height as
Container(height: 80, child: VerticalDivider(color: Colors.red)),
Tried with VerticalDivider() but cannot get any divider. I Solved it with
Container(color: Colors.black45, height: 50, width: 2,),
You can use a vertical divider with a thickness of 1.
VerticalDivider(
thickness: 1,
color: Color(0xFFF6F4F4),
),
And if you can't see the vertical divider wrap the row with a IntrinsicHeight widget.
Just wrap your Row in IntrinsicHeight widget and you should get the desired result:
IntrinsicHeight(
child: Row(
mainAxisAlignment: MainAxisAlignment.spaceEvenly,
children: <Widget>[
Text('Name'),
VerticalDivider(),
Text('Contact'),
],
))
As #rwynnchristian suggested, this seems to be the simplest solution IMO. Just leaving the code here:
import 'package:flutter/material.dart';
class VerticalDivider extends StatelessWidget {
#override
Widget build(BuildContext context) => RotatedBox(
quarterTurns: 1,
child: Divider(),
);
}
add this method anywhere.
_verticalDivider() => BoxDecoration(
border: Border(
right: BorderSide(
color: Theme.of(context).dividerColor,
width: 0.5,
),
),
);
now wrap your content in container
Container(
decoration: _verticalDivider(),
child: //your widget code
);
Use Container for divider is easy, wrap your row in IntrinsicHeight()
IntrinsicHeight(
child: Row(
children: [
Text(
'Admissions',
style: TextStyle(fontSize: 34),
),
Container(width: 1, color: Colors.black), // This is divider
Text('another text'),
],
),
You need to wrap VerticalDivider() widget with the IntrinsicHeight widget. Otherwise, the vertical divider will not show up. And to gain some padding over the top and bottom you can add indent.
IntrinsicHeight(
child: Row(
mainAxisSize: MainAxisSize.min,
children: [
Flexible(
child: VerticalDivider(
thickness: 0.8,
color: Colors.grey,
),
),
Flexible(
child: Text(
"Random Text",
style: TextStyle(
fontSize: 12,
color: AppColor.darkHintTextColor,),
),
),
],
),
)
I guess i found a more robust solution when dealing with this problem;
IntrinsicHeight(
child: Row(
mainAxisAlignment: MainAxisAlignment.spaceEvenly,
crossAxisAlignment: CrossAxisAlignment.center,
children: [
Expanded(
child: Container(
decoration: BoxDecoration(borderRadius: BoxRadius.circular(),color: Colors.gray),
height: 5,
margin: CustomPaddings.horizontal(),
),
),
Text(
"TEST",
style: Theme.of(context)
.textTheme
.subtitle1!
.copyWith(
color: Colors.black,
fontWeight: FontWeight.bold),
),
Expanded(
child: Container(
decoration: BoxDecoration(borderRadius: BoxRadius.circular(),color: Colors.gray),
height: 5,
margin: CustomPaddings.horizontal(),
),
),
],
),
),
Try RotatedBox in combination with a divider to get it vertical, RotatedBox is a widget of flutter that automatically rotates it's child based on the quarterTurn property you have to specify. Head over to here for a detailed explanation https://docs.flutter.io/flutter/widgets/RotatedBox-class.html