Skip to content

Instantly share code, notes, and snippets.

@roketstorm
Created July 16, 2020 17:54
Show Gist options
  • Save roketstorm/ba0e2a8684eeb9508ee3a2e7c7dd03a0 to your computer and use it in GitHub Desktop.
Save roketstorm/ba0e2a8684eeb9508ee3a2e7c7dd03a0 to your computer and use it in GitHub Desktop.
import 'package:flutter/material.dart';
import 'package:gensei_shop/pages/catalogPage.dart';
import 'package:gensei_shop/pages/contactsPage.dart';
import 'package:gensei_shop/pages/homePage.dart';
import 'package:gensei_shop/pages/ordersPage.dart';
// Точка входа в программу
void main() => runApp(MyApp());
// Корневой виджет с настройками приложения
class MyApp extends StatelessWidget {
@override
Widget build(BuildContext context) {
return MaterialApp(
title: 'Flutter Demo',
theme: ThemeData(
primarySwatch: Colors.purple,
primaryColor: Colors.purple[300]
),
home: MyHomePage(title: 'Gensei Shop Mobile'), // Начальный виджет
);
}
}
// Создание объекта класса MyHomePage с полем title
class MyHomePage extends StatefulWidget {
MyHomePage({Key key, this.title}) : super(key: key);
final String title;
@override
_MyHomePageState createState() => _MyHomePageState();
}
// Класса состояния виджета MyHomePage
class _MyHomePageState extends State<MyHomePage> {
// Индекс текущей страницы
int _selectedIndex = 0;
// Страницы, которые можно вызвать из нижнего бара
List<Widget> _widgetOptions = <Widget>[
HomePage(),
CatalogPage(),
OrdersPage(),
ContactsPage()
];
// Вызываем функцию при нажатии на элемент в нижнем баре
void _onItemTapped(int index) {
setState(() {
_selectedIndex = index;
});
}
@override
Widget build(BuildContext context) {
return Scaffold(
appBar: AppBar(
title: Text(widget.title),
centerTitle: true,
actions: <Widget>[
IconButton(
icon: Icon(Icons.notifications_none),
onPressed: () {},
)
],
),
body: _widgetOptions.elementAt(_selectedIndex),
bottomNavigationBar: BottomNavigationBar(
onTap: _onItemTapped,
currentIndex: _selectedIndex,
type: BottomNavigationBarType.shifting,
unselectedItemColor: Colors.grey[400],
selectedItemColor: Theme.of(context).primaryColor,
items: [
BottomNavigationBarItem(
icon: Icon(Icons.chrome_reader_mode), title: Text("Главная")),
BottomNavigationBarItem(
icon: Icon(Icons.shopping_cart), title: Text("Каталог")),
BottomNavigationBarItem(
icon: Icon(Icons.assignment), title: Text("Мои Заказы")),
BottomNavigationBarItem(
icon: Icon(Icons.map), title: Text("Контакты"))
],
),
);
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment