Related
I am trying to navigate the section on the same page when the button is clicked but I can not do it using PageView and Scroll, Does anyone know how to do it?
This is the navigation bar on the top of the page and I want it to go to specific section on the same page when the button is clicked.
this is my code:
Row(
children: [
NavItem(
title: 'Home',
onPreesed: () {},
color: KprimaryColor,
fontWeight: FontWeight.w900,
),
NavItem(
title: 'About',
onPreesed: () {},
color: Colors.black,
fontWeight: FontWeight.normal,
),
NavItem(
title: 'Projects',
onPreesed: () {},
color: Colors.black,
fontWeight: FontWeight.normal,
),
NavItem(
title: 'Contact',
onPreesed: () {},
color: Colors.black,
fontWeight: FontWeight.normal,
),
Please, try this!
class MyAppTabView extends StatelessWidget {
#override
Widget build(BuildContext context) {
return MaterialApp(
home: DefaultTabController(
length: 4,
child: Scaffold(
appBar: AppBar(
backgroundColor: Colors.white,
title: Text('Flutter Tabs', style: TextStyle(color: Colors.black)),
bottom: const PreferredSize(
preferredSize: Size.fromHeight(40),
child: Align(
alignment: Alignment.centerRight,
child: TabBar(
isScrollable: true,
unselectedLabelStyle: TextStyle(fontWeight: FontWeight.normal),
unselectedLabelColor: Colors.black,
indicatorSize: TabBarIndicatorSize.label,
indicatorColor: Colors.transparent,
labelColor: Colors.red,
labelStyle: TextStyle(fontWeight: FontWeight.bold),
tabs: [
Tab(
child: Padding(
padding: EdgeInsets.symmetric(horizontal: 20),
child: Center(
child: Text("Home"),
),
),
),
Tab(
child: Padding(
padding: EdgeInsets.symmetric(horizontal: 20),
child: Center(
child: Text("About"),
),
),
),
Tab(
child: Padding(
padding: EdgeInsets.symmetric(horizontal: 20),
child: Center(
child: Text("Projects"),
),
),
),
Tab(
child: Padding(
padding: EdgeInsets.symmetric(horizontal: 20),
child: Center(
child: Text("Contact"),
),
),
),
]),
),
),
),
body: TabBarView(
children: [
Center(child: Text("Home")),
Center(child: Text("About")),
Center(child: Text("Projects")),
Center(child: Text("Contact")),
],
),
),
),
);
}
}
Enjoy Coding!!
I have a sliver app bar with the background of the same color as the color or the contents that are scrolled under it, therefore making the appbar blend with the contents. Is there any way I can completely hide the contents that are beneath the SliverAppBar?
So as you can see below, the background color of the main app bar is the same as the background color of what follows(the contents).
CustomScrollView(
controller: controller,
slivers: [
// This should be the main app bar where the contents have to be behind it
SliverAppBar(
toolbarHeight: 36,
centerTitle: true,
title: showChatTitle
? const Text(
'Chats',
style: TextStyle(fontSize: 13, color: Colors.black),
)
: null,
pinned: true,
floating: true,
elevation: 0,
backgroundColor: Colors.grey.withOpacity(0.002),
leading: Container(
margin: const EdgeInsets.only(left: 14, top: 10),
child: const Text(
'Edit',
style: TextStyle(color: Colors.blue, fontSize: 12.5),
),
),
actions: [
IconButton(
onPressed: () {},
icon: const Icon(
Icons.edit_calendar,
color: Colors.blueAccent,
),
),
]),
//--------------------------------------------------------------------
// Contents follows now
SliverAppBar(
toolbarHeight: 45,
elevation: 0,
pinned: pinChatText,
foregroundColor: Colors.black,
backgroundColor: Colors.grey.withOpacity(0.002),
title: const Text(
'Chats',
style: TextStyle(
fontSize: 25,
fontWeight: FontWeight.bold,
color: Colors.black,
),
),
),
SliverPadding(
padding: const EdgeInsets.symmetric(horizontal: 10),
sliver: SliverAppBar(
toolbarHeight: searchBarHeight,
floating: false,
shape: RoundedRectangleBorder(
borderRadius: BorderRadius.circular(5),
),
foregroundColor: Colors.black,
backgroundColor: Colors.grey.withOpacity(0.2),
title: Text.rich(
TextSpan(
style: TextStyle(
fontSize: 15,
color: Colors.grey.withOpacity(textColorOpacity),
),
children: [
WidgetSpan(
child: Icon(
Icons.search,
color: Colors.grey.withOpacity(textColorOpacity),
size: 17,
),
),
const TextSpan(
text: ' Search',
)
],
),
)),
),
SliverList(
delegate: SliverChildListDelegate(
[
Padding(
padding: const EdgeInsets.only(left: 8.0, right: 8, top: 15),
child: Row(children: const [
Text(
'Broadcast Lists',
style: TextStyle(
color: Colors.blueAccent,
),
),
Spacer(),
Text(
'New Group',
style: TextStyle(
color: Colors.blueAccent,
),
)
]),
),
ListView.builder(
shrinkWrap: true,
itemCount: 20,
itemBuilder: (context, index) => Column(
children: const [
ChatItem(),
Divider(
indent: 50,
thickness: 0.4,
)
],
),
),
],
))
],
);
You can try it with code:
NestedScrollView(
controller: _scrollController,
headerSliverBuilder: (BuildContext context, bool innerBoxIsScrolled) {
return <Widget>[
SliverAppBar(
expandedHeight: 200.0,
floating: false,
pinned: true,
backgroundColor: Colors.red,
flexibleSpace: FlexibleSpaceBar(
centerTitle: true,
title: Text("text sample",
style: TextStyle(
color: isShrink ? Colors.black : Colors.white,
fontSize: 16.0,
)),
background: CachedNetworkImage(
imageUrl:
'http://preprod.tibib-live.com/medias/cached-media/medium/5bea5964109aa-c827b05facc3781485e584dac2f4dddc.png',
fit: BoxFit.cover,
)),
),
];
},
body: Center(
child: Text("hello world"),
),
);
Okay so I had to use Colors.grey.shade50 instead of Colors.grey.withOpacity(0.003)
Check code below
CustomScrollView(
controller: controller,
slivers: [
// This should be the main app bar where the contents have to be behind it
SliverAppBar(
toolbarHeight: 36,
centerTitle: true,
title: showChatTitle
? const Text(
'Chats',
style: TextStyle(fontSize: 13, color: Colors.black),
)
: null,
pinned: true,
floating: true,
elevation: 0,
backgroundColor: Colors.grey.shade50, // Used shade here
leading: Container(
margin: const EdgeInsets.only(left: 14, top: 10),
child: const Text(
'Edit',
style: TextStyle(color: Colors.blue, fontSize: 12.5),
),
),
actions: [
IconButton(
onPressed: () {},
icon: const Icon(
Icons.edit_calendar,
color: Colors.blueAccent,
),
),
]),
//--------------------------------------------------------------------
// Contents follows now
SliverAppBar(
toolbarHeight: 45,
elevation: 0,
pinned: pinChatText,
foregroundColor: Colors.black,
backgroundColor: Colors.grey.withOpacity(0.002),
title: const Text(
'Chats',
style: TextStyle(
fontSize: 25,
fontWeight: FontWeight.bold,
color: Colors.black,
),
),
),
SliverPadding(
padding: const EdgeInsets.symmetric(horizontal: 10),
sliver: SliverAppBar(
toolbarHeight: searchBarHeight,
floating: false,
shape: RoundedRectangleBorder(
borderRadius: BorderRadius.circular(5),
),
foregroundColor: Colors.black,
backgroundColor: Colors.grey.withOpacity(0.2),
title: Text.rich(
TextSpan(
style: TextStyle(
fontSize: 15,
color: Colors.grey.withOpacity(textColorOpacity),
),
children: [
WidgetSpan(
child: Icon(
Icons.search,
color: Colors.grey.withOpacity(textColorOpacity),
size: 17,
),
),
const TextSpan(
text: ' Search',
)
],
),
)),
),
SliverList(
delegate: SliverChildListDelegate(
[
Padding(
padding: const EdgeInsets.only(left: 8.0, right: 8, top: 15),
child: Row(children: const [
Text(
'Broadcast Lists',
style: TextStyle(
color: Colors.blueAccent,
),
),
Spacer(),
Text(
'New Group',
style: TextStyle(
color: Colors.blueAccent,
),
)
]),
),
ListView.builder(
shrinkWrap: true,
itemCount: 20,
itemBuilder: (context, index) => Column(
children: const [
ChatItem(),
Divider(
indent: 50,
thickness: 0.4,
)
],
),
),
],
))
],
);
I'm trying to add TabBar in my Flutter application. I will use 5 tabs with long names. For now, I added them like this;
DefaultTabController(
length: 5, // length of tabs
initialIndex: 0,
child: Column(crossAxisAlignment: CrossAxisAlignment.stretch, children: <Widget>[
Container(
child: TabBar(
labelColor: Color(0xffd17842),
unselectedLabelColor: Color(0xff52555a),
indicator: DotIndicator(
color: Color(0xffd17842),
distanceFromCenter: 16,
radius: 3,
paintingStyle: PaintingStyle.fill,
),
indicatorColor: Colors.transparent,
tabs: [
Tab(text: 'Cappuccino'),
Tab(text: 'Espresso'),
Tab(text: 'Latte'),
Tab(text: 'Espresso'),
Tab(text: 'Cappuccino'),
],
),
),
Container(
height: 250, //height of TabBarView
decoration: BoxDecoration(
border: Border(top: BorderSide(color: Colors.grey, width: 0.5))
),
child: TabBarView(children: <Widget>[
Container(
child: Center(
child: Text('Display Tab 1', style: TextStyle(fontSize: 22, fontWeight: FontWeight.bold)),
),
),
Container(
child: Center(
child: Text('Display Tab 2', style: TextStyle(fontSize: 22, fontWeight: FontWeight.bold)),
),
),
Container(
child: Center(
child: Text('Display Tab 3', style: TextStyle(fontSize: 22, fontWeight: FontWeight.bold)),
),
),
Container(
child: Center(
child: Text('Display Tab 4', style: TextStyle(fontSize: 22, fontWeight: FontWeight.bold)),
),
),
Container(
child: Center(
child: Text('Display Tab 5', style: TextStyle(fontSize: 22, fontWeight: FontWeight.bold)),
),
),
])
)
])
)
But the output is this;
I want it to act like Horizontal SingleChildScrollView with BouncingScrollPhysics with full long names. I can't fix it... Can you help me?
On your TabBar set isScrollable: true,
child: TabBar(
labelColor: Color(0xffd17842),
unselectedLabelColor: Color(0xff52555a),
indicatorColor: Colors.transparent,
isScrollable: true, // this
tabs: [
set isScrollable property to true
isScrollable: true
I solved the problem by reducing the space between tabs.
enter image description here
I wanted to aling a button to the bottom center of the listview.
Scaffold(
backgroundColor: Colors.white,
appBar: buildAppBar(context, ''),
body: ListView(
physics: ClampingScrollPhysics(),
children: [
Column(
children: [
Text(
'check up',
style: TextStyle(
fontSize: 35,
fontWeight: FontWeight.bold,
color: Colors.black,
),
),
SizedBox(height: 12),
Text(
'SachsenwaldStr. 3. 12157 Berlin',
style: TextStyle(
fontSize: 20,
color: Colors.black,
),
),
],
),
Spacer(),
buildNextButton(context),
],
),
I tried using Align, but it didn't work, and Spacer() didn't too:
Align(
alignment: Alignment.bottomCenter,
child: buildNextButton(context),
),
is there any way to align buildNextButton to the bottom?
return Scaffold(
body: Stack(
children: [
Positioned(
bottom: 0,
width: MediaQuery.of(context).size.width,
child: Center(
child: MaterialButton(
child: Text("My button"),
onPressed: () {},
color: Colors.red,
),
),
),
ListView(
children: [
Text(
'check up',
style: TextStyle(
fontSize: 35,
fontWeight: FontWeight.bold,
color: Colors.black,
),
),
SizedBox(height: 12),
Text(
'SachsenwaldStr. 3. 12157 Berlin',
style: TextStyle(
fontSize: 20,
color: Colors.black,
),
),
],
)
],
));
You can use Scaffold Properties to make a button centre at the bottom. Hope it would be helpful for you,Thanks
import 'package:flutter/material.dart';
class BottomButton extends StatefulWidget {
const BottomButton({Key? key}) : super(key: key);
#override
_BottomButtonState createState() => _BottomButtonState();
}
class _BottomButtonState extends State<BottomButton> {
#override
Widget build(BuildContext context) {
return Scaffold(
///you can make the centre button use floating action Button and
provide its location
floatingActionButton: FloatingActionButton(
backgroundColor: Colors.transparent,
child: Container(
width: MediaQuery.of(context).size.width,
color: Colors.green,
child: Text(
"Button")),
onPressed: () {},
),
floatingActionButtonLocation: FloatingActionButtonLocation.centerDocked,
appBar: AppBar(
title: Text("MyAppBar"),
),
body: ListView(
physics: ClampingScrollPhysics(),
children: [
Column(
children: [
Text(
'check up',
style: TextStyle(
fontSize: 35,
fontWeight: FontWeight.bold,
color: Colors.black,
),
),
SizedBox(height: 12),
Text(
'SachsenwaldStr. 3. 12157 Berlin',
style: TextStyle(
fontSize: 20,
color: Colors.black,
),
),
],
),
],
),
///bottom sheet place button at bottom without using space
bottomSheet: Container(
width: MediaQuery.of(context).size.width,
color: Colors.green,
child: TextButton(onPressed: () {}, child: Text("Button"))),
);
}
}
You can wrap your Align widget with Expanded and in Align widget use alignment: FractionalOffset.bottomCenter .
Please find below link to get more clear idea - Button at bottom
I suggest to wrap ListView and builtNextButton with Stack Widget.
Because when ListView children is bigger than screen height, button can not be located bottom.
import 'package:flutter/material.dart';
const Color darkBlue = Color.fromARGB(255, 18, 32, 47);
void main() {
runApp(MyApp());
}
class MyApp extends StatelessWidget {
Widget buildNextButton(context) {
return Container(height: 40, color: Colors.green);
}
#override
Widget build(BuildContext context) {
return MaterialApp(
theme: ThemeData.dark().copyWith(
scaffoldBackgroundColor: darkBlue,
),
debugShowCheckedModeBanner: false,
home: Scaffold(
backgroundColor: Colors.white,
//appBar: buildAppBar(context, ''),
body: Stack(
children: [
ListView(
physics: const ClampingScrollPhysics(),
children: [
Column(
children: [
Text(
'check up',
style: TextStyle(
fontSize: 35,
fontWeight: FontWeight.bold,
color: Colors.black,
),
),
SizedBox(height: 12),
Text(
'SachsenwaldStr. 3. 12157 Berlin',
style: TextStyle(
fontSize: 20,
color: Colors.black,
),
),
],
),
],
),
Align(
alignment: Alignment.bottomCenter,
child: buildNextButton(context),
),
],
),
),
);
}
}
Now the only way you can use it in a list view is if you are to pas it in a column widget, so the order would become, column -> Expanded -> ListView andoutside the expanded, that is where you now pass the button. Just copy and paste my code here, Hopefully it works for you.
Scaffold(
body: Column(
children: [
Expanded(
child: ListView(
// physics: ClampingScrollPhysics(),
children: [
Column(
children: [
Text(
'check up',
style: TextStyle(
fontSize: 35,
fontWeight: FontWeight.bold,
color: Colors.black,
),
),
SizedBox(height: 12),
Text(
'SachsenwaldStr. 3. 12157 Berlin',
style: TextStyle(
fontSize: 20,
color: Colors.black,
),
),
],
),
// buildNextButton(context),
],
),
),
Container(
child: Center(
child: buildNextButton()
),
)
],
),
)
and then the buildNextButton code is
buildNextButton() {
return ElevatedButton(
style: ElevatedButton.styleFrom(textStyle: const TextStyle(fontSize: 20))
,
onPressed: () {},
child: const Text('Enabled'),
);
}
the moment you render a listview as aparent widget, automatically it renders all items in alist, one after the other.
anyquestions, am available to help you out
Good luck bro
I have a problem this that in my android device cwctv page is working but in IOS Device giving height error,so how to set height for every device.
I have a problem this that in my android device cwctv page is working but in IOS Device giving height error,so how to set height for every device.
I have a problem this that in my android device cwctv page is working but in IOS Device giving height error,so how to set height for every device.
this is my cwctv page.
#override
Widget build(BuildContext context) {
return Scaffold(backgroundColor: Colors.white,
resizeToAvoidBottomInset: false,
appBar: AppBar(
iconTheme: IconThemeData(color: Colors.black),
automaticallyImplyLeading: true,
backgroundColor: Colors.white,
elevation: 0.5, ),
drawer: Drawer(
child: SideBar(),
),
floatingActionButton: Padding(
padding: const EdgeInsets.only(top: 18.0),
child: Container(
height: 80,
width: 80,
child: FittedBox(
child: FloatingActionButton(
focusColor: Colors.transparent,
backgroundColor: selectBlueColor,
onPressed: () {
Navigator.pushReplacement(context,
MaterialPageRoute(builder: (context) => HomePage()));
},
materialTapTargetSize: MaterialTapTargetSize.shrinkWrap,
child: Image.asset(
'assets/home_icon.png',
),
elevation: 1.0,
highlightElevation: 2,
),
),
),
),
floatingActionButtonLocation: FloatingActionButtonLocation.centerDocked,
bottomNavigationBar: Container(
// height: MediaQuery.of(context).size.height * (10 / 100),
child: BottomNavBarTV()),
body: Stack(
children: [
Padding(
padding: const EdgeInsets.only(left: 16.0,right: 16,bottom: 4,top: 0),
child: SizedBox(
height: 60,
child: TextField( keyboardType: TextInputType.text,
onChanged: (value) {
setState(() {
print("tab on cwctv page $cwcTvTab");
});
},
// controller: cwcTvTab == 3 ?searchImageQuery : cwcTvTab == 2 ?searchPdfQuery : cwcTvTab == 1 ? searchAudioQuery : searchVideoQuery,
controller: searchQuery,
decoration: InputDecoration(
border: OutlineInputBorder(
borderRadius: BorderRadius.circular(10.0),
borderSide: BorderSide.none,
),
filled: true,
fillColor: const Color(0xFFF1F2F6),
hintText: 'Search for Wellness Tips & Tricks',
suffixIcon: const Icon(
Icons.search_outlined,
color: Color(0xFF444444),
),
),
)
)),
Padding(
padding: EdgeInsets.only(top: 70.0),
child: TestScreen(widget.selectTab),
),
// CwcTVPageChanger(),
// VideoComponent(),
],
),
);
}
This is my tab screen page.
import 'package:cwc/constants/constants.dart';
import 'package:cwc/ui/CwcTv/components/images/image_document.dart';
import 'package:cwc/ui/CwcTv/components/podcast/podcast_list.dart';
import 'package:cwc/ui/CwcTv/components/slides/slide_component.dart';
import 'package:cwc/ui/CwcTv/components/videos/video_component.dart';
import 'package:cwc/ui/CwcTv/cwc_tv.dart';
import 'package:flutter/material.dart';
import 'package:google_fonts/google_fonts.dart';
import 'package:cwc/constants/constant_functions.dart';
class TestScreen extends StatefulWidget {
int selectedPage;
TestScreen(this.selectedPage);
#override
State<TestScreen> createState() => _TestScreenState();
}
class _TestScreenState extends State<TestScreen> with SingleTickerProviderStateMixin, WidgetsBindingObserver {
void _handleTabSelection() {
setState(() {});
}
#override
Widget build(BuildContext context) {
return Column(
children: <Widget>[
// _tabSection(context, widget.selectedPage,controller!),
_tabSection(context, widget.selectedPage),
],
);
}
}
Widget _tabSection(BuildContext context, var selectedPage) {
return DefaultTabController(
initialIndex: selectedPage,
length: 4,
child: SafeArea(
child: Column(
// mainAxisSize: MainAxisSize.min,
children: [
TabBar(
indicatorColor: Colors.black,
onTap: (v) {
cwcTvTab = v;
},
isScrollable: true,
// physics: NeverScrollableScrollPhysics(),
labelColor: Colors.black,
tabs: [
Tab(
child: Text(
'Video',
style: GoogleFonts.poppins(color: Colors.black),
),
),
Tab(
child: Text(
'Podcast',
style: GoogleFonts.poppins(color: Colors.black),
),
),
Tab(
child: Text(
'Documents',
style: GoogleFonts.poppins(
color: Colors.black,
),
),
),
Tab(
child: Text(
'Images',
style: GoogleFonts.poppins(color: Colors.black),
),
),
],
),
Container(
height: MediaQuery.of(context).size.height - 282,
// height: MediaQuery.of(context).size.height - 205,
// height: double.infinity,
child:
TabBarView( physics: NeverScrollableScrollPhysics(),
children: [
VideoComponent(),
PodcastList(),
SlideComponent(),
ImageDocument(),
]),
),
],
),
),
);
}
this is my android Device's screenshot.
this is my IOS Device's screenshot.
There is 2 options you can use, first try with indicator like this one:
TabBar(
indicator: UnderlineTabIndicator(
borderSide: BorderSide(width: 5.0),
insets: EdgeInsets.symmetric(horizontal:16.0)
),
indicatorColor: Colors.black,
onTap: (v) {
cwcTvTab = v;
},
isScrollable: true,
// physics: NeverScrollableScrollPhysics(),
labelColor: Colors.black,
tabs: [
Tab(
child: Text(
'Video',
style: GoogleFonts.poppins(color: Colors.black),
),
),
Tab(
child: Text(
'Podcast',
style: GoogleFonts.poppins(color: Colors.black),
),
),
Tab(
child: Text(
'Documents',
style: GoogleFonts.poppins(
color: Colors.black,
),
),
),
Tab(
child: Text(
'Images',
style: GoogleFonts.poppins(color: Colors.black),
),
),
],
),
Or you can just wrap it with a container.
PreferredSize(
preferredSize: const Size.fromHeight(10),
child: Container(
height: 50,
child: TabBar(
indicatorColor: Colors.black,
isScrollable: true,
labelColor: Colors.black,
tabs: [
Tab(
child: Text(
'Video',
),
),
Tab(
child: Text(
'Podcast',
),
),
Tab(
child: Text(
'Documents',
),
),
Tab(
child: Text(
'Images',
),
),
],
),
),
),