Follow

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use
Contact

"Invalid constant value" error for TabController

I’ve worked with tabs before and this code bellow always worked. But I recently updated everything and as usual they broke something that was working perfectly and now I don’t know how to make it work.

It’s the exact same example as in https://api.flutter.dev/flutter/material/TabController-class.html

Here’s my code:

MEDevel.com: Open-source for Healthcare and Education

Collecting and validating open-source software for healthcare, education, enterprise, development, medical imaging, medical records, and digital pathology.

Visit Medevel

class _MyHomePageState extends State<MyHomePage> with SingleTickerProviderStateMixin {  
  late TabController _tabController;

  @override
  void initState() {
    super.initState();
    _tabController = TabController(length: 5, vsync: this);
  }

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

  @override
  Widget build(BuildContext context) {
    return Scaffold(
      appBar: AppBar(
        title: Text(widget.title),
        bottom: const TabBar(
          controller: _tabController, //problem is here
          tabs: [...

When I assign "controller: _tabController" it throws "Invalid constant value".

I get it, TabBar.controller is expecting a constant. But how to work around this error?

>Solution :

Remove const keyword in front of TabBar widget

Add a comment

Leave a Reply

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use

Discover more from Dev solutions

Subscribe now to keep reading and get access to the full archive.

Continue reading