HomeiOS Developmentandroid - Make the + button tab not capable of be chosen

android – Make the + button tab not capable of be chosen


I’m making an app in flutter and have a tabview widget. Faux I’ve three tabs, a, b, and c. I would like to have the ability to swipe from a to b and b to a, however not b to c or c to b. One of many tabs shouldn’t be capable of be swiped to. As an alternative of a b and c tabs, in my code it’s ‘My First Exercise’ and a plus button. Whenever you click on the plus button one other tab pops up, and I would like to have the ability to swipe from ‘My First Exercise’ to the brand new tab, however not the the plus button.

import 'package deal:flutter/materials.dart';
import 'package deal:workout_app/Screens/Elements/Widgets/footer.dart';

class workout_page extends StatefulWidget {
  @override
  _WorkoutPageState createState() => _WorkoutPageState();
}

class _WorkoutPageState extends State<workout_page>
    with TickerProviderStateMixin {
  late TabController _tabController;
  Checklist<Map<String, dynamic>> workoutMap = [
    {
      'name': 'My First Workout',
      'exercises': [
        {
          'name': 'Bicep Curl',
          'musclesworked': ['bicep', 'tricep']
        },
        {
          'identify': 'Preacher Curl',
          'musclesworked': ['bicep', 'tricep']
        }
      ]
    },
  ];

  @override
  void initState() {
    tremendous.initState();
    _tabController = TabController(size: workoutMap.size + 1, vsync: this);
  }

  TextEditingController _newTabController = TextEditingController();

  void _addTab() {
    setState(() {
      String newTabName = _newTabController.textual content;
      Map<String, dynamic> newTab = {
        'identify': newTabName,
        'workouts': [],
      };
      workoutMap.add(newTab);
      _newTabController.clear();
      _tabController = TabController(
        size: workoutMap.size + (workoutMap.size < 4 ? 1 : 0),
        vsync: this,
      );
    });
  }

  @override
  Widget construct(BuildContext context) {
    var measurement = MediaQuery.of(context).measurement;
    return Container(
      ornament: BoxDecoration(shade: Colour.fromARGB(255, 67, 67, 67)),
      baby: DefaultTabController(
        size: workoutMap.size + (workoutMap.size < 4 ? 1 : 0),
        baby: Scaffold(
          backgroundColor: Colour.fromRGBO(79, 79, 79, 1),
          physique: Stack(
            kids: [
              CustomScrollView(
                physics: NeverScrollableScrollPhysics(),
                slivers: [
                  SliverAppBar(
                    expandedHeight: 30,
                    titleSpacing: 15,
                    pinned: true,
                    elevation: 0,
                    backgroundColor: Color.fromARGB(255, 19, 19, 19),
                    centerTitle: false,
                    bottom: PreferredSize(
                        preferredSize: const Size.fromHeight(0),
                        child: Column(children: [
                          TabBar(
                            physics: NeverScrollableScrollPhysics(),
                            tabs: [
                              ...workoutMap.map(
                                  (tab) => Tab(text: tab['name'] as String)),
                              if (workoutMap.size < 4)
                                Container(
                                  width: 40,
                                  peak: 40,
                                  alignment: Alignment.heart,
                                  baby: IconButton(
                                    icon: Icon(Icons.add),
                                    onPressed: () {
                                      showDialog(
                                        context: context,
                                        builder: (context) => AlertDialog(
                                          title: Textual content('Add Tab'),
                                          content material: TextField(
                                            controller: _newTabController,
                                            ornament: InputDecoration(
                                              hintText: 'Enter tab identify',
                                            ),
                                          ),
                                          actions: [
                                            TextButton(
                                              child: Text('Cancel'),
                                              onPressed: () {
                                                Navigator.pop(context);
                                              },
                                            ),
                                            TextButton(
                                              child: Text('Add'),
                                              onPressed: () {
                                                _addTab();
                                                Navigator.pop(context);
                                              },
                                            ),
                                          ],
                                        ),
                                      );
                                    },
                                  ),
                                ),
                            ],
                          ),
                        ])),
                  ),
                  SliverToBoxAdapter(
                    baby: Container(
                      peak: measurement.peak,
                      baby: TabBarView(
                        physics: NeverScrollableScrollPhysics(),
                        controller: _tabController,
                        kids: [
                          ...workoutMap.map((tab) => Text(tab['name'])),
                          if (workoutMap.size < 4) Container(),
                        ],
                      ),
                    ),
                  )
                ],
              ),
              //Positioned(
              //  proper: 10, backside: measurement.peak * .3, baby: ExpandableFab()),
              Footer(tab: 'Exercise'),
            ],
          ),
        ),
      ),
    );
  }
}

Thanks!

RELATED ARTICLES

LEAVE A REPLY

Please enter your comment!
Please enter your name here

Most Popular

Recent Comments