i am getting an error while using the sliding up panel dependency in my flutter code

214 Views Asked by At

I get an exception whenever I press the payments button on my bottom nav-bar. the error goes like this:

The ParentDataWidget Expanded(flex: 1) wants to apply ParentData of type FlexParentData to a RenderObject, which has been set up to accept ParentData of incompatible type ParentData.

Usually, this means that the Expanded widget has the wrong ancestor RenderObjectWidget. Typically, Expanded widgets are placed directly inside Flex widgets.
The offending Expanded is currently placed inside a RepaintBoundary widget.

The ownership chain for the RenderObject that received the incompatible parent data was:
  SizedBox.shrink ← Expanded ← Spacer ← RepaintBoundary ← IndexedSemantics ← _SelectionKeepAlive ← NotificationListener<KeepAliveNotification> ← KeepAlive ← AutomaticKeepAlive ← KeyedSubtree ← ⋯
When the exception was thrown, this was the stack

one other issue that i am getting is that whenever i close the sliding up panel i want the bottom nav bar to go back to the personal screen and the personal index as well. right now in my code when i close the panel it remains in the payments tab.

code for the main page is:

import 'package:flutter/material.dart';
import 'package:sadapay_clone/screens/more_screen.dart';
import 'package:sadapay_clone/screens/payments.dart';
// import 'package:sliding_up_panel/sliding_up_panel.dart';

import '../widgets/homepage_item.dart';

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

  @override
  State<MyHomePage> createState() => _MyHomePageState();
}

class _MyHomePageState extends State<MyHomePage> {
  int _currIndex = 0;

  final tabs = [
    const HomePageItem(),
    const Payments(),
    const MoreScreen(),
  ];

  @override
  Widget build(BuildContext context) {
    return Scaffold(
      backgroundColor: const Color.fromARGB(255, 238, 237, 237),
      body: tabs[_currIndex],
      bottomNavigationBar: BottomNavigationBar(
        currentIndex: _currIndex,
        items: const <BottomNavigationBarItem>[
          BottomNavigationBarItem(
            icon: Icon(Icons.home_rounded),
            label: 'Personal',
          ),
          BottomNavigationBarItem(
            icon: Icon(Icons.view_kanban),
            label: 'Payments',
          ),
          BottomNavigationBarItem(
            icon: Icon(Icons.menu),
            label: 'More',
          ),
        ],
        fixedColor: const Color.fromARGB(255, 255, 129, 129),
        onTap: (index) {
          setState(() {
            _currIndex = index;
          });
        },
      ),
    );
  }
}

and the code for the payments page is:

import 'package:flutter/material.dart';
// import 'package:sadapay_clone/screens/homepage.dart';
import 'package:sliding_up_panel/sliding_up_panel.dart';

import '../widgets/homepage_item.dart';
import '../widgets/tabwidget.dart';

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

  @override
  State<Payments> createState() => _PaymentsState();
}

class _PaymentsState extends State<Payments> {
  @override
  Widget build(BuildContext context) {
    return SlidingUpPanel(
      backdropEnabled: true,
      panelBuilder: (scrollController) =>
          buildSlidingPanel(scrollController: scrollController),
      body: const HomePageItem(),
      // panel: const Text('this is sliding up panel'),
      // borderRadius: BorderRadius.only(topRight: 20,topLeft: 20),
      borderRadius: const BorderRadius.only(
          topLeft: Radius.circular(20), topRight: Radius.circular(20)),
      backdropTapClosesPanel: true,
      defaultPanelState: PanelState.OPEN,
      // onPanelClosed: () => const MyHomePage(),
      panelSnapping: false,
      maxHeight: 400,
      minHeight: 40,
    );
  }

  Widget buildSlidingPanel({
    required ScrollController scrollController,
  }) =>
      TabWidget(
        scrollController: scrollController,
      );
}

the tabwidget code is:

import 'package:flutter/material.dart';
import 'package:sadapay_clone/widgets/personal_item.dart';

class TabWidget extends StatelessWidget {
  final ScrollController scrollController;
  const TabWidget({super.key, required this.scrollController});

  @override
  Widget build(BuildContext context) => ListView(
        padding: const EdgeInsets.all(16),
        controller: scrollController,
        children: const [
          Padding(
            padding: EdgeInsets.only(bottom: 20.0),
            child: Icon(
              Icons.horizontal_rule,
            ),
          ),
          Spacer(),
          Padding(
            // padding: EdgeInsets.all(15.0),
            padding: EdgeInsets.only(
              top: 15,
              left: 10,
              bottom: 15,
            ),
            child: Text(
              'Payments',
              textAlign: TextAlign.left,
              style: TextStyle(
                fontSize: 35,
                fontWeight: FontWeight.w500,
                color: Colors.black,
              ),
            ),
          ),
          PersonalItem(
            icon: Icon(
              Icons.phone_android_rounded,
              size: 30,
              color: Color.fromARGB(255, 255, 129, 129),
            ),
            title: 'Mobile top up',
            subtext: 'Instantly top up your mobile.',
          ),
          Divider(thickness: 1.5),
          PersonalItem(
            icon: Icon(
              Icons.receipt_rounded,
              size: 30,
              color: Color.fromARGB(255, 255, 129, 129),
            ),
            title: 'Bills and utilities',
            subtext: 'Pay for your utilities.',
          ),
          Divider(
            thickness: 1.5,
          ),
          PersonalItem(
            icon: Icon(
              Icons.card_membership_rounded,
              size: 30,
              color: Color.fromARGB(255, 255, 129, 129),
            ),
            title: 'Money requests',
            subtext: 'Review pending money req.',
          ),
          // PersonalItem(),
          // PersonalItem(),
        ],
      );
}
0

There are 0 best solutions below