Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Nested TabBar&TabBarView - first tab scroll out when open app #28007

Closed
lzdon opened this issue Feb 15, 2019 · 4 comments
Closed

Nested TabBar&TabBarView - first tab scroll out when open app #28007

lzdon opened this issue Feb 15, 2019 · 4 comments
Labels
f: material design flutter/packages/flutter/material repository. f: scrolling Viewports, list views, slivers, etc. framework flutter/packages/flutter repository. See also f: labels.

Comments

@lzdon
Copy link

lzdon commented Feb 15, 2019

looks like

image

should be

image

@lzdon lzdon changed the title Nested TabBar&TabBarView - first tab Nested TabBar&TabBarView - first tab scroll out when open app Feb 15, 2019
@zoechi
Copy link
Contributor

zoechi commented Feb 15, 2019

Please add the output of flutter doctor -v.

To investigate we would need a minimal runnable reproduction
as a single file so that we can just copy your code into lib/main.dart of a new project and run to reproduce.

Please consider asking on StackOverflow before creating an issue and only create an issue if it turns out to be a Flutter bug or missing feature.

@zoechi zoechi added the waiting for customer response The Flutter team cannot make further progress on this issue until the original reporter responds label Feb 15, 2019
@lzdon
Copy link
Author

lzdon commented Feb 15, 2019

only show in profile or release mode

output

[✓] Flutter (Channel stable, v1.0.0, on Mac OS X 10.14.2 18C54, locale zh-Hans-CN)
    • Flutter version 1.0.0 at /Users/lzd/Library/Android/flutter
    • Framework revision 5391447fae (3 months ago), 2018-11-29 19:41:26 -0800
    • Engine revision 7375a0f414
    • Dart version 2.1.0 (build 2.1.0-dev.9.4 f9ebf21297)

[!] Android toolchain - develop for Android devices (Android SDK 28.0.3)
    • Android SDK at /Users/lzd/Library/Android/sdk
    • Android NDK location not configured (optional; useful for native profiling support)
    • Platform android-28, build-tools 28.0.3
    • ANDROID_HOME = /Users/lzd/Library/Android/sdk
    • Java binary at: /Applications/Android Studio.app/Contents/jre/jdk/Contents/Home/bin/java
    • Java version OpenJDK Runtime Environment (build 1.8.0_152-release-1248-b01)
    ✗ Android license status unknown.

[✗] iOS toolchain - develop for iOS devices
    ✗ Xcode installation is incomplete; a full installation is necessary for iOS development.
      Download at: https://developer.apple.com/xcode/download/
      Or install Xcode via the App Store.
      Once installed, run:
        sudo xcode-select --switch /Applications/Xcode.app/Contents/Developer
    ✗ libimobiledevice and ideviceinstaller are not installed. To install with Brew, run:
        brew update
        brew install --HEAD usbmuxd
        brew link usbmuxd
        brew install --HEAD libimobiledevice
        brew install ideviceinstaller
    ✗ ios-deploy not installed. To install with Brew:
        brew install ios-deploy
    ✗ CocoaPods not installed.
        CocoaPods is used to retrieve the iOS platform side's plugin code that responds to your plugin usage on the
        Dart side.
        Without resolving iOS dependencies with CocoaPods, plugins will not work on iOS.
        For more info, see https://flutter.io/platform-plugins
      To install:
        brew install cocoapods
        pod setup

[✓] Android Studio (version 3.3)
    • Android Studio at /Applications/Android Studio.app/Contents
    • Flutter plugin version 32.0.1
    • Dart plugin version 182.5124
    • Java version OpenJDK Runtime Environment (build 1.8.0_152-release-1248-b01)

[✓] Connected device (1 available)
    • MI 6X • 1f97b91d • android-arm64 • Android 8.1.0 (API 27)

! Doctor found issues in 2 categories.

code

import 'package:flutter/material.dart';

const ProjectTitle = 'RX-0';
const EnableBroadcast = true;

enum BLTabItem { home, feed, favorite, discovery, mine }

String titleForTabItem(BLTabItem item) {
  switch (item) {
    case BLTabItem.home:
      return '首页';
    case BLTabItem.feed:
      return '推荐';
    case BLTabItem.favorite:
      return '关注';
    case BLTabItem.discovery:
      return '发现';
    case BLTabItem.mine:
      return '我的';
  }
  return null;
}

Icon iconForTabItem(BLTabItem item) {
  switch (item) {
    case BLTabItem.home:
      return Icon(Icons.home);
    case BLTabItem.feed:
      return Icon(Icons.list);
    case BLTabItem.favorite:
      return Icon(Icons.favorite);
    case BLTabItem.discovery:
      return Icon(Icons.info);
    case BLTabItem.mine:
      return Icon(Icons.account_circle);
  }
  return null;
}

