0

Have 'TextInputArea' widget, and want to keep this widget remain on screen (upper part of screen) all the time,

Lower part of screen need to be changed as per BottomNavigationBar (it has three pages XX,YY,ZZ) is clicked

But 'TextInputArea' is not getting loaded on screen.

Tried something like this

Widget build(BuildContext context) {
    returnScaffold(
        appBar: AppBarWidget(),
        body: TextInputArea(),          
        bottomNavigationBar: Location(),
        floatingActionButton: TextFloatingButtonSpeedDial(),
      ),
  }

Location.dart

class Location extends StatefulWidget {

  @override
  State<Location> createState() => _LocationState();
}

    class _LocationState extends State<Location> {
      final List<Map<String, Object>> _pages = [
        {
          'page': India(),
          'title': 'india',
        },
        {
          'page': Universe(targetArea: Galaxy.milkyway),
          'title': 'milkyway',
        },
        {
          'page': Universe(targetArea: Galaxy.other),,
          'title': 'other',
        },
      ];
      int _selectedPageIndex = 0;
    
      void _selectPage(int index) {
        setState(() {
          _selectedPageIndex = index;
        });
      }
    
      @override
      Widget build(BuildContext context) {
        
        return Scaffold(
          appBar: AppBar(
            title: Text(_pages[_selectedPageIndex]['title'] as String),
          ),
          body: _pages[_selectedPageIndex]['page'] as Widget,
          bottomNavigationBar: BottomNavigationBar(
            backgroundColor: Colors.white,
            unselectedItemColor: Colors.grey,
            selectedItemColor: Colors.blue,
            currentIndex: _selectedPageIndex,
            items: [
              BottomNavigationBarItem(
                backgroundColor: Colors.lightBlue,
                icon: Icon(Icons.abc),
                label: 'ZZ',
              ),
              BottomNavigationBarItem(
                backgroundColor: Colors.lightBlue,
                icon: Icon(Icons.water_drop_outlined),
                label: 'YY',
              ),
              BottomNavigationBarItem(
                backgroundColor: Colors.lightBlue,
                icon: Icon(Icons.filter_list_alt),
                label: 'XX',
              ),
            ],
            onTap: _selectPage,
          ),
        );
      }
    }
Noorus Khan
  • 1,342
  • 3
  • 15
  • 33

2 Answers2

0

There is a common issue with creating state variable with widget where inner widgets needed to be updated. but without reassigning the variable value will be same. You can create method instead of variable on this case.

List<Map<String, Object>> _pages() => [...

And use like _pages()[_selectedPageIndex]

Md. Yeasin Sheikh
  • 54,221
  • 7
  • 29
  • 56
0

Change your main widget to this:

Widget build(BuildContext context) {
    returnScaffold(
        appBar: AppBarWidget(),
        body: Column(children: [
                Expanded(child: TextInputArea()),
                Location(),
              ]),          
        floatingActionButton: TextFloatingButtonSpeedDial(),
      ),
  }
Code on the Rocks
  • 11,488
  • 3
  • 53
  • 61
  • Actually Location() have three segment/pages, you have removed BottomNavigationBar, then how would these segment get available on tab bar below, so that can click on respective page to navigate on to these segment. – Noorus Khan Nov 28 '22 at 08:20