caduandrade / tabbed_view

Widget inspired by the classic Desktop-style tab component.
MIT License
49 stars 16 forks source link

New tab after the first is highlighted when added #31

Closed vladimircokorilo closed 1 year ago

vladimircokorilo commented 1 year ago

I am having a bug when adding a new tab after the first one is already opened. Every time I add a new tab when the first tab is selected, the second tab is immediately highlighted, but every other tab added after the second isn't highlighted. Tested on all desktop platforms (Windows, Macos, Linux), tabbed_view version 1.17.0

mit@mit-System-Product-Name:~$ flutter doctor Doctor summary (to see all details, run flutter doctor -v): [✓] Flutter (Channel stable, 3.10.0, on Ubuntu 22.04.2 LTS 5.19.0-42-generic, locale en_US.UTF-8) [✓] Android toolchain - develop for Android devices (Android SDK version 33.0.2) [✗] Chrome - develop for the web (Cannot find Chrome executable at google-chrome) ! Cannot find Chrome. Try setting CHROME_EXECUTABLE to a Chrome executable. [✓] Linux toolchain - develop for Linux desktop [✓] Android Studio (version 2022.1) [✓] Android Studio [✓] VS Code (version 1.77.3) [✓] Connected device (1 available) [✓] Network resources

`import 'package:flutter/material.dart'; import 'package:tabbed_view/tabbed_view.dart';

void main() { runApp(const MyApp()); }

class MyApp extends StatelessWidget { const MyApp({super.key});

// This widget is the root of your application. @override Widget build(BuildContext context) { return MaterialApp( debugShowCheckedModeBanner: false, title: 'Flutter Demo', theme: ThemeData( colorScheme: ColorScheme.fromSeed(seedColor: Colors.deepPurple), useMaterial3: true, ), home: TabbedViewExample(), ); } }

class TabbedViewExample extends StatelessWidget { @override Widget build(BuildContext context) { return TabbedViewExamplePage(); } }

class TabbedViewExamplePage extends StatefulWidget { @override _TabbedViewExamplePageState createState() => _TabbedViewExamplePageState(); }

class _TabbedViewExamplePageState extends State { late TabbedViewController _controller;

List tabs = []; @override void initState() { super.initState();

tabs.add(TabData(
    text: 'Tab 1',
    leading: (context, status) => Icon(Icons.star, size: 16),
    content: Text('Hello')));
tabs.add(TabData(text: 'Tab 2', content: Text('Hello again')));

_controller = TabbedViewController(tabs);

}

@override Widget build(BuildContext context) { TabbedView tabbedView = TabbedView(controller: _controller); Widget w = TabbedViewTheme(child: tabbedView, data: TabbedViewThemeData.mobile()); return Column( children: [ TextButton( onPressed: () { setState(() { tabs.add( TabData(text: 'New tab', content: Text('Hello again'))); }); }, child: Text("Add new tab")), SizedBox(height: 200, width: 500, child: Scaffold(body: w)), ], ); } } `

image

Mouse cursor is not over second tab.

caduandrade commented 1 year ago

Hi @vladimircokorilo!

I made small changes to your code as it wasn't compiling. But after adding new tabs, no other tab gets highlighted without the cursor being over it. Could you test it with this code? Didn't you forget anything?

import 'package:flutter/material.dart';
import 'package:tabbed_view/tabbed_view.dart';

void main() {
  runApp(MyApp());
}

class MyApp extends StatelessWidget {
// This widget is the root of your application.

  Widget build(BuildContext context) {
    return MaterialApp(
      debugShowCheckedModeBanner: false,
      title: 'Flutter Demo',
      theme: ThemeData(
        colorScheme: ColorScheme.fromSeed(seedColor: Colors.deepPurple),
        useMaterial3: true,
      ),
      home: TabbedViewExample(),
    );
  }
}

class TabbedViewExample extends StatelessWidget {
  @override
  Widget build(BuildContext context) {
    return TabbedViewExamplePage();
  }
}

class TabbedViewExamplePage extends StatefulWidget {
  @override
  _TabbedViewExamplePageState createState() => _TabbedViewExamplePageState();
}

class _TabbedViewExamplePageState extends State {
  late TabbedViewController _controller;

  List<TabData> tabs = [];

  @override
  void initState() {
    super.initState();

    tabs.add(TabData(
        text: 'Tab 1',
        leading: (context, status) => Icon(Icons.star, size: 16),
        content: Text('Hello')));
    tabs.add(TabData(text: 'Tab 2', content: Text('Hello again')));

    _controller = TabbedViewController(tabs);
  }

  @override
  Widget build(BuildContext context) {
    TabbedView tabbedView = TabbedView(controller: _controller);
    Widget w =
        TabbedViewTheme(child: tabbedView, data: TabbedViewThemeData.mobile());
    return Column(
      children: [
        TextButton(
            onPressed: () {
              setState(() {
                tabs.add(
                    TabData(text: 'New tab', content: Text('Hello again')));
              });
            },
            child: Text("Add new tab")),
        SizedBox(height: 200, width: 500, child: Scaffold(body: w)),
      ],
    );
  }
}
vladimircokorilo commented 1 year ago

I copied and pasted the code you have provided and the bug is still there. The second tab that's added is highlighted, but the third one isn't. Cursor was not hovering over the second tab. I am attaching a video to display the issue.

https://github.com/caduandrade/tabbed_view/assets/49246201/c9d1cc70-836e-4b2f-8f19-26097e6fe1b5

caduandrade commented 1 year ago

Hi @vladimircokorilo! Thank you and sorry for the delay. Fix made in version 1.18.0