how can I swipe pageview with holding background image in Flutter? - flutter

I want to hold background image and swipe pageview screen.
However, it seems that I can't swipe if I put image file(I can do only when I delete background image) even though you can see the pageindicator.
](https://i.stack.imgur.com/oXYaL.jpg)
please let me know how to do it. Is there any way to solve it? I don't know what I missed here.
import 'package:eseowakorean/page/secondpage/add_image_profile1.dart';
import 'package:eseowakorean/page/secondpage/add_image_profile2.dart';
import 'package:eseowakorean/page/secondpage/add_image_profile3.dart';
import 'package:eseowakorean/page/secondpage/add_image_profile4.dart';
import 'package:flutter/material.dart';
import 'package:flutter/src/widgets/container.dart';
import 'package:flutter/src/widgets/framework.dart';
import 'package:flutter_svg/svg.dart';
import 'package:get/get.dart';
import 'package:smooth_page_indicator/smooth_page_indicator.dart';
import '../../widgets/text_widgets.dart';
class AddInformationOnBoarding extends StatefulWidget {
const AddInformationOnBoarding({super.key});
#override
State<AddInformationOnBoarding> createState() =>
_AddInformationOnBoardingState();
}
class _AddInformationOnBoardingState extends State<AddInformationOnBoarding> {
PageController _controller = PageController();
#override
Widget build(BuildContext context) {
return Scaffold(
body: Stack(
children: [
PageView(
controller: _controller,
children: [
AddImageProfile1(),
AddImageProfile2(),
AddImageProfile3(),
AddImageProfile4(),
],
),
Container(
height: double.infinity,
width: double.infinity,
// alignment: Alignment.center,
decoration: const BoxDecoration(
image: DecorationImage(
image: AssetImage(
'assets/home.jpg',
),
fit: BoxFit.cover),
),
child: Column(
children: [
SizedBox(
height: 60,
),
Padding(
padding: const EdgeInsets.symmetric(horizontal: 25),
child: Row(
mainAxisAlignment: MainAxisAlignment.end,
children: [
SvgPicture.asset('assets/Skip.svg'),
// poppinsTextWidget('hi')
],
),
),
SizedBox(
height: 60,
),
Row(
mainAxisAlignment: MainAxisAlignment.center,
children: [
poppinsTextWidget('Let' 's Talk About You!', fontSize: 20)
],
),
],
),
),
Container(
alignment: Alignment(0, 0.75),
child: Row(
children: [
SmoothPageIndicator(controller: _controller, count: 4),
],
mainAxisAlignment: MainAxisAlignment.center,
),
),
],
),
);
}
}

You are containing everything within the same stack. Add the image itself in another Stack widget.
Try this example:
return Scaffold(
backgroundColor: Colors.white,
body: Stack(
alignment: AlignmentDirectional.bottomCenter,
children: <Widget>[
Image.asset(
"assets/home.jpg",
),
Stack(
children: [
PageView(
controller: _controller,
children: [
AddImageProfile1(),
AddImageProfile2(),
AddImageProfile3(),
AddImageProfile4(),
],
),
Column(
children: [
SizedBox(
height: 60,
),
Padding(
padding: const EdgeInsets.symmetric(horizontal: 25),
child: Row(
mainAxisAlignment: MainAxisAlignment.end,
children: [
SvgPicture.asset('assets/Skip.svg'),
// poppinsTextWidget('hi')
],
),
),
SizedBox(
height: 60,
),
Row(
mainAxisAlignment: MainAxisAlignment.center,
children: [
poppinsTextWidget('Let' 's Talk About You!', fontSize: 20)
],
),
],
),
Container(
alignment: Alignment(0, 0.75),
child: Row(
children: [
SmoothPageIndicator(controller: _controller, count: 4),
],
mainAxisAlignment: MainAxisAlignment.center,
),
),
],
),
],
),
);

Related

Flutter - how to position the background to the bottom with stack

I'm a beginner at app dev and I'm trying out flutter. I'm currently having a problem with positioning my background on the project that I am currently testing out.I'm following a UI kit that I am trying to copy for the purpose of practicing, but I am having problem with the UI.
I tried using stack but the whole screen is wrapped with its children and not taking up space. it looks like this:
and this is what I wanted to do:
This is the background that I wanted to put in my app, it is not literally a background or wallpaper because of its size. I just needed this to be placed at the bottom of the screen or background:
this is the code that I currently have:
import 'package:audit_finance_app/constant/theme.dart';
import 'package:audit_finance_app/widgets/widgets.dart';
import 'package:audit_finance_app/screens/homescreen.dart';
import 'package:flutter/material.dart';
import 'dart:math' as math;
class SignInPage extends StatefulWidget {
const SignInPage({super.key});
#override
State<SignInPage> createState() => _SignInPageState();
}
class _SignInPageState extends State<SignInPage> {
late List<String> inputPass;
String defaultPass = '1234';
#override
void initState() {
inputPass = [];
super.initState();
}
#override
Widget build(BuildContext context) {
return Scaffold(
body: Stack(
fit: StackFit.expand,
children: <Widget>[
const SizedBox(
width: double.maxFinite,
height: double.maxFinite,
child: Image(
image: AssetImage('assets/background.png'),
),
),
CustomScrollView(
slivers: <Widget>[
SliverAppBar(
pinned: true,
flexibleSpace: Container(
decoration: const BoxDecoration(
gradient: LinearGradient(
colors: [
AuditTheme.primaryColor,
AuditTheme.secondaryColor,
],
),
),
),
leadingWidth: 100,
leading: Padding(
padding: const EdgeInsets.fromLTRB(10, 0, 0, 0),
child: Row(
children: const [
Expanded(
child: ImageIcon(
AssetImage('assets/logo/white_logo.png'),
),
),
Text(
'Audit',
style: TextStyle(fontSize: 20),
),
],
),
),
title: const Text('Sign In'),
centerTitle: true,
actions: [
Transform(
alignment: Alignment.center,
transform: Matrix4.rotationY(math.pi),
child: IconButton(
onPressed: () {},
icon: const Icon(Icons.sort),
),
),
],
),
SliverList(
delegate: SliverChildListDelegate(
[
Column(
mainAxisAlignment: MainAxisAlignment.spaceEvenly,
crossAxisAlignment: CrossAxisAlignment.center,
children: [
Widgets().sixedBoxHeight(50),
Column(
children: [
const CircleAvatar(
radius: 35,
backgroundImage:
AssetImage('assets/logo/audit_logo.png'),
),
Widgets().sixedBoxHeight(10),
const Text(
'Ledjoric Vermont',
style: TextStyle(fontSize: 20),
),
],
),
Row(
mainAxisAlignment: MainAxisAlignment.center,
children: [
pinIconTest(inputPass.isNotEmpty
? Colors.black
: Colors.grey),
pinIconTest(inputPass.length >= 2
? Colors.black
: Colors.grey),
pinIconTest(inputPass.length >= 3
? Colors.black
: Colors.grey),
pinIconTest(inputPass.length == 4
? Colors.black
: Colors.grey),
],
),
Card(
child: Column(
children: [
Row(
mainAxisSize: MainAxisSize.min,
mainAxisAlignment: MainAxisAlignment.center,
children: [
numPad(const Text('1'), () => inputPin('1')),
numPad(const Text('2'), () => inputPin('2')),
numPad(const Text('3'), () => inputPin('3')),
],
),
Row(
mainAxisSize: MainAxisSize.min,
mainAxisAlignment: MainAxisAlignment.center,
children: [
numPad(const Text('4'), () => inputPin('4')),
numPad(const Text('5'), () => inputPin('5')),
numPad(const Text('6'), () => inputPin('6')),
],
),
Row(
mainAxisSize: MainAxisSize.min,
mainAxisAlignment: MainAxisAlignment.center,
children: [
numPad(const Text('7'), () => inputPin('7')),
numPad(const Text('8'), () => inputPin('8')),
numPad(const Text('9'), () => inputPin('9')),
],
),
Row(
mainAxisSize: MainAxisSize.min,
mainAxisAlignment: MainAxisAlignment.end,
children: [
const SizedBox(
width: 100,
height: 100,
),
numPad(const Text('0'), () => inputPin('0')),
numPad(
const Icon(Icons.backspace_sharp),
() => deletePin(),
),
],
),
],
),
),
],
),
],
),
),
],
),
],
),
);
}
Widget pinIconTest(Color color) {
return Padding(
padding: const EdgeInsets.all(5.0),
child: Icon(
Icons.circle,
size: 35,
color: color,
),
);
}
Widget numPad(Widget widget, void Function() function) {
return SizedBox(
width: 100,
height: 100,
child: TextButton(
style: TextButton.styleFrom(
foregroundColor: Colors.grey,
textStyle: const TextStyle(
fontSize: 30,
),
),
onPressed: function,
child: widget,
),
);
}
void inputPin(String value) {
setState(() {
inputPass.length != 4 ? inputPass.add(value) : null;
inputPass.length == 4 ? checkPass() : null;
});
print(inputPass);
}
void checkPass() {
var stringList = inputPass.join('');
if (stringList == defaultPass) {
Navigator.push(
context,
MaterialPageRoute(
builder: (context) => const HomeScreen(),
),
);
}
print(stringList);
}
void deletePin() {
setState(() {
inputPass.isNotEmpty ? inputPass.removeLast() : null;
});
print(inputPass);
}
}
I was missing the fact you want to place at the bottom that background, however to achieve that you can do it as the code below shows:
class SignInPage extends StatefulWidget {
const SignInPage({super.key});
#override
State<SignInPage> createState() => _SignInPageState();
}
class _SignInPageState extends State<SignInPage> {
#override
void initState() {
super.initState();
}
#override
Widget build(BuildContext context) {
return Scaffold(
body: Stack(
fit: StackFit.expand,
children: <Widget>[
const Align(
alignment: Alignment.bottomCenter,
child: Image(
image: AssetImage('assets/background.png'),
),
),
//Other child here
],
),
);
}
}
And this is the result:
You can use the example below for the status bar. I don't know about the real problem.
You can try using this way for gradient color
SystemUiOverlayStyle systemUiOverlayStyle = SystemUiOverlayStyle(
statusBarColor: Colors.transparent,
statusBarIconBrightness: Brightness.light,
statusBarBrightness: Brightness.dark,
statusBarGradient: LinearGradient(
colors: [Colors.red, Colors.blue],
begin: Alignment.topLeft,
end: Alignment.bottomRight,
),
);
You need to wrap your image in a Positioned Widget.
Positioned(bottom: 0.0,
child: const SizedBox(
width: double.maxFinite,
height: double.maxFinite,
child: Image(
image: AssetImage('assets/background.png'),
),
),
Or you can use the alignment property of the Stack to stick everything onto the bottom. I'm not sure this is exactly what you want though.
body: Stack(
alignment: Alignment.bottomCenter,
fit: StackFit.expand,
children: <Widget>[
const SizedBox(
width: double.maxFinite,
height: double.maxFinite,
child: Image(
image: AssetImage('assets/background.png'),
),
),

TabBar in the middle of the screen

I'm trying to put a TabBar in the middle of the screen to make a personal area view. Every time I run the code its jumps me up an exception.
The problem comes in the Tabbar the part above is just the name of the user and the Avatar but when I try to put the appbar it throws me this "throw constraintsError;"
Here is the source code which I use to make the view:
class PersonalArea extends StatelessWidget {
#override
Widget build(BuildContext context) {
String _viewSelector = "personalData";
late Color color = Colors.white;
return new Scaffold(
body: StoreConnector<AppState, PersonalAreaViewModel>(
onInit: (store) {
store.dispatch(new GetPersonalAreaAction());
},
converter: (store) => PersonalAreaViewModel.fromStore(store),
builder: (context, viewModel) => Column(children: [
Stack(children: [
Container(
width: double.infinity,
padding: EdgeInsets.only(left: 4, right: 4),
child: Column(
children: [
Container(
height: MediaQuery.of(context).size.height / 2,
child: Column(
mainAxisSize: MainAxisSize.min,children: [
Stack(
children: [
Row(
mainAxisAlignment: MainAxisAlignment.center,
children: [
avatar(),
],
),
Align(
alignment: Alignment.topRight,
child: edit(),
)
],
),
//Avatar&Edit
Row(
mainAxisAlignment: MainAxisAlignment.center,
children: [
Container(
padding: EdgeInsets.only(top: 12),
child: generateStyleText(
"${FirebaseAuth.instance.currentUser?.displayName}",
color.primary75,
FontWeight.w700,
0,
16,
0),
)
],
),
//Name
]), //MainColumn
),
DefaultTabController(
length: 3,
child: Container(
child: Column(
children: [
TabBar(
tabs: [
Tab(
text: "Experiencia",
),
Tab(
text: "Area",
),
Tab(
text: "pedro",
),
],
indicatorSize: TabBarIndicatorSize.tab,
),
Expanded(
child: TabBarView(
children: [
Text('people'),
Text('Person'),
Text("data"),
],
),
)
],
),
))
],
),
)
])
])));
}
Wrap the DefaultTabController with Expanded

Bottom overflow 13 pixels

How can fix it?
Widget build(BuildContext context) {
final Size size = MediaQuery.of(context).size;
return Scaffold(
resizeToAvoidBottomInset: false,
body: Stack(
fit: StackFit.loose,
children: [
Column(
mainAxisSize: MainAxisSize.min,
children: <Widget>[
Expanded(
flex: 2,
child: buildSearch(),
),
Expanded(
flex: 2,
child: Container(color: Colors.green),
),
Row(
mainAxisAlignment: MainAxisAlignment.spaceBetween,
children: [
Text('Frequitly Visited'),
TextButton(
onPressed: () {},
child: Text('Show More'),
),
],
),
Expanded(
flex: 6,
child: buildSites(size),
)
],
)
],
),
);
}
buildSearch() {
return Container(
child: FloatingSearchBar(
transitionCurve: Curves.easeInOutCubic,
transition: CircularFloatingSearchBarTransition(),
physics: const BouncingScrollPhysics(),
scrollPadding: EdgeInsets.zero,
builder: (context, _) => _history(),
),
);
}
Container buildSites(size) {
return Container(
color: Colors.black,
width: size.width,
);
}
Widget _history() {
List<String> listHistory = [
'Flutter',
'Python',
'Nodejs',
'Rails',
];
return ClipRRect(
borderRadius: BorderRadius.circular(8),
child: Material(
child: Column(
children: listHistory
.map((e) => ListTile(
title: Text(e),
onTap: () {},
))
.toList(),
),
),
);
}
}
try to fixed the height of search & container, expanded only flexible part:
Column(
mainAxisSize: MainAxisSize.min,
children: <Widget>[
Container(
height: 100,
child: buildSearch(),
),
Container(
height: 100,
child: Container(color: Colors.green),
),
Row(
mainAxisAlignment: MainAxisAlignment.spaceBetween,
children: [
Text('Frequitly Visited'),
TextButton(
onPressed: () {},
child: Text('Show More'),
),
],
),
Expanded(
child: buildSites(size),
)
],
)
You can just remove the Expanded widget wrapped around your buildSearch() widget and give a desired padding or you can also your sizedbox with a desiredHeight below and above the buildSearch()
so basically change
...
Expanded(
flex: 2,
child: buildSearch(),
),
...
to
...
Padding(
padding:EdgeInsets.only(top:20,bottom:50), // adding a suitable padding should fix it
child:buildSearch(),
)
...

How do I set the animated container without error when opening the picture?

When I press the arrow button on the left using the animation container, I want it to slide down, but the picture is loaded before and it gives an error. How do I synchronize the picture with the container?
here I gave the animated container in the picture. To grow in the picture at the same time as the growth rate of the container, but it did not happen. I tried using the Animation control but didn't understand exactly how to use it in the Animation container.
import 'package:flutter/cupertino.dart';
import 'package:flutter/material.dart';
import 'package:google_fonts/google_fonts.dart';
import '../models/question_model.dart';
import 'package:date_format/date_format.dart';
class ActiveQuestion extends StatefulWidget {
final Question question;
ActiveQuestion({Key key, this.question}) : super(key: key);
#override
_ActiveQuestionState createState() => _ActiveQuestionState();
}
class _ActiveQuestionState extends State<ActiveQuestion> with SingleTickerProviderStateMixin{
bool tapped = false;
double _margin = 15;
double _height = 120;
Color _color = Colors.white;
#override
Widget build(BuildContext context) {
return AnimatedContainer(
duration: Duration(milliseconds: 100),
margin: EdgeInsets.all(_margin),
width: double.infinity,
height: _height,
decoration: BoxDecoration(
color: _color,
borderRadius: BorderRadius.circular(12),
border: Border.all(color: Colors.black,width: 3.0)
),
child: Column(
mainAxisAlignment: MainAxisAlignment.spaceBetween,
crossAxisAlignment: CrossAxisAlignment.center,
children: [
Row(
mainAxisSize: MainAxisSize.max,
mainAxisAlignment: MainAxisAlignment.spaceBetween,
crossAxisAlignment: CrossAxisAlignment.start,
children: [
if (!tapped)
Flexible(
flex: 1,
child: IconButton(
icon: Icon(Icons.arrow_downward),
onPressed: () {
setState(() {
_height +=250;
tapped = tapped ? false : true;
});
},
),
),
if (tapped)
Flexible(
flex: 1,
child: IconButton(
icon: Icon(Icons.arrow_upward),
onPressed: () {
setState(() {
_height -=250;
tapped = tapped ? false : true;
});
},
),
),
Flexible(
flex: 4,
child: Column(
crossAxisAlignment: CrossAxisAlignment.start,
children: [
Row(
mainAxisAlignment: MainAxisAlignment.spaceBetween,
children: [
Flexible(child: Text(widget.question.title,style: GoogleFonts.rokkitt(fontSize: 20),)),
],
),
SizedBox(height: 10,),
Row(
mainAxisAlignment: MainAxisAlignment.spaceBetween,
children: [
Row(
children: [
Icon(Icons.comment),
Text(widget.question.answerCount.toString(),style: GoogleFonts.rokkitt(fontSize: 18),),
],
),
Text("#" + widget.question.name,style: GoogleFonts.rokkitt(fontSize: 18),),
Text('${formatDate(DateTime.parse(widget.question.time),[dd,'.',mm,".",yy," ",HH,":",nn])} ',style: GoogleFonts.rokkitt(fontSize: 18),),
],
),
],
),
),
],
),
if(tapped)
Divider(thickness: 1,),
if (tapped)
AnimatedContainer(
width: double.infinity,
height: _height,
duration: Duration(milliseconds: 1000),
child: SizedBox(
child: Image(
fit: BoxFit.fitWidth,
image: NetworkImage(widget.question.questPath,),
),
),
)
],
),
);
}
}
You should be able to do this by simply wrapping your Image (or SizedBox) in a ClipRect. The linked page includes an example showing how to define the alignment of the child. In your case, I imagine you'll want to align it to the top.

flutter How to align text in a row /column

I am writing a row of data with space between the item. However, the items on the right side are not aligned properly.
As you can see from image the right elements are aligned to the end
How do I fit it so the "*" are aligned
Here is my code
static pw.Row makeRow(String sk1, String sk2) {
return pw.Row(
mainAxisAlignment: pw.MainAxisAlignment.spaceBetween,
crossAxisAlignment: pw.CrossAxisAlignment.start,
children: <pw.Widget>[
pw.Column(
children: <pw.Widget>[
pw.Row(
children: <pw.Widget>[
pw.Container(
width: 2.0,
height: 2.0,
decoration: pw.BoxDecoration(
shape: pw.BoxShape.circle,
color: PdfColor.fromInt(Colors.black.value),
),
),
pw.SizedBox(width: 5.0),
makeTextField(sk1, size: 11.0),
],
)
],
),
if (sk2 != null)
pw.Column(
children: <pw.Widget>[
pw.Row(
children: <pw.Widget>[
pw.Container(
width: 2.0,
height: 2.0,
decoration: pw.BoxDecoration(
shape: pw.BoxShape.circle,
color: PdfColor.fromInt(Colors.black.value),
),
),
pw.SizedBox(width: 4.0),
makeTextField(sk2, size: 11.0),
],
)
],
),
],
);
}
I am looping through a list and calling the method to create a row.
Thanks for your help
import 'package:flutter/material.dart';
void main() {
runApp(
MaterialApp(
home: MyWidget(),
),
);
}
class MyWidget extends StatelessWidget {
#override
Widget build(BuildContext context) {
return Scaffold(
body: Padding(
padding: EdgeInsets.all(50),
child: Row(
mainAxisAlignment: MainAxisAlignment.spaceBetween,
children: [
Column(
children:[
Text('Skill 1'),
Text('Skill 2'),
]
),
Column(
crossAxisAlignment: CrossAxisAlignment.start,
// If you want to move it to the end just use CrossAxisAlignment.end
children:[
Text('Skill 1'),
Text('Skill 22222'),
]
),
]
)
)
);
}
}
This code will give you following output:
You can use the table widget instead of columns and rows
Look at
https://api.flutter.dev/flutter/widgets/Table-class.html
Try this:
Row(
mainAxisAlignment: MainAxisAlignment.spaceBetween,
children: [
Column(
crossAxisAlignment: CrossAxisAlignment.start,
children: [
Text('Skill 12938'),
Text('Skill 2')
]
),
Column(
crossAxisAlignment: CrossAxisAlignment.start,
children: [
Text('Skill 3'),
Text('Skill 42938')
]
)
]
)
demo: https://dartpad.dev/b6409e10de32b280b8938aa75364fa7b