home_page.dart 2.62 KB
Newer Older
nayeli92433 committed
1
import 'package:flutter/material.dart';
nayeli92433 committed
2
import 'package:miapp_flutter/src/specific_widgets/menu.dart';
nayeli92433 committed
3
import '../delegate/SearchDelegate.dart';
nayeli92433 committed
4
import 'NewCategoryPage.dart';
nayeli92433 committed
5
import 'category/CategoryListWidget.dart';
nayeli92433 committed
6

nayeli92433 committed
7 8 9 10
void main() => runApp(const DrawerApp());

class DrawerApp extends StatelessWidget {
  const DrawerApp({super.key});
nayeli92433 committed
11 12 13

  @override
  Widget build(BuildContext context) {
nayeli92433 committed
14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30
    return MaterialApp(
      theme: ThemeData(useMaterial3: true),
      home: const HomePage(),
    );
  }
}

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

  @override
  State<HomePage> createState() => _HomePageState();
}

class _HomePageState extends State<HomePage> {
  String selectedPage = '';

nayeli92433 committed
31
  void _handleNewCategory() {
nayeli92433 committed
32 33 34
    Navigator.push(
      context,
      MaterialPageRoute(builder: (context) => const NewCategoryPage()),
nayeli92433 committed
35 36 37
    );
  }

nayeli92433 committed
38 39 40 41 42 43 44
  void _startSearch() async {
    showSearch(
      context: context,
      delegate: ArticleSearchDelegate(),
    );
  }

nayeli92433 committed
45 46 47
  @override
  Widget build(BuildContext context) {
    return DefaultTabController(
nayeli92433 committed
48
      length: 2,
nayeli92433 committed
49 50 51 52 53 54 55 56 57 58 59 60 61 62
      child: Scaffold(
        appBar: AppBar(
          title: const Text('Home Page'),
          backgroundColor: Colors.blue,
          leading: Builder(
            builder: (BuildContext context) {
              return IconButton(
                icon: const Icon(Icons.menu),
                onPressed: () {
                  Scaffold.of(context).openDrawer();
                },
              );
            },
          ),
nayeli92433 committed
63 64 65 66 67 68
          actions: [
            IconButton(
              icon: const Icon(Icons.search),
              onPressed: _startSearch,
            ),
          ],
nayeli92433 committed
69 70 71 72 73 74 75
          bottom: const TabBar(
            tabs: [
              Tab(icon: Icon(Icons.home), text: 'Categoria'),
              Tab(icon: Icon(Icons.person_2_outlined), text: 'Perfil'),
            ],
          ),
        ),
nayeli92433 committed
76
        drawer: MenuWidget(),
nayeli92433 committed
77 78
        body: TabBarView(
          children: [
nayeli92433 committed
79
            Column(
nayeli92433 committed
80 81
              children: [
                Expanded(
nayeli92433 committed
82
                  child: CategoryListWidget(),
nayeli92433 committed
83 84
                ),
                Padding(
nayeli92433 committed
85
                  padding: const EdgeInsets.all(16.0),
nayeli92433 committed
86 87
                  child: ElevatedButton(
                    onPressed: _handleNewCategory,
nayeli92433 committed
88
                    child: const Text('Nueva categoría'),
nayeli92433 committed
89 90 91
                    style: ElevatedButton.styleFrom(
                      foregroundColor: Colors.white, backgroundColor: Colors.blue,
                    ),
nayeli92433 committed
92 93 94 95
                  ),
                ),
              ],
            ),
nayeli92433 committed
96 97
            Center(child: Text('Tab 2 Contenido')),
          ],
nayeli92433 committed
98 99 100 101 102
        ),
      ),
    );
  }
}