NestedScrollView widget in Flutter

 import "package:flutter/material.dart";

import "package:sdreatech_learning_widget/All_widgets_Ui/customWidget.dart";

void main() {
runApp(MyApp());
}

class MyApp extends StatelessWidget {
const MyApp({super.key});

@override
Widget build(BuildContext context) {
return MaterialApp(
title: "NestedScrollView",
debugShowCheckedModeBanner: false,
theme: ThemeData(
appBarTheme: const AppBarTheme(
backgroundColor: Colors.grey,
centerTitle: true,
),
),
home: const NestedScrollViewPractice(),
);
}
}

class NestedScrollViewPractice extends StatefulWidget {
const NestedScrollViewPractice({super.key});

@override
State<NestedScrollViewPractice> createState() =>
_NestedScrollViewPracticeState();
}

class _NestedScrollViewPracticeState extends State<NestedScrollViewPractice>
with SingleTickerProviderStateMixin {
late TabController _tabController;
late ScrollController _scrollViewController;

@override
void initState() {
super.initState();
_tabController = TabController(length: 2, vsync: this);
_scrollViewController = ScrollController(initialScrollOffset: 0.0);
}

@override
void dispose() {
super.dispose();
_tabController.dispose();
_scrollViewController.dispose();
}

@override
Widget build(BuildContext context) {
return Scaffold(
appBar: UiHelper.customAppBar("NestedScrollView"),
body: NestedScrollView(
controller: _scrollViewController,
headerSliverBuilder: (BuildContext context, bool boxIsScrolled) {
return <Widget>[
SliverAppBar(
title: const Text("Tab Controller Example"),
pinned: true,
floating: true,
forceElevated: boxIsScrolled,
bottom: TabBar(
tabs: const <Widget>[
Tab(
text: "Home",
icon: Icon(Icons.home),
),
Tab(
text: "Example Page",
icon: Icon(Icons.help),
),
],
controller: _tabController,
),
),
];
},
body: TabBarView(
controller: _tabController,
children: [
PageOne(),
PageTwo(),
],
),
),
floatingActionButton: FloatingActionButton(
onPressed: () {
_tabController.animateTo(
1,
curve: Curves.bounceInOut,
duration: const Duration(seconds: 2),
);

_scrollViewController
.jumpTo(_scrollViewController.position.maxScrollExtent);
},
child: const Icon(Icons.control_point),
),
);
}
}

class PageOne extends StatelessWidget {
const PageOne({super.key});

@override
Widget build(BuildContext context) {
return const Scaffold(
backgroundColor: Colors.brown,
body: Center(
child: Text(
"Tab 1 Content",
style: TextStyle(
fontWeight: FontWeight.bold, fontSize: 40.0, color: Colors.white),
),
),
);
}
}

class PageTwo extends StatelessWidget {
const PageTwo({super.key});

@override
Widget build(BuildContext context) {
return const Scaffold(
backgroundColor: Colors.brown,
body: Center(
child: Text(
"Tab 2 Content",
style: TextStyle(
fontWeight: FontWeight.bold, fontSize: 40.0, color: Colors.white),
),
),
);
}
}



Comments

Popular posts from this blog

Pagination with Bloc Pattern in Flutter

Pagination First Practical in Flutter

ExpansionPanel with ExpansionPanelList with Complete Collapse Operation in Flutter