feat: add app bar with dynamic header

welcome
98spag 2023-04-19 19:56:35 +02:00
parent 78c2415391
commit 345a9e0d4e
3 changed files with 19 additions and 21 deletions

6
.gitignore vendored
View File

@ -7,6 +7,7 @@
# Icon must end with two \r # Icon must end with two \r
Icon Icon
# Thumbnails # Thumbnails
._* ._*
@ -491,6 +492,11 @@ __pycache__/
# Tabs Studio # Tabs Studio
*.tss *.tss
#Dart Tools
package_config.json
package_config_subset
version
# Telerik's JustMock configuration file # Telerik's JustMock configuration file
*.jmconfig *.jmconfig

View File

@ -1,10 +1,8 @@
import 'package:flutter/material.dart'; import 'package:flutter/material.dart';
class CardComponent extends StatelessWidget { class CardComponent extends StatelessWidget {
final String title;
final String description;
const CardComponent({super.key, required this.title, required this.description}); const CardComponent({super.key});
@override @override
Widget build(BuildContext context) { Widget build(BuildContext context) {
@ -16,11 +14,6 @@ class CardComponent extends StatelessWidget {
padding: const EdgeInsets.all(16.0), padding: const EdgeInsets.all(16.0),
child: Column( child: Column(
crossAxisAlignment: CrossAxisAlignment.start, crossAxisAlignment: CrossAxisAlignment.start,
children: <Widget>[
Text(title, style: const TextStyle(fontSize: 24.0)),
const SizedBox(height: 8.0),
Text(description, style: const TextStyle(fontSize: 16.0)),
],
), ),
), ),
), ),

View File

@ -11,11 +11,15 @@ class NavigationScreen extends StatefulWidget {
class NavigationScreenState extends State<NavigationScreen> { class NavigationScreenState extends State<NavigationScreen> {
int _selectedIndex = 0; int _selectedIndex = 0;
final _pages = ["Page 1", "Page 2", "Page 3"];
String _selectedPage = "Page 1";
final PageController _pageController = PageController(initialPage: 0); final PageController _pageController = PageController(initialPage: 0);
void _onItemTapped(int index) { void _onItemTapped(int index) {
setState(() { setState(() {
_selectedIndex = index; _selectedIndex = index;
_selectedPage = _pages[index];
_pageController.animateToPage(index, _pageController.animateToPage(index,
duration: const Duration(milliseconds: 300), curve: Curves.easeInOut); duration: const Duration(milliseconds: 300), curve: Curves.easeInOut);
}); });
@ -24,11 +28,15 @@ class NavigationScreenState extends State<NavigationScreen> {
@override @override
Widget build(BuildContext context) { Widget build(BuildContext context) {
return Scaffold( return Scaffold(
appBar: AppBar(
title: Text(_selectedPage),
),
body: PageView( body: PageView(
controller: _pageController, controller: _pageController,
children: _widgetOptions, children: _widgetOptions,
onPageChanged: (int index) { onPageChanged: (int index) {
setState(() { setState(() {
_selectedPage = _pages[index];
_selectedIndex = index; _selectedIndex = index;
}); });
}, },
@ -57,30 +65,21 @@ class NavigationScreenState extends State<NavigationScreen> {
static final List<Widget> _widgetOptions = <Widget>[ static final List<Widget> _widgetOptions = <Widget>[
Swiper( Swiper(
itemBuilder: (BuildContext context, int index) { itemBuilder: (BuildContext context, int index) {
return const CardComponent( return const CardComponent();
title: 'Page 1',
description: 'This is page 1',
);
}, },
itemCount: 1, itemCount: 1,
loop: false, loop: false,
), ),
Swiper( Swiper(
itemBuilder: (BuildContext context, int index) { itemBuilder: (BuildContext context, int index) {
return const CardComponent( return const CardComponent();
title: 'Page 2',
description: 'This is page 2',
);
}, },
itemCount: 1, itemCount: 1,
loop: false, loop: false,
), ),
Swiper( Swiper(
itemBuilder: (BuildContext context, int index) { itemBuilder: (BuildContext context, int index) {
return const CardComponent( return const CardComponent();
title: 'Page 3',
description: 'This is page 3',
);
}, },
itemCount: 1, itemCount: 1,
loop: false, loop: false,