How retrieve two classes Flutter - flutter

i am green in flutter and i have quick question, would like to make retrieve two classes SearchBar() & HomeView(), but it only allows to retrieve one class. I understand that something is missing, i would like to hear your suggestions in order to learn it better.
return Scaffold(
appBar: AppBar(
title: Text(title),
actions: <Widget>[
IconButton(
icon: Icon(
Icons.add_box,
color: Colors.white,
),
onPressed: () {
Navigator.push(
context,
MaterialPageRoute(
builder: (context) =>
AddBookPage(uid: this.widget.uid)));
})
],
),
body: SearchBar(),
body: HomeView(),
drawer: NavigateDrawer(uid: this.widget.uid));
}
Here is the picture how i would like make it look like
I get Search Bar overflowed by Infinity pixels on the bottom

Use Column:
Scaffold(
body: Column(
children: [
SearchBar(),
SizedBox(height: 20),
Expanded(
child: HomeView(),
)
],
),
// ... your other code
)

Using a Column may be the best way.
The overflow error is probably caused by the SearchBar() widget not having a defined height. A Column widget can't have a child with infinite height.

Related

Flutter Modal Bottom Sheet with Navigator does not pop as expected

I a working with ModalBottomSheet and I love the package. However I am encountering an issue when trying to navigate with in a ModalBottomSheet.
Here is a ScreenVideo for a better understanding.
As you can see the View is presented as a ModalBottomSheet. But when popping it, it is not simply dismissing to the bottom but instead it is popping to some empty screen with a MaterialPage Pop animation.
I changed my code so I can push with a MaterialPageRoute-Animation inside that ModalBottomSheet. Before that everything was working as expected.
Here is my Page:
class _AboutScreenState extends State<AboutScreen> {
#override
Widget build(BuildContext context) {
return Material(
color: AppColors.primary,
child: Navigator(
onGenerateRoute: (settings) => MaterialPageRoute(
builder: (context2) => Builder(
builder: (context) => CupertinoPageScaffold(
backgroundColor: AppColors.secondary,
resizeToAvoidBottomInset: false,
child: SafeArea(
child: Padding(
padding: EdgeInsets.all(sidePadding),
child: Column(
crossAxisAlignment: CrossAxisAlignment.start,
children: [
Row(
mainAxisAlignment: MainAxisAlignment.end,
children: [
IconButtonWithExpandedTouchTarget(
onTapped: () {
Navigator.pop(context);
},
svgPath: 'assets/icons/down.svg',
),
],
),
Text(
'About',
style: AppTextStyles.montserratH2SemiBold,
),
...
RoundedCornersTextButton(
title: 'Impressum',
onTap: () {
Navigator.pop(context);
},
textColor: AppColors.primary,
backgroundColor: AppColors.secondary,
borderColor: AppColors.primary,
),
],
),
),
)),
),
),
),
);
}
}
I was simply following this example. What am I missing here? With the code above I can push inside the ModalSheet as expected with a MaterialPageRoute Animation but popping the first screen brings up the issue...
Let me know if you need any more info! Any help is appreciated :)
I think you are popping with the wrong context. The example is popping with rootContext, which is from the top-most widget in the hierarchy. You are popping from with context, defined at your lowest builder in the hierarchy.
I believe you are using the incorrect context. rootContext, which is from the top-most widget in the hierarchy, is what makes the sample pop. You're popping from your lowest builder in the hierarchy, which is dictated by context.

how we can use two rows in appbar flutter Like first row with title and the second with search input field

Hi There I am working on a app where i need to use two sections in appbar one upper
1->section with logo and some Icons
2-> Search input field below the Title Section.
UI images are attached for better understanding.
you can customize the size of app bar by using toolbarHeight: 120.0 // set value
then use flexibleSpace to add column or rows
it will look something like this
import 'package:flutter/material.dart';
void main() => runApp(App());
class App extends StatelessWidget {
#override
Widget build(BuildContext context) {
return MaterialApp(
home: Scaffold(
appBar: AppBar(
toolbarHeight: 120.10, //set your height
flexibleSpace: SafeArea(
child: Container(
color: Colors.blue, // set your color
child: Column(
children: [
Row(
children: [Text("Logo")],
),
Text("data"), // set an icon or image
IconButton(
icon: Icon(Icons.search),
onPressed: () {}) // set your search bar setting
],
),
),
),
),
),
);
}
}
Just simply create your AppBar as intended, in your screenshot, you don't actually need a second Row. A TextFormField will be enough (you will actually need to customise the InputDecoration as well):
return AppBar(
title: Column(children: [
Row(children: [
Icon(Icons.menu),
Text('First row'),
const Spacer(),
Icon(Icons.person),
]),
TextFormField(),
]),
);
You can use the bottom property from the AppBar widget.
AppBar(
title: YourFirstRowWidget(),
centerTitle: true,
bottom: PreferredSize(
child: YourSearchBarWidget(),
preferredSize: null),
)
But you may want to create your own AppBar widget for a perfect result.

