I've been developing an app and noticed that the CupertinoPageRoute keeps pushing content upwards when going to a new page. This is quite annoying as it creates a lag/stutter effect.
Here is an image demonstrating this issue:
Incorrect UI
Meanwhile this is how the UI is supposed to look:
Correct UI
Here is a video:
https://vimeo.com/798133261
My code:
WelcomePage({Key? key}) : super(key: key);
final TextEditingController emailEditingController = TextEditingController();
#override
Widget build(BuildContext context) {
return Scaffold(
body: SafeArea(
child: Stack(
children: [
Center(
child: Column(
mainAxisAlignment: MainAxisAlignment.center,
children: const [
Text(
"Welcome!",
style: TextStyle(fontSize: 36, fontWeight: FontWeight.bold),
),
SizedBox(height: 5),
Text(
"Sign up to see what your friends are listening to!",
style: TextStyle(
fontSize: 14,
fontWeight: FontWeight.normal,
),
textAlign: TextAlign.center,
),
SizedBox(height: 100),
],
),
),
Column(
mainAxisAlignment: MainAxisAlignment.spaceBetween,
children: [
Row(
mainAxisAlignment: MainAxisAlignment.center,
children: [
ClipRRect(
borderRadius: BorderRadius.circular(16.0),
child: Image.asset(
'assets/images/icons/app/app_icon_transparent.png',
width: 50,
height: 50,
),
),
],
),
Padding(
padding: const EdgeInsets.only(bottom: 30),
child: Column(
children: [
ThirdPartySignIn(),
Padding(
padding: const EdgeInsets.only(top: 15),
child: CupertinoButton(
onPressed: () {
Navigator.push(
context,
CupertinoPageRoute(
builder: (context) => SignupPage(),
),
);
},
padding: const EdgeInsets.symmetric(horizontal: 16.0),
child: Container(
height: 50,
decoration: BoxDecoration(
borderRadius: BorderRadius.circular(16.0),
gradient: LinearGradient(
begin: Alignment.centerLeft,
end: Alignment.centerRight,
colors: [
CustomColors.accentColor,
CustomColors.accentColor
],
),
),
child: const Center(
child: Text(
"Sign up",
style: TextStyle(
fontSize: headlineLabelFontSize,
fontWeight: FontWeight.w500,
color: CupertinoColors.white),
),
),
),
),
),
],
),
),
],
),
],
),
),
);
}
}
At first, I thought that the issue was with the Stack widget, however I tried using a column widget and recieved the same effect. I am not sure if this is a bug but I am sure that there is a possible work around. Thank you.
To fix this problem, I just had to add resizeToAvoidBottomInset: false to my main scaffold, and the page stopped resizing.
Related
I don't know what I did wrong.
import 'package:flutter/material.dart';
import 'package:nle_app/models/stall.dart';
import 'package:nle_app/constants/colors.dart';
class StallInfo extends StatelessWidget {
final stall = Stall.generateRestaurant();
#override
Widget build(BuildContext context) {
return Container(
margin: const EdgeInsets.only(top: 40),
padding: const EdgeInsets.symmetric(horizontal: 25),
child: Column(
children: [
Row(
mainAxisAlignment: MainAxisAlignment.spaceBetween,
children: [
Column(
crossAxisAlignment: CrossAxisAlignment.start,
children: [
Text(
stall.name,
style: const TextStyle(
fontSize: 25,
fontWeight: FontWeight.bold,
),
),
const SizedBox(height: 10),
Row(
children: [
Container(
padding: EdgeInsets.all(5),
decoration: BoxDecoration(
color: Colors.blueGrey.withOpacity(0.4),
borderRadius: BorderRadius.circular(5),
),
child: Text(
stall.label,
style: const TextStyle(
color: Colors.white,
),
)),
const SizedBox(
width: 10,
),
],
)
],
),
ClipRRect(
borderRadius: BorderRadius.circular(50),
child: Image.asset(
stall.logoUrl,
width: 80,
),
),
],
),
const SizedBox(
height: 5,
),
Row(
mainAxisAlignment: MainAxisAlignment.spaceBetween,
children: [
Text(
stall.desc,
style: const TextStyle(fontSize: 16),
),
Row(
children: [
const Icon(
Icons.star_outline,
color: Colors.amber,
),
Text(
'${stall.score}',
style: const TextStyle(
fontSize: 18,
fontWeight: FontWeight.bold,
),
),
const SizedBox(width: 15),
],
)
],
)
],
),
);
}
}
The image I uploaded shows what its suppossed to look like but in case you missed it, it's supposed to look like .
I thought maybe the image overflowed to the right but even when I remove the image it's the same thing.
I've tested it on different devices but it's all the same. It doesn't even throw an exception or anything. Does anyone know how to fix this.
It is missing material, Check if the parent widget contains Scaffold. Also for this one , you can wrap with any material widget like Material, Card,Scaffold....
Widget build(BuildContext context) {
return Material(
child: Container(
```
I have a few screens that I need to switch between using the BottomNavigationBar in Flutter when I tap on the Icons.
I'm calling the different screens in a List widget below:
List<Widget> pages = [
const Dashboard(),
const HomePage(checklistData: [], numberofForms: 0, userData: {},),
const ScannerPage(title: 'Scan QR Code',),
const Notifications(),
const Login(),
];
However, this is the output when I click on one Icon to call up the screen that I need:
Stacked Up Screen
The first AppBar with "Maintenance Checklist" is from the screen I'm calling.
The second AppBar with "Welcome back, Agent Wesley!" is from the Dashboard() screen which should be disappearing when calling the Checklist screen.
How do I make sure that the content of the screen I call is what appears on that screen not all content from other screens?
Here is my Scaffold from Dashboard() that I think is causing the problem:
backgroundColor: Constants.primaryColor,
body: Stack(
clipBehavior: Clip.none,
children: [
pages.elementAt(activeIndex),
SingleChildScrollView(
child: Container(
child: Column(
mainAxisSize: MainAxisSize.min,
crossAxisAlignment: CrossAxisAlignment.start,
children: [
const SizedBox(
height: kToolbarHeight,
),
Container(
padding: const EdgeInsets.symmetric(
horizontal: 16.0,
),
child: Column(
mainAxisSize: MainAxisSize.min,
crossAxisAlignment: CrossAxisAlignment.start,
children: [
GestureDetector(
onTap: () {
Navigator.pop(context);
},
child: const Icon(
FlutterIcons.keyboard_backspace_mdi,
color: Colors.white,
),
),
Row(
mainAxisAlignment: MainAxisAlignment.spaceBetween,
children: [
RichText(
text: TextSpan(
children: [
TextSpan(
text: "Welcome back,\n",
style: Theme.of(context)
.textTheme
.headline6
?.copyWith(
color: Colors.white,
),
),
TextSpan(
text: "Agent Wesley!",
style: Theme.of(context)
.textTheme
.headline6
?.copyWith(
color: Colors.white,
fontWeight: FontWeight.w600,
),
)
],
),
),
],
)
],
),
),
const SizedBox(
height: 50.0,
),
Container(
width: double.infinity,
constraints: BoxConstraints(
minHeight: MediaQuery.of(context).size.height - 200.0,
),
decoration: BoxDecoration(
borderRadius: const BorderRadius.only(
topLeft: Radius.circular(30.0),
topRight: Radius.circular(30.0),
),
color: Constants.scaffoldBackgroundColor,
),
padding: const EdgeInsets.symmetric(
vertical: 24.0,
),
child: Column(
mainAxisSize: MainAxisSize.min,
crossAxisAlignment: CrossAxisAlignment.start,
children: [
const Padding(
padding: EdgeInsets.symmetric(
horizontal: 24.0,
),
child: Text(
"Agent Services",
style: TextStyle(
color: Color.fromRGBO(19, 22, 33, 1),
fontSize: 18.0,
),
),
),
const SizedBox(height: 7.0),
Container(
height: 100.0,
child: const Center(
// lets make a widget for the cards
//child: ServiceSlider(),
),
),
],
),
)
],
),
),
),
],
),
);
you can use navigator (https://docs.flutter.dev/cookbook/navigation/navigation-basics)
or use PageView (https://api.flutter.dev/flutter/widgets/PageView-class.html)
Subject: PageView and GetX
I'm having trouble detaching the controls on a PageView widget from the HomeView module. I have a GlobalController with its respective GlobalBinding that are instantiated when opening the HomeView. I would like to take the setPage(int page) method to the GlobalController that would eventually make the HomeView's PageView change pages. I don't know how to get PageController from PageView to GlobalController in order to make it work. How should I proceed?
Something Like this?
am using pageview in onboarding
class Onboard{
final headTitle;
final secondarytitle;
final discription;
final pngimage;
Onboardslist(this.headTitle, this.secondarytitle, this.discription, this.pngimage);
}
then for the controller
class OnboardController extends GetxController{
var selectedPagexNumber = 0.obs;
bool get isLastPage => selectedPagexNumber.value == onBoardPages.length -1;
var pageControll = PageController();
forwardAct()
{
if(isLastPage) Get.offNamedUntil(signin, (route)=> false);
else pageControll.nextPage(duration: 300.milliseconds, curve: Curves.ease);
}
List<Onboardslist> onBoardPages =
[
Onboardslist("title",
"short description",
"long description",
imageString),
Onboardslist("title",
"short description",
"long description",
imageString),
Onboardslist("title",
"short description",
"long description",
imageString),
Onboardslist("title",
"short description",
"long description",
imageString)
];
}
then for the view i did was simply like this
class Onboarding extends StatelessWidget {
final yourController= OnboardController();
#override
Widget build(BuildContext context) {
SizeXGet().init(context);
return Scaffold(
backgroundColor: decent_white,
appBar: AppBarCustom(
title: 'Skip',
button: ()=>Get.offNamedUntil(signin,(route)=>false),
),
body: WillPopScope(
onWillPop: () async => false,
child: SafeArea(
child: Stack(
children: [
PageView.builder(
controller: yourController.pageControll,
onPageChanged: yourController.selectedPagexNumber,
itemCount: yourController.onBoardPages.length,
itemBuilder: (context, index)
=>Padding(
padding: const EdgeInsets.only(left: 10,right: 10),
child: Container(
child: SingleChildScrollView(
physics: BouncingScrollPhysics(),
child: Column(
crossAxisAlignment: CrossAxisAlignment.center,
mainAxisAlignment: MainAxisAlignment.center,
children: [
Container(
height: getHeight(150),
child: Column(
crossAxisAlignment: CrossAxisAlignment.center,
mainAxisAlignment: MainAxisAlignment.center,
children: [
Padding(
padding: const EdgeInsets.only(left: 20,right: 20),
child: Text(yourController.onBoardPages[index].headTitle,
style: TextStyle(
color: darkish_color,
fontSize: getHeight(20),
fontFamily: 'Metropolis-SemiBold' ,
fontWeight: FontWeight.bold
),),
),
SizedBox(height: 15,),
Padding(
padding: const EdgeInsets.only(left: 50,right: 50),
child: Text(yourController.onBoardPages[index].secondarytitle,
style: TextStyle(
color: not_sopure_black,
fontSize: getHeight(26),
fontFamily: 'Metropolis-Bold' ,
fontWeight: FontWeight.bold
),
),
),
SizedBox(height: 15,),
Padding(
padding: const EdgeInsets.only(left: 40,right: 40),
child: Text(yourController.onBoardPages[index].discription,
style: TextStyle(
color: not_sopure_black,
fontSize: getHeight(15),
fontFamily: 'Metropolis-Regular' ,
),
),
),
],
),
),
SizedBox(height: 15,),
Image.asset(yourController.onBoardPages[index].pngimage),
],
),
),
),
),
),
],
),
),
),
bottomNavigationBar: BottomAppBar(
color: Colors.transparent,
elevation: 0,
child: Container(
height: 75,
width: MediaQuery.of(context).size.width,
child: Padding(
padding: const EdgeInsets.only(left: 25,right:25,),
child: Container(
width: MediaQuery.of(context).size.width,
child: Stack(
children: [
Align(
alignment: Alignment.centerLeft,
child: Container(
child: Row(
children: List.generate(yourController.onBoardPages.length,
(index)=>Obx(()=>
AnimatedContainer(
duration: Duration(milliseconds: 200),
margin: EdgeInsets.only(right: 5),
height: 10,
width: yourController.selectedPagexNumber.value == index ? 20 : 10,
decoration: BoxDecoration(
borderRadius: BorderRadius.circular(60),
color: yourController.selectedPagexNumber.value == index
? darkish_color
: not_sopure_black,),
),
)),
),
),
),
Align(
alignment: Alignment.centerRight,
child: Container(
width: 130,
height: 52,
child: RaisedButton(
elevation: 0,
onPressed: yourController.forwardAct,
splashColor: not_sopure_black,
color: darkish_color,
shape: RoundedRectangleBorder(
borderRadius: BorderRadius.circular(100)
),
child: Obx(() =>
Row(
mainAxisAlignment: MainAxisAlignment.center,
children: [
Text(yourController.isLastPage ? 'Next' : 'Next',
style: TextStyle(
color: Colors.white,
fontFamily: 'Metropolis-Semibold',
fontSize: 16,
),
),
],
),
),
),
),
)
],
),
),
),
),
),
);
}
}
I have issue my screen showing orange line in end and show ing error of A Renderflex overflowed by 5105 pixels on the bottom .
My code
class Orderlist extends StatelessWidget {
final posts;
Orderlist({Key key, this.posts}) : super(key: key);
#override
Widget build(BuildContext context) {
double stackWidth = MediaQuery.of(context).size.width;
double stackHeight = MediaQuery.of(context).size.height;
return SingleChildScrollView(
child: Column(
children: [
test(),
test(),
test(),
test(),
test()
],
),
);
}
}
class test extends StatelessWidget {
#override
Widget build(BuildContext context) {
double width = MediaQuery.of(context).size.width;
double height = MediaQuery.of(context).size.height;
return Container(
color: Color(0xfff6f6f6),
child: Padding(
padding: const EdgeInsets.all(14.0),
child: Card(
shape: RoundedRectangleBorder(
borderRadius: BorderRadius.circular(8.0),
),
child: Column(
children: <Widget>[
Padding(
padding: const EdgeInsets.all(10.0),
child: Container(
color: Color(0xfff8f8f8),
child: Row(
mainAxisAlignment: MainAxisAlignment.spaceBetween,
children: <Widget>[
Padding(
padding: const EdgeInsets.all(10.0),
child: Column(
crossAxisAlignment:
CrossAxisAlignment.start,
children: <Widget>[
Text(
'asdada',
style: TextStyle(
fontFamily: 'SFPROBOLD',
color: Colors.black,
fontSize: 16,
fontWeight: FontWeight.bold),
),
Text(
'asda'
.toString(),
style: TextStyle(
color: Colors.grey, fontSize: 14))
],
),
),
Padding(
padding: const EdgeInsets.all(8.0),
child: Container(
width: width * 0.13,
decoration: BoxDecoration(
color: Color(0xffef9500),
borderRadius: BorderRadius.all(
Radius.circular(5))),
child: Padding(
padding: const EdgeInsets.all(4.0),
child: Center(
child: Text('Pending',
style: TextStyle(
fontFamily: 'SFPROBOLD',
color: Colors.white,
fontSize: 9))),
),
),
),
],
),
),
),
Padding(
padding: const EdgeInsets.all(13.0),
child: Column(
crossAxisAlignment: CrossAxisAlignment.start,
children: <Widget>[
Container(
child: Text(
'Delivery',
style: TextStyle(
fontFamily: 'SFPROBOLD',
color: Color(0xffea6c7b),
fontSize: 13),
),
),
Row(
mainAxisAlignment:
MainAxisAlignment.spaceBetween,
children: <Widget>[
Container(
child: Text(
'asdada',
style: TextStyle(fontSize: 15),
),
),
IconButton(
icon: Icon(
Icons.arrow_forward,
color: Colors.grey,
),
onPressed: () {
// do something
Navigator.push(
context,
MaterialPageRoute(
builder: (context) =>
OrderDetails()),
);
},
)
],
)
],
),
)
],
),
),
),
);
}
}
Try to wrap the first widget with SingleScrollview but its not working. Also try to wrap the Listviewbuilder but still showing pixels error and if i wrap SignleScrollview with expanded then its showing parent directory error
I think the error is because you wrapped the column in ListView as well as SingleChildScrollView. Try removing any one of them.
So, here is my code for the GridView. I'm already tried to use InkWell but it does not navigate to the page that is specified. I don't know what is the problem as I am new in coding world. I also try restructure the code but as I said I am new so the code always got some error here and there. I hope i can get some help in solving this problem. Thank you all.
class _DashboardState extends State<Dashboard> {
Material myItems(IconData icon, String heading, int color) {
return Material(
color: Colors.white,
elevation: 14.0,
shadowColor: Color(0x802196F3),
borderRadius: BorderRadius.circular(20.0),
child: Center(
child: Padding(
padding: const EdgeInsets.all(8.0),
child: Row(
mainAxisAlignment: MainAxisAlignment.center,
children: <Widget>[
Column(
mainAxisAlignment: MainAxisAlignment.center,
children: <Widget>[
//text
Center(
child: Padding(
padding: const EdgeInsets.all(8.0),
child: Text(
heading,
style: TextStyle(
color: new Color(color),
fontSize: 20.0,
),
),
),
),
//icon
Material(
color: new Color(color),
borderRadius: BorderRadius.circular(24.0),
child: Padding(
padding: const EdgeInsets.all(16.0),
child: Icon(
icon,
color: Colors.white,
size: 30.0,
),
),
),
],
)
],
),
),
),
);
}
#override
Widget build(BuildContext context) {
return Scaffold(
appBar: AppBar(
title: Text(
'Dashboard',
style: TextStyle(
color: Colors.white,
),
),
),
body: Container(
padding: EdgeInsets.all(16.0),
child: StaggeredGridView.count(
crossAxisCount: 1,
mainAxisSpacing: 12.0,
padding: EdgeInsets.symmetric(horizontal: 16.0, vertical: 8.0),
children: <Widget>[
myItems(
Icons.report,
"Report",
0x802196F3),
myItems(
Icons.insert_chart,
"Chart",
0x802196F3),
myItems(
Icons.format_list_numbered,
"Ranking",
0x802196F3),
],
staggeredTiles: [
StaggeredTile.extent(1, 130),
StaggeredTile.extent(1, 130),
StaggeredTile.extent(1, 130)
],
),
),
);
}
}
I tried adding an Inkwell with a simple print statement to one of your tiles and it worked, clicking on report prints hello in the console.
children: <Widget>[
InkWell(
onTap: () {
print('hello!');
},
child: myItems(Icons.report, "Report", 0x802196F3),
),
myItems(Icons.insert_chart, "Chart", 0x802196F3),
myItems(Icons.format_list_numbered, "Ranking", 0x802196F3),
],
),