0

Выводятся ошибки:

Another exception was thrown: RangeError (index): Index out of range: index should be less than 1: 2
Another exception was thrown: RangeError (index): Index out of range: index should be less than 1: 1
Another exception was thrown: RangeError (index): Index out of range: index should be less than 1: 4
Another exception was thrown: RangeError (index): Index out of range: index should be less than 1: 9
Another exception was thrown: RangeError (index): Index out of range: index should be less than 1: 6
Another exception was thrown: RangeError (index): Index out of range: index should be less than 1: 5
Another exception was thrown: RangeError (index): Index out of range: index should be less than 1: 7
Another exception was thrown: RangeError (index): Index out of range: index should be less than 1: 4
Another exception was thrown: RangeError (index): Index out of range: index should be less than 1: 3
Another exception was thrown: RangeError (index): Index out of range: index should be less than 1: 4
Another exception was thrown: RangeError (index): Index out of range: index should be less than 1: 7
Another exception was thrown: RangeError (index): Index out of range: index should be less than 1: 4
Another exception was thrown: RangeError (index): Index out of range: index should be less than 1: 4.

Хотя всё правильно написал вот код:`

import 'package:flutter/material.dart';
import 'package:my_app/views/screens/profile.dart';
import 'chat/chats.dart';
import 'friends.dart';
import 'home.dart';
import 'notifications.dart';

class MainScreen extends StatefulWidget {
  const MainScreen({Key? key});

  @override
  _MainScreenState createState() => _MainScreenState();
}

class _MainScreenState extends State<MainScreen> {
  late PageController _pageController;
  int _page = 2;

  @override
  void initState() {
    super.initState();
    _pageController = PageController(initialPage: _page);
  }

  @override
  void dispose() {
    _pageController.dispose();
    super.dispose();
  }

  void onPageChanged(int page) {
    setState(() {
      _page = page;
    });
  }

  void navigationTapped(int page) {
    _pageController.animateToPage(
      page,
      duration: const Duration(milliseconds: 300),
      curve: Curves.ease,
    );
  }

  @override
  Widget build(BuildContext context) {
    return Scaffold(
      body: PageView(
        physics: const NeverScrollableScrollPhysics(),
        controller: _pageController,
        onPageChanged: onPageChanged,
        children: <Widget>[
          const Chats(),
          Friends(),
          const Home(),
          Notifications(),
          Profile(),
        ],
      ),
      bottomNavigationBar: Theme(
        data: Theme.of(context).copyWith(
          canvasColor: Theme.of(context).primaryColor,
          primaryColor: Theme.of(context).colorScheme.secondary,
          textTheme: Theme.of(context).textTheme.copyWith(
                bodySmall: TextStyle(color: Colors.grey[500]),
              ),
        ),
        child: BottomNavigationBar(
          type: BottomNavigationBarType.fixed,
          items: const <BottomNavigationBarItem>[
            BottomNavigationBarItem(
              icon: Icon(Icons.message),
              label: '',
            ),
            BottomNavigationBarItem(
              icon: Icon(Icons.group),
              label: '',
            ),
            BottomNavigationBarItem(
              icon: Icon(Icons.home),
              label: '',
            ),
            BottomNavigationBarItem(
              icon: Icon(Icons.notifications),
              label: '',
            ),
            BottomNavigationBarItem(
              icon: Icon(Icons.person),
              label: '',
            ),
          ],
          onTap: navigationTapped,
          currentIndex: _page,
        ),
      ),
    );
  }
}

`Помогите решить проблему

1
  • Ошибка не в данном коде. У вас есть конкретная ошибка, где написано что и как.
    – Dinario
    16 июл в 14:49

0

Ваш ответ

Нажимая на кнопку «Отправить ответ», вы соглашаетесь с нашими условиями использования и подтверждаете, что прочитали и поняли наши политику конфиденциальности и нормы поведения.

Посмотрите другие вопросы с метками или задайте свой вопрос.