void main() => runApp(BLApp());

class BLApp extends StatelessWidget {
  @override
  Widget build(BuildContext context) {
    return MaterialApp(title: ProjectTitle, home: EntranceScaffold());
  }
}

class EntranceScaffold extends StatefulWidget {
  @override
  _EntranceScaffoldState createState() => _EntranceScaffoldState();
}

class _EntranceScaffoldState extends State<EntranceScaffold> {
  @override
  Widget build(BuildContext context) {
    return DefaultTabController(
      length: BLTabItem.values.length,
      child: Scaffold(
          body: TabBarView(
            children:
                BLTabItem.values.map((BLTabItem item) => HomeTab()).toList(),
          ),
          bottomNavigationBar: Material(
              color: Colors.white,
              child: SafeArea(
                  child: Container(
                height: 65,
                decoration: BoxDecoration(
                  color: const Color(0xFFF0F0F0),
                  boxShadow: <BoxShadow>[
                    BoxShadow(
                      color: const Color(0xFFd0d0d0),
                      blurRadius: 4.0,
                      spreadRadius: 2.0,
                      offset: Offset(-1.0, -1.0),
                    ),
                  ],
                ),
                child: TabBar(
                    indicatorColor: Colors.transparent,
                    labelColor: Theme.of(context).primaryColor,
                    unselectedLabelColor: const Color(0xFF8E8E8E),
                    tabs: BLTabItem.values
                        .map((item) => Tab(
                            text: titleForTabItem(item),
                            icon: iconForTabItem(item)))
                        .toList()),
              ))),
          floatingActionButton: EnableBroadcast
              ? Builder(builder: (BuildContext context) {
                  return FloatingActionButton(
                      child: Text('开播'),
                      onPressed: () {
                        final snackBar = SnackBar(
                            content: Text('主播开播', textAlign: TextAlign.center),
                            duration: Duration(milliseconds: 1500));
                        Scaffold.of(context).showSnackBar(snackBar);
                      });
                })
              : null),
    );
  }
}

class HomeTab extends StatefulWidget {
  @override
  _HomeTabState createState() => _HomeTabState();
}

class _HomeTabState extends State<HomeTab> with AutomaticKeepAliveClientMixin {
  @override
  bool get wantKeepAlive => true;

  @override
  Widget build(BuildContext context) {
    return DefaultTabController(
        length: 6,
        child: Scaffold(
          appBar: AppBar(
            // 大量配置属性参考 SliverAppBar 示例
            title: Text('TabBar'),
            leading: Icon(Icons.home),
            backgroundColor: Colors.amber[1000],
            bottom: TabBar(
              isScrollable: true,
              tabs: <Widget>[
                Tab(text: "Tabs 1"),
                Tab(text: "Tabs 2"),
                Tab(text: "Tabs 3"),
                Tab(text: "Tabs 4"),
                Tab(text: "Tabs 5"),
                Tab(text: "Tabs 6"),
              ],
            ),
          ),
          body: TabBarView(children: <Widget>[
            Text('TabsView 1'),
            Text('TabsView 2'),
            Text('TabsView 3'),
            Text('TabsView 4'),
            Text('TabsView 5'),
            Text('TabsView 6'),
          ]),
        ));
  }
}

@no-response no-response bot removed the waiting for customer response The Flutter team cannot make further progress on this issue until the original reporter responds label Feb 15, 2019
@zoechi zoechi added framework flutter/packages/flutter repository. See also f: labels. f: material design flutter/packages/flutter/material repository. f: scrolling Viewports, list views, slivers, etc. labels Feb 15, 2019
@zoechi zoechi added this to the Goals milestone Feb 15, 2019
@VladyslavBondarenko
Copy link

I can't reproduce it with dev 1.16.4-pre.83 when running flutter run --release on Android 9 device.
Closing, I hope it's fixed.
@lzdon comment please if it's not so and I'll reopen the issue

@lock
Copy link

lock bot commented Apr 19, 2020

This thread has been automatically locked since there has not been any recent activity after it was closed. If you are still experiencing a similar issue, please open a new bug, including the output of flutter doctor -v and a minimal reproduction of the issue.

@lock lock bot locked and limited conversation to collaborators Apr 19, 2020
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
f: material design flutter/packages/flutter/material repository. f: scrolling Viewports, list views, slivers, etc. framework flutter/packages/flutter repository. See also f: labels.
Projects
None yet
Development

No branches or pull requests

3 participants