How to make a Widget come from below and stack itself on top of current screen?

In Duolingo's app, there is an element that comes animated from the bottom and display some text everytime you unswer a question (see image bellow).
How to replicate that feature with Flutter?
You can use showModalBottomSheet widget. Here is a simple usage of this widget:
showModalBottomSheet(
context: context,
builder: (BuildContext bc){
return Container(
child: new Wrap(
children: <Widget>[
new ListTile(
leading: new Icon(Icons.music_note),
title: new Text('Music'),
onTap: () => {}
),
new ListTile(
leading: new Icon(Icons.videocam),
title: new Text('Video'),
onTap: () => {},
),
],
),
);
}
);
You can read an article about how to use Bottom sheets here
I hope this will help you.

How to use provider beetween several classes in flutter?

I am creating a register app in flutter, but there is too much information tu use a single screen, so I decided to use tab views in the screens and separate the screens in objects of a drawer.
but I needed to use the information from diferent screens to saved it. so I think about using a Multiprovider. but when I try to use the information in the provider it throws:
Could not find the correct Provider<General> above this Baseformularios Widget
my implementation is like this:
Here is my drawer with the first field General, that is basic information about the client,
as you can see the provider is created here and the body: is supplied by a variable called bodycontent, that will be over written when a try to change the form, but when I try to print the name of the user it throws the error above.
MultiProvider(
providers: [
ChangeNotifierProvider<General>(
create: (context)=>General(),
)
],
child: Scaffold(
appBar: AppBar(
title: Text("Historias clinicas"),
centerTitle: true,
actions: <Widget>[
IconButton(
icon: Icon(Icons.check),
onPressed: (){
print(Provider.of<General>(context).nombre);
Provider.of<General>(context).addCLiente();
},
)
],
),
body: bodycontent,
drawer: Drawer(
child: ListView(
padding: EdgeInsets.zero,
children: <Widget>[
AspectRatio(
aspectRatio: 0.001/0.001,
child: DrawerHeader(
decoration: BoxDecoration(
gradient: LinearGradient(colors: [Colors.white,Colors.blueAccent]
),
),
),
ListTile(
title: Text("General"),
onTap: (){
setState(() {
bodycontent = I_II_III_IV();
});
Navigator.pop(context);
},
),
],
),
),
),
);
and here is the usage on the form general:
Provider.of<General>(context).set(nombre.text,
"Apellido hay que quitar en la funcion",
edad.text,
_currentsexo,
estado_civil.text,
direccion.text,
emergencia.text,
procedencia.text,
telefono.text,
ocupacion.text,
referencia.text,
fecha_inicio.text,
"",userid);
this save well the information, I checked it in the debugger, but the problem is in the other side.
I tried using the multiprovider in the screen before the one with the drawer, but it throwed the same error but with "above generalform". notice that I removed the multiprovider from the screen with the drawer when I tried this.
so should I declare the multiprovider in every screen to use it into it's son? because I supposed that provider where variables that you could use in every screen after the one where it's declare, or am I missunderstanding something?... Every help is very appreciated, thanks before hand.
To get access to the Provider from every where in your app, you should declare it in the main:
void main() {
runApp(MultiProvider(
providers: [
ChangeNotifierProvider<General>(
create: (context) => General(),
),
],
child: MyApp(),
));
}

How can I put a SearchView on top of a ListView?

I'm new to flutter and am trying to stack a searchView on top of a ListView. I would Look something like this:
I don't know how to achieve this layout on flutter, i tried using a column(which crashes the app), used the a stack (which overlaps the widgets) and i finally tried to add a search widget a the first item of the ListView but that didn't result am looking for.
Widget build(BuildContext context) {
return new Scaffold(
drawer: _makeDrawer(),
appBar: new AppBar(
title: new Center(
child: new Text("translate"),
),
actions: <Widget>[
new IconButton(icon: new Icon(Icons.people_outline), onPressed: () {})
],
),
body: _phraseListFutureBuilder(), // this part of the code renders the listview
);
}
FutureBuilder _phraseListFutureBuilder() {
return new FutureBuilder(
builder: (BuildContext context, AsyncSnapshot snapshot) {
return mPhrases.isEmpty
? new CircularProgressIndicator()
: _buildPhrases();
},
future: _fetchData());
}
A Column was the right choice, but you will also need an Expanded widget to specify which widget should fill the remaining space:
Column(
crossAxisAlignment: CrossAxisAlignment.stretch,
children: <Widget>[
TextField(
decoration: InputDecoration(
labelText: 'Search'
),
),
Expanded(
child: _phraseListFutureBuilder(),
)
],
);