mirror of https://github.com/flutter/samples.git
You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
72 lines
1.7 KiB
72 lines
1.7 KiB
// Copyright 2021, the Flutter project authors. Please see the AUTHORS file
|
|
// for details. All rights reserved. Use of this source code is governed by a
|
|
// BSD-style license that can be found in the LICENSE file.
|
|
|
|
import 'package:flutter/material.dart';
|
|
|
|
class BooksScreen extends StatefulWidget {
|
|
final Widget child;
|
|
final ValueChanged<int> onTap;
|
|
final int selectedIndex;
|
|
|
|
const BooksScreen({
|
|
required this.child,
|
|
required this.onTap,
|
|
required this.selectedIndex,
|
|
super.key,
|
|
});
|
|
|
|
@override
|
|
State<BooksScreen> createState() => _BooksScreenState();
|
|
}
|
|
|
|
class _BooksScreenState extends State<BooksScreen>
|
|
with SingleTickerProviderStateMixin {
|
|
late TabController _tabController;
|
|
|
|
@override
|
|
void initState() {
|
|
super.initState();
|
|
_tabController = TabController(length: 3, vsync: this)
|
|
..addListener(_handleTabIndexChanged);
|
|
}
|
|
|
|
@override
|
|
void dispose() {
|
|
_tabController.removeListener(_handleTabIndexChanged);
|
|
super.dispose();
|
|
}
|
|
|
|
@override
|
|
Widget build(BuildContext context) {
|
|
_tabController.index = widget.selectedIndex;
|
|
return Scaffold(
|
|
appBar: AppBar(
|
|
title: const Text('Books'),
|
|
bottom: TabBar(
|
|
controller: _tabController,
|
|
tabs: const [
|
|
Tab(
|
|
text: 'Popular',
|
|
icon: Icon(Icons.people),
|
|
),
|
|
Tab(
|
|
text: 'New',
|
|
icon: Icon(Icons.new_releases),
|
|
),
|
|
Tab(
|
|
text: 'All',
|
|
icon: Icon(Icons.list),
|
|
),
|
|
],
|
|
),
|
|
),
|
|
body: widget.child,
|
|
);
|
|
}
|
|
|
|
void _handleTabIndexChanged() {
|
|
widget.onTap(_tabController.index);
|
|
}
|
|
}
|