Flutter: Using Expandable Textfield With Bottomnavigationbar
I need some help with this layout :) The Layout contains a BottomNavigationBar. The body consists of a Container at the top (which serves as some kind of header) and a Textfiel
Solution 1:
You just have some stuff misplaced. Try as much as you can to break apart your code into re-usable widgets. It helps to keep everything more organized.
Also, as a general rule, when you're trying to implement something commonly needed, chances are there will be a widget built for it already. In this case, you don't need to mess with the AnimatedCrossFade
etc... It's all built into the TabBarView
.
voidmain() => runApp(MyApp());
classMyAppextendsStatelessWidget {
// This widget is the root of your application.@override
Widget build(BuildContext context) {
return MaterialApp(
home: TabBarScaffold(),
);
}
}
classTabBarScaffoldextendsStatelessWidget {
@override
Widget build(BuildContext context) {
returnnewMaterialApp(
color: Colors.yellow,
home: DefaultTabController(
length: 3,
child: newScaffold(
body: MyPages(),
bottomNavigationBar: MyTabs(),
),
),
);
}
}
classMyTabsextendsStatelessWidget {
@override
Widget build(BuildContext context) {
return TabBar(
tabs: [
Tab(
child: Text("Tab 1"),
),
Tab(
child: Text("Tab 2"),
),
Tab(
child: Text("Tab 3"),
),
],
labelColor: Colors.blue,
unselectedLabelColor: Colors.black,
indicatorSize: TabBarIndicatorSize.label,
indicatorPadding: EdgeInsets.all(5.0),
indicatorColor: Colors.red,
);
}
}
classMyPagesextendsStatelessWidget {
@override
Widget build(BuildContext context) {
return TabBarView(
children: [
MyPageBody(
textBackgroundColor: Colors.blue[200],
),
MyPageBody(
textBackgroundColor: Colors.green[200],
),
MyPageBody(
textBackgroundColor: Colors.red[200],
),
],
);
}
}
classMyPageBodyextendsStatelessWidget {
final Color textBackgroundColor;
MyPageBody({this.textBackgroundColor});
@override
Widget build(BuildContext context) {
return LayoutBuilder(
builder: (context, constraint) {
return SingleChildScrollView(
child: ConstrainedBox(
constraints: BoxConstraints(minHeight: constraint.maxHeight),
child: IntrinsicHeight(
child: Column(
children: <Widget>[
Container(
height: 100,
alignment: Alignment.center,
color: Colors.green,
child: Text("Header"),
),
Expanded(
child: TextField(
expands: true,
maxLines: null,
decoration: InputDecoration(
fillColor: textBackgroundColor, filled: true),
),
),
],
),
),
),
);
},
);
}
}
Post a Comment for "Flutter: Using Expandable Textfield With Bottomnavigationbar"