Flutter: EBook application: problem with zoom and scroll text - flutter

I am writing an ebook application in flutter.
I could have a long text page that needs to scroll (the text is outside the boundaries of the screen from the beginning).
Also, I would like to zoom in the page and keep scrolling when it is zoomed in.
This is a snippet of the code
return Container(
child: Column(
children: [
Container(
padding: EdgeInsets.all(4),
decoration: BoxDecoration(
border: Border(
bottom: BorderSide()
)
),
margin: EdgeInsets.only(left: 4, top: 4, right: 4),
child: Text("Header")
),
Expanded(
child: SingleChildScrollView(
child:
InteractiveViewer(
minScale: 0.5,
maxScale: 4,
child:
Text("A very long text...") // Here I have a text that exceeds the screen boundaries
),
),
),
]
),
);
The problem is that when I zoom in the page, the scroll range remains the same.
With this behavior the user cannot scroll the entire zoomed page.
Do you have any suggestions?
Thanks a lot.

Try changing the ListView() to a SingleChildScrollView()
body: SingleChildScrollView(
child: Padding(
padding: const EdgeInsets.all(8.0),
child: InteractiveViewer(
maxScale: 4.0,
minScale: 0.5,
child: Container(
height: 10000,
decoration: BoxDecoration(
gradient: LinearGradient(
begin: Alignment.topCenter,
end: Alignment.bottomCenter,
colors: <Color>[Colors.orange, Colors.red],
stops: <double>[0.0, 1.0],
),
),
),
),
),
),
This worked for me.
If in your case this don't work you should probably look where this snippet are being called. And instead of the SingleChildScollView wrap your e-book inside the widget you should wrap from outside of it. Like this:
return Scaffold(
appBar: AppBar(
title: Text(widget.title),
),
body: SingleChildScrollView(
child: Padding(
padding: const EdgeInsets.all(8.0),
child: <Your Widget>
),
),
);

Related

SingleChildScroll adding a large inset on-top of the Keyboard

I'm trying to create a scrollable register form for a Flutter app. I got SingleChildScroll to work, but theres a large padding or inset or something on top of the keyboard that can block content. You can see if pretty well If I scroll all they way to the bottom.
Here's my code.
Widget _buildContainer() {
return Row(
mainAxisAlignment: MainAxisAlignment.center,
children: <Widget>[
ClipRRect(
// This Clips the border Radius of the Container
borderRadius: const BorderRadius.all(
Radius.circular(20),
),
child: Container(
// This sets the attributes of the Container
height: MediaQuery.of(context).size.height * 0.69,
width: MediaQuery.of(context).size.width * 0.9,
decoration: const BoxDecoration(
color: Colors.white,
),
child: Scaffold(
body: SingleChildScrollView(
child: Form(
key: _formKey,
child: Column(
mainAxisAlignment: MainAxisAlignment.center,
children: <Widget>[
_buildFirstNameRow(),
_buildLastNameRow(),
_buildEmailRow(),
_buildPasswordRow(),
_buildConfirmPasswordRow(),
_buildRegisterButton(),
],
),
),
),
),
),
),
],
);
}
I've tried setting resizeToAvoidBottomInset: false, in the Scaffold, but that prevents any scrolling from happening.
I've also tried adding to Scaffold as well, but that only changes the padding around that mystery inset.
body: Padding(
padding: EdgeInsets.only(
bottom: 8.0),
Thanks for your Help!

How can stretch height of one of child widget according to another widget in a row?

I wanted to get same dynamic height of right widget to left widget in Row Widget.Below I was attaching screenshot of my expected design. Could you help how can do that.
We can see right side date widget is expanding , So I wanted to get the height of left side widget(blue and purple) same as right side widget.
If left side image widget is not possible to expand the height then is any there any possible to create custom widget, Any solution is welcome.
Thanks in advance.
Row(
children: [
Align(
alignment: Alignment.topCenter,
child: Container(
constraints: BoxConstraints(
minHeight: 40.0,
maxHeight: 50.0,
/*maxWidth: 10,
minWidth: 10,*/
),
padding: EdgeInsets.only(top: 0.0),
//height: 98,
width: 20,
child: ShaderMask(
shaderCallback: (bounds) {
return LinearGradient(
colors: [Color(0xff12229F), Color(0xff615FDF)],
begin: Alignment.topCenter,
end: Alignment.bottomCenter,
).createShader(bounds);
},
child: ImageIcon(
AssetImage('assets/images/reservations/small_timeline.png'),
color: Colors.white,
size: 40,
),
),
),
),
Expanded(
child: Column(
children: [
pickup(data),
dropoff(data),
],
),
),
],
),
After Using IntrinsicHeight
I was unable to remove default padding around the icons
IntrinsicHeight(
child: Padding(
padding: const EdgeInsets.only(top: 0,bottom: 0),
child: Row(
children: [
Column(
children: [
Padding(
padding: const EdgeInsets.only(top: 4),
child: Icon(
Icons.fiber_manual_record,
size: 18,
color: Color(0xff11219E),),
),
Flexible(
child: Container(
decoration: BoxDecoration(
gradient:
LinearGradient(colors: [Color(0xff11219E), Color(0xff6F6AEB)]),
),
width: 4,
),
),
Padding(
padding: const EdgeInsets.only(bottom: 4),
child: Icon(
Icons.fiber_manual_record,
size: 18,
color: Color(0xff6F6AEB),),
),
],
),
Expanded(
child: Column(
children: [
pickup(data),
dropoff(data),
],
),
),
],
),
),
),
It seems to me that Expanded could be used to expand your widget to full availabe height.
Keep in mind that the Row width will distribution will also expand, since no flex parameter is provided.
You already have an Expanded on the right widget so just add the other one and provide a flex value for both of them.
Some thing like 10 for left and 90 for right should work for you :)

