How can I wrap this into Scaffold in Flutter? - flutter

I want to wrap this widget inside a Scaffold in order to include some title text for my app. However it returns an empty screen when I wrap it with Scaffold. Why is that?
Widget build(BuildContext context) {
return SafeArea(
child: Column(
children: [
SizedBox(
height: Dimensions.pageView,
child: PageView.builder(
//depende de dos parámetros el builder. Position cogerá desde el index 0 al itemcount.
itemCount: items.length,
controller: pageController,
itemBuilder: (context, position) {
return _buildPageItem(position);
}),
),
... MORE BASIC CHILDRENS

Widget build(BuildContext context) {
return Scaffold(
appBar: AppBar(
title: const Text('Title'),
),
body: Column(
.....
),
);
}
Note that you don't need SafeArea when using AppBar

Related

How to make clickable widget behind stack in flutter

I have two scaffold widget in the stack for some purposes .. And every scaffold has its own contents .
the second scaffold has transparent background colors so the first scaffold is visible.
Stack(
children: [
Scaffold(
body: GestureDetector(
onTap: () {},
child: myBody(),
),
),
Scaffold(
backgroundColor: Colors.transparent,
body: ListView.builder(
itemBuilder: (context, index) => ...,
),
)
],
),
the GestureDetector in first Scaffolddoes not work and that's because of the Scaffold stack
Note : I can't wrap the second Scaffold with IgnorePointer because it has clickable ListView.bulder which gonna be ignoring any pointer too
How could I solve this ×_O
You can get callback method from second scaffold list item tap. And create a function on level that will be provided on first scaffold GestureDetector.
void main(List<String> args) {
Widget myBody() {
return Container(
color: Colors.cyanAccent.withOpacity(.3),
);
}
void topLevelGesture() {
debugPrint("got hit on GestureDetector");
}
runApp(
MaterialApp(
home: Stack(
children: [
Scaffold(
body: GestureDetector(
onTap: topLevelGesture,
child: myBody(),
),
),
Scaffold(
backgroundColor: Colors.transparent,
body: ListView.builder(
itemBuilder: (context, index) => ListTile(
title: Text("item $index"),
onTap: () {
topLevelGesture();
print("tapped $index");
},
),
),
),
],
),
),
);
}
You can set Gesture as outside of the stack and with this inner list click also works but when you put the first Scaffold body as a clickable it's not working because the second Scaffold overlay that.
GestureDetector(
onTap(){}
child:Stack(
children[
Scaffold(
body: myBody()
)
Scaffold(
backGroundColor: Colors.transparent
body: ListView.bulder(){....}
)
]
))
You need to add clickable widget at the end in your stack widget as below:
Stack(
children[
firstWidget(),
GestureDetector(
onTap(){},
child: secondWidget()
)
]
)

Flutter disable scrolling on CupertinoNavBar with large title

How can I disable scrolling when there is a widget with CupertinoNavBar and large title? For instance I have:
#override
Widget build(BuildContext context) {
return CupertinoPageScaffold(
child: NestedScrollView(
headerSliverBuilder: (BuildContext context, bool innerBoxIsScrolled){
return <Widget>[
CupertinoSliverNavigationBar(
largeTitle: Text('Settings'),
)
];
},
body: Center(child: Text('Home Page'),),
),
);
}
if I add physics: NeverScrollableScrollPhysics(), it doesn't work

Is it possible to drag DraggableScrollableSheet programmatically in flutter?

I want to know how to drag the DraggableScrollableSheet widget to go up or down programmatically. For example, based on a timer class.
class HomePage extends StatelessWidget {
#override
Widget build(BuildContext context) {
return Scaffold(
appBar: AppBar(
title: const Text('DraggableScrollableSheet'),
),
body: SizedBox.expand(
child: DraggableScrollableSheet(
builder: (BuildContext context, ScrollController scrollController) {
return Container(
color: Colors.blue[100],
child: ListView.builder(
controller: scrollController,
itemCount: 25,
itemBuilder: (BuildContext context, int index) {
return ListTile(title: Text('Item $index'));
},
),
);
},
),
),
);
}
}

Correct way to display snapshot data in flutter with multiple widgets on the screen

Im really new at Flutter and Im having problems to display multiples Widgets and snapshot data.
What would be the correct way to display snapshot data inside a Column with multiples Widgets without stacic Height or special scroll ?
I mean I only want to have something like a SingleChildScrollView Where all the other widgets have to move with the _builderViewWidget but when I try to use the SingleChildScrollView I get a lot of errors like:
RenderFlex children have non-zero flex but incoming height constraints are unbounded.
This is my code:
Widget build(BuildContext context) {
StoreDatum store = widget.store;
return Scaffold(
appBar: AppBar(
title: Text('HelloWorld')
),
body: Container(
padding: EdgeInsets.all(20.0),
child: Column(
children: <Widget>[
Text(store.title, style: TextStyle(fontSize: 30.0),),
Text(store.details, style: TextStyle(fontSize: 20.0),),
_builderViewWidget(context), <---------------------------- BUILDERVIEWWIDGET
Container(
child: Text(store.address, style: TextStyle(fontSize: 20.0),),
)
]
),
),
);
}
Widget _builderViewWidget(BuildContext context){
return Container(
// height: 500.0, <------------------------------------- I DONT WANT THIS
child: Expanded(
child: Container(
child: _productBuilder(context)
)
)
);
}
Widget _productBuilder(BuildContext context) {
return FutureBuilder(
future: loadStoreProducts(),
builder: (context, snapshot) {
if(snapshot.hasData){
return _productWidget(context, snapshot.data);
}
else if(snapshot.hasError){
print(snapshot.error);
return Center(
child: Text('ERROR'),
);
}
return Center( child: CircularProgressIndicator() );
},
);
}
Widget _productWidget(BuildContext context, product){
return ListView.builder(
// physics: const NeverScrollableScrollPhysics(),
itemCount: product == null ? 0 : product.length,
itemBuilder: (context, i) {
return Container(
child: Row(
children: <Widget>[
Image.network(product[i].image),
Text(product[i].title, style: TextStyle(fontSize: 20.0),)
],
)
);
}
);
}
You have unbounded height in the vertical axis as your ListView will try to expand infinitely.
You can add shrinkWrap: true to your ListView.builder this will solve your problem.
Since you wanted the whole screen to scroll You will have to wrap Your Column in a SingleChildScrollView and remove all the Expanded widgets. And to the ListViewBuilder you can add a NeverScrollableScrollPyhsics this ensures the ListView doesn't scroll itself instead the whole screen in scrolled by SingleChildScrollView.

Flutter: How to add a text line above a ListView inside a Container

I have the following code in one of my screens. I need to add a line of text above the ListView widget. I've tried adding a Column widget above and below the Container that holds the ListView, but I can't seem to get it right.
Can anyone tell me how I do this?
Cheers,
Paul
#override
Widget build(BuildContext context) {
return WillPopScope(
child: Scaffold(
appBar: rmoAppBar(subText: 'My Jobs'),
drawer: RmoMenu(),
body: isLoading
? Center(child: CircularProgressIndicator())
: Container(
child: ListView.builder(
itemCount: jobs.sjRows.length,
itemBuilder: (BuildContext context, int index) {
return jobCard(jobs.sjRows, index);
},
),
),
),
onWillPop: () => logoutAlert(context: context),
);
}
#override
Widget build(BuildContext context) {
return WillPopScope(
child: Scaffold(
appBar: rmoAppBar(subText: 'My Jobs'),
drawer: RmoMenu(),
body: isLoading
? Center(child: CircularProgressIndicator())
: Column(
children: [
Text('Your text goes here'),
Expanded(
child: ListView.builder(
itemCount: jobs.sjRows.length,
itemBuilder: (BuildContext context, int index) {
return jobCard(jobs.sjRows, index);
},
),
)
],
),
),
onWillPop: () => logoutAlert(context: context),
);
}