Multiple tab views per page? - flutter

I have a container with two columns. When you click on the OPTIONS button, the screen animates half a width to the left and shows additional (clickable!) options.
I'm currently doing this with a Row containing two containers where the second container lives in a Stack that overlays a translated-to-the-right container with the options. Something along those lines:
Row(
children: <Widget>[
Expanded(
child: Container(
color: Colors.blue,
),
),
Expanded(
child: Container(
child: Stack(
children: <Widget>[
Container(
color: Colors.orange
),
Transform.translate(
offset: const Offset(170.0, 0.0),
child: Container(
color: Colors.green,
child: Column(
children: const <Widget>[
FlatButton(child: Text("Option 1")),
FlatButton(child: Text("Option 2")),
FlatButton(child: Text("Option 3")),
],
),
),
),
],
),
),
)
],
);
Now, since the green container is outside its parent stack, the option buttons won't get any gesture events and hence not work. There is a similar question here and even a GitHub issue. What neither provides is a solution.
Is there way to make gestures outside the stack work, and if not, what are my options for this use case? In a way what I'm trying to achieve is similar to a tab view but with two tab views displayed at the same time.

Related

How to make split buttons

I'm trying to make a similar UI. Tell me how you can implement split custom buttons as shown on the screen. I'm more interested in how to make a custom form for buttons. As you can see, it blends into the background of the container.
I understand that ordinary containers can not do here. We need something more custom.
I am considering using ordinary containers, but here it should be noted that something is more custom. It is possible to look towards CustomPainter??
Here is an example how you can use flex in a row to have two seperate buttons next to each other. Hope this is what you are looking for.
Row(
children: <Widget> [
Expanded(
// with the flex you give the width
flex: 9,
child: Align(
alignment: Alignment.center,
child: ElevatedButton(
child: const Text('Configuration'),
onPressed: () {
},
//styling button
style: ElevatedButton.styleFrom(
),
),
)
),
Expanded(
// with the flex you give the width
flex: 9,
child: Align(
alignment: Alignment.center,
child: ElevatedButton(
child: const Text('Rack 3'),
onPressed: () {
},
// styling button
style: ElevatedButton.styleFrom(
),
),
)
)
]
),

How to make a horizontal bar in flutter

I am trying to create a horizontal bar that grows in colour strength given the numbers supplied to it in a flutter app. Does anyone have an idea?
You can use row with Expanded and Text
Row(
mainAxisAlignment: MainAxisAlignment.spaceBetween,
children: [
Expanded(
child: Padding(
padding: const EdgeInsets.all(8.0),
child: SizedBox(
height: 10,
child: LinearProgressIndicator(
value: 200 / 425, //current / max
backgroundColor: Colors.blue.shade100,
color: Colors.blue,
),
),
),
),
Text("value")
],
),
Also you can use stack().
First make bar then on the top put Text() or what ever you want

How to create a tabbar with icon and text in same row in flutter?