Flutter: how to Align to bottom of Stack in Listview.builder

I am trying to use a Stack() Widget within a Listview to display Widgets over an Image in each iteration of the Listview however I am running into an issue. Whenever I use Align() for any widgets they stay at the top and do not Align to the Bottom of the Container()
Each image is a different size so I can not define a definite size to apply to all.
The code below aligns alignedWidget() to the topLeft even though I coded it to Align to bottomLeft
Padding(
padding: const EdgeInsets.symmetric(horizontal: 40.0),
child: ListView.builder(
itemCount: widget.posts.length,
itemBuilder: (context, index) {
return listViewCard(images[index])
}
),
)
Widget listViewCard(image) {
return Padding(
padding: const EdgeInsets.symmetric(vertical: 20.0),
child: Stack(
children: [
Container(
decoration: BoxDecoration(
borderRadius: BorderRadius.all(Radius.circular(20.0)),
),
child: ClipRRect(
borderRadius: BorderRadius.circular(18.0),
child: Image(image: NetworkImage(image), fit: BoxFit.fitWidth, )
),
),
child: Align(
alignment: Alignment.bottomLeft,
child: Padding(
padding: const EdgeInsets.only(left: 8.0),
child: Row(
children: [
alignedWidget(),
],
),
)
),
],
),
);
}
}
I'm not sure what exactly you're trying to accomplish. But to position widgets within a Stack, you can use a Positioned widget:
Stack(children: [
Positioned(bottom: 0.0, left: 0.0, child: ...)
])

Align widget in bottom navigation covers body

I have a Scaffold with the following architecture, and the body is being covered by the bottom navigation. Everything works fine if I comment the navigation.
Scaffold(
backgroundColor: Theme.of(context).backgroundColor,
appBar: AppAppBar(title: this.title),
body: Row(
children: [
Expanded(
child: Container(
child: Padding(
padding: EdgeInsets.symmetric(
horizontal: this.pageProvider.horizontalPadding,
vertical: 25),
child: this.body,
),
),
)
],
),
bottomNavigationBar: AppNavigation(),
);
This is the implementation of the AppNavigation widget:
Stack(
children: <Widget>[
Align(
alignment: Alignment.bottomCenter,
child: Container(
height: 64,
child: BottomNavigation(),
),
),
Align(
alignment: Alignment.bottomCenter,
child: Container(
height: 80,
child: WorkoutButton(),
),
),
],
);
This is the body, regardless of what widget I use:
In case it is not clear enough, the body does not have almost height.
Why don’t you use a BottomNavigationBar widget instead of a Stack?
Anyway, that happens because your Stack is unconstrained, thus, using all the available space. Give it some constrains (E.g., by wrapping it in a ConstrainedBox with some height constraint).
ConstrainedBox(
constraints: BoxConstraints.tightFor(height: 150.0),
child: Stack( ...
)
)

Flutter : Applying One Gradient For Full Background

How can i apply a gradient like here to the app background? Can you see the gradient moving down on that the app bar and the scaffold body just like they were one widget and not 2 widgets that each has his own color?
You need to use container as background to your scaffold to add a gradient. You can use Opacity widget as well to make container or any widget transparent. But here is the exact solution what you are looking for:
Scaffold(
body: Container(
height: MediaQuery.of(context).size.height,
width: MediaQuery.of(context).size.width,
decoration: BoxDecoration(
gradient: LinearGradient(
colors: [Color(0xFF282a57), Colors.black],
begin: Alignment.topCenter,
end: Alignment.bottomCenter),
),
child: Column(
children: <Widget>[
Padding(
padding: const EdgeInsets.fromLTRB(20, 50, 20, 0),
child: Container(
child: Row(
children: <Widget>[
Icon(Icons.menu,color: Colors.white,),
Spacer(),
Text("Expense",style: TextStyle(color: Colors.white,fontSize: 18,)),
Spacer(),
Icon(Icons.clear, color: Colors.white,)
],
),
),
),
],
),
)