I am trying to create a tab bar which contains icon and text in the same row in tab.
I have tried below code to implement the same , due to which the icon and text are shown in column manner in tab.
bottom: TabBar(
tabs: [
Tab(icon: new Image.asset("assets/images/ic_policy#2x.png",width: 18,height: 18), child: Text("Policies")
),
Tab(
child: Container(
child: Align(
alignment: Alignment.center,
child: Text("Policy Payments")),
),
)
Can anyone guide me how to achieve the same.
My tabbar currently looks as below.
I want to design something like below :-
why don't you define tabs like this?
Tab(
child: Row(
mainAxisSize: MainAxisSize.min,
children: [
Image.asset('assets/images/ic_policy#2x.png', width: 18, height: 18),
const SizedBox(width: 8),
Text('Policies'),
],
),
),

Flutter TextFormField hide when keyboard appears

I'm new on flutter and i have a problem.
When i click on the textformField, this one disappears
I put in red the container but normaly it's transparent
I put a stack, then in the background the GoogleMap which is extend. And to have a research effect I put an overlay with the textformfield and I will have specific filter buttons instead of the yellow and green.
The problem is that when I click on the textformfield, it disappears from the screen.
I tried to play with the SingleChildScrollView, ListView, but I still have errors especially because of GoogleMap which takes up all the space
Everything is contained by a Scaffold
Can you help me please, where to give me a solution?
I enclose the code below
cordially
return Stack(
children: [
/// GoogleMap
Column(
children: [
Expanded(
child: GoogleMap(initialCameraPosition: _kInitialPosition),
),
],
),
/// Search Bar And Filter
Positioned.fill(
bottom: _searchBarContainer,
child: SafeArea(
child: Container(
color: Colors.red,
child: Padding(
padding: const EdgeInsets.only(left: 8.0, right: 8.0),
child: Row(
children: [
/// Search Bar
Expanded(
child: TextFormField(
decoration: DesignWidget.inputDecorationTexFieldMap(
_searchBarMap, Icons.search),
),
),
/// Filter
Container(
width: _filterContainer,
color: Colors.green,
child: Row(
children: [
Container(
color: Colors.yellow,
width: _filterContainer / 2,
),
Container(
color: Colors.green,
width: _filterContainer / 2,
)
],
),
),
],
),
),
),
),
),
],
);
simply user this pakage [material_floating_search_bar: ^0.3.4]
I think before you use textFormField you either have to define a key or controller.....it happens when you don't define an instance of controller and use that controller inside of textFormField controller.
Okay i found the solution
I need to add (to Scallfold) : resizeToAvoidBottomInset: false

Flutter - FlatButton Fill available horizontal space

I'm trying to have a UI in such a way that the number of buttons in a row changes depending on available information. More specifically, there will always be one FlatButton that links to an external page, but if a download link is also provided, then there will be a second FlatButton in the row.
On the website that currently exists, we have this working for one button versus two buttons, but I can't get the one button to horizontally expand to fill the available space.
At the moment, I add the FlatButtons to a List<Widget> variable that I pass as the children for a row. I have tried using Flex -> Expanded, SizedBox.expand, CrossAxisAlignment.stretch and every solution I have found on this site so far to get it to expand, but every solution I have tried have all resulted in forced infinite width or unbounded width or non-zero flex but incoming width constraints are unbounded.
Here's my code in the build method as it currently stands:
List<Widget> fullTextDownloadBtns = new List();
if (this.fullArticleUrl != null && this.fullArticleUrl.isNotEmpty) {
fullTextDownloadBtns.add(
FlatButton(
color: Color(0x66629c44),
onPressed: _openFullArticle,
child: Text(
"Full Article",
style: TextStyle(color: Color(0xff629c44)),
),
)
);
}
if (this.downloadUrl != null && this.downloadUrl.isNotEmpty) {
fullTextDownloadBtns.add(
FlatButton(
color: Color(0x664d69b1),
onPressed: _download,
child: Text(
"Download",
style: TextStyle(color: Color(0xff4d69b1)),
),
)
);
}
return Scaffold(
appBar: AppBar(
backgroundColor: Color(0xff0096b0)
),
body: SingleChildScrollView(
scrollDirection: Axis.vertical,
child: Column(
crossAxisAlignment: CrossAxisAlignment.stretch,
children: [
// ...related image, title
Container(
padding: EdgeInsets.all(15.0),
child: Row(
mainAxisAlignment: MainAxisAlignment.spaceEvenly,
children: fullTextDownloadBtns,
),
), // Read full article & download PDF
// ... Authors, excerpt/description, like/share buttons, comments
],
)
),
);
Wrapping your buttons with Expanded is the way to go here (I tried it with your code) :
Row(
children: [
Expanded(
child: FlatButton(onPressed: (){},
child: Text("1")),
),
Expanded(
child: FlatButton(onPressed: (){},
child: Text("2")),
)
],
),
By the way, since the SDK 2.2.2 (in your pubspec.yaml), you can use conditions within the children list :
children: [
if(true == true)
FlatButton(
onPressed: (){},
child: Text("1")),
],
I just wanted to add that you can adjust the width of the buttons border by using the 'width' property inside 'side: BorderSide(color: Colors.black54, width: 2.2)'.
Row(
children: <Widget>[
Expanded(
child: FlatButton(
onPressed: () {},
shape: RoundedRectangleBorder(
borderRadius: BorderRadius.circular(5.0),
side: BorderSide(color: Colors.black54, width: 2.2),
),
color: Colors.white,
child: (Text('BUTTON NAME')),
),
),
],
),
Couldn't find how to change the border outline width for a long while on here. So thought I might add it here. Maybe help some other noobie like me in the future.
You can use a Row widget and use two Expanded widget which their child are FlatButton.implement the condition fot them seperately sth like:
Row(
children:[
trueCondition ? Expanded(
child: FlatButton()
) : SizedBox()
]
)