flutter的widget关系图

flutter的widget关系图_第1张图片

PreferredSizeWidget

PreferredSizeWidget (preferred_size.dart)
    AppBar (app_bar.dart)
    CupertinoTabBar (bottom_tab_bar.dart)
    ObstructingPreferredSizeWidget (page_scaffold.dart)
        CupertinoNavigationBar (nav_bar.dart)
    PreferredSize (preferred_size.dart)
    TabBar (tabs.dart)

ProxyWidget

Diagnosticable (diagnostics.dart)
    DiagnosticableTree (diagnostics.dart)
        Widget (framework.dart)
            ProxyWidget (framework.dart)
                InheritedWidget (framework.dart)
                    _FocusScopeMarker (focus_scope.dart)
                    _FormScope (form.dart)
                    _InheritedCupertinoTheme (theme.dart)
                    _InheritedNestedScrollView (nested_scroll_view.dart)
                    _InheritedTheme (theme.dart)
                    _LocalizationsScope (localizations.dart)
                    _ModalScopeStatus (routes.dart)
                    _ScaffoldScope (scaffold.dart)
                    _ScrollableScope (scrollable.dart)
                    _TabControllerScope (tab_controller.dart)
                    ButtonTheme (button_theme.dart)
                    ChipTheme (chip_theme.dart)
                    DefaultAssetBundle (basic.dart)
                    DefaultTextStyle (text.dart)
                    Directionality (basic.dart)
                    DropdownButtonHideUnderline (dropdown.dart)
                    FlexibleSpaceBarSettings (flexible_space_bar.dart)
                    IconTheme (icon_theme.dart)
                    InheritedModel (inherited_model.dart)
                    InheritedNotifier (inherited_notifier.dart)
                    ListTileTheme (list_tile.dart)
                    MediaQuery (media_query.dart)
                    PrimaryScrollController (primary_scroll_controller.dart)
                    ScrollConfiguration (scroll_configuration.dart)
                    SliderTheme (slider_theme.dart)
                    TickerMode (ticker_provider.dart)
                ParentDataWidget (framework.dart)
                    _ActionButtonParentDataWidget (action_sheet.dart)
                    _ActionButtonParentDataWidget (dialog.dart)
                    Flexible (basic.dart)
                        Expanded (basic.dart)
                    KeepAlive (sliver.dart)
                    LayoutId (basic.dart)
                    Positioned (basic.dart)
                    TableCell (table.dart)

RenderObjectWidget

Diagnosticable (diagnostics.dart)
    DiagnosticableTree (diagnostics.dart)
        Widget (framework.dart)
            RenderObjectWidget (framework.dart)
                _ChipRenderWidget (chip.dart)
                _CupertinoAlertRenderWidget (action_sheet.dart)
                _CupertinoDialogRenderWidget (dialog.dart)
                _Decorator (input_decorator.dart)
                _ListTile (list_tile.dart)
                _SliverPersistentHeaderRenderObjectWidget (sliver_persistent_header.dart)
                    _SliverFloatingPersistentHeader (sliver_persistent_header.dart)
                    _SliverFloatingPinnedPersistentHeader (sliver_persistent_header.dart)
                    _SliverPinnedPersistentHeader (sliver_persistent_header.dart)
                    _SliverScrollingPersistentHeader (sliver_persistent_header.dart)
                _Theatre (overlay.dart)
                LayoutBuilder (layout_builder.dart)
                LeafRenderObjectWidget (framework.dart)
                    _AndroidPlatformView (platform_view.dart)
                    _CheckboxRenderObjectWidget (checkbox.dart)
                    _CupertinoSliderRenderObjectWidget (slider.dart)
                    _CupertinoSwitchRenderObjectWidget (switch.dart)
                    _Editable (editable_text.dart)
                    _InspectorOverlay (widget_inspector.dart)
                    _RadioRenderObjectWidget (radio.dart)
                    _SliderRenderObjectWidget (slider.dart)
                    _SwitchRenderObjectWidget (switch.dart)
                    _UiKitPlatformView (platform_view.dart)
                    ErrorWidget (framework.dart)
                    PerformanceOverlay (performance_overlay.dart)
                    RawImage (basic.dart)
                    RichText (basic.dart)
                    Texture (texture.dart)
                    WidgetToRenderBoxAdapter (basic.dart)
                ListWheelViewport (list_wheel_scroll_view.dart)
                MultiChildRenderObjectWidget (framework.dart)
                    _CupertinoAlertActionsRenderWidget (action_sheet.dart)
                    _CupertinoDialogActionsRenderWidget (dialog.dart)
                    _SegmentedControlRenderWidget (segmented_control.dart)
                    CustomMultiChildLayout (basic.dart)
                    Flex (basic.dart)
                        _TabLabelBar (tabs.dart)
                        Column (basic.dart)
                        Row (basic.dart)
                    Flow (basic.dart)
                    ListBody (basic.dart)
                        _MergeableMaterialListBody (mergeable_material.dart)
                    ShrinkWrappingViewport (viewport.dart)
                    Stack (basic.dart)
                        IndexedStack (basic.dart)
                    Viewport (viewport.dart)
                        NestedScrollViewViewport (nested_scroll_view.dart)
                    Wrap (basic.dart)
                RenderObjectToWidgetAdapter (binding.dart)
                SingleChildRenderObjectWidget (framework.dart)
                    _ChildOverflowBox (floating_action_button.dart)
                    _ChipRedirectingHitDetectionWidget (chip.dart)
                    _CupertinoPickerSemantics (picker.dart)
                    _CupertinoSliverRefresh (refresh.dart)
                    _GestureSemantics (gesture_detector.dart)
                    _InkFeatures (material.dart)
                    _InputPadding (button.dart)
                    _ScrollSemantics (scrollable.dart)
                    _SingleChildViewport (single_child_scroll_view.dart)
                    AbsorbPointer (basic.dart)
                    Align (basic.dart)
                        Center (basic.dart)
                    AnimatedSize (animated_size.dart)
                    AnnotatedRegion (annotated_region.dart)
                    AspectRatio (basic.dart)
                    BackdropFilter (basic.dart)
                    Baseline (basic.dart)
                    BlockSemantics (basic.dart)
                    ClipOval (basic.dart)
                    ClipPath (basic.dart)
                    ClipRect (basic.dart)
                    ClipRRect (basic.dart)
                    CompositedTransformFollower (basic.dart)
                    CompositedTransformTarget (basic.dart)
                    ConstrainedBox (basic.dart)
                    CustomPaint (basic.dart)
                    CustomSingleChildLayout (basic.dart)
                    DecoratedBox (container.dart)
                    ExcludeSemantics (basic.dart)
                    FadeTransition (transitions.dart)
                    FittedBox (basic.dart)
                    FractionallySizedBox (basic.dart)
                    FractionalTranslation (basic.dart)
                    IgnorePointer (basic.dart)
                    IndexedSemantics (basic.dart)
                    IntrinsicHeight (basic.dart)
                    IntrinsicWidth (basic.dart)
                    LimitedBox (basic.dart)
                    Listener (basic.dart)
                    MergeSemantics (basic.dart)
                    MetaData (basic.dart)
                    Offstage (basic.dart)
                    Opacity (basic.dart)
                    OverflowBox (basic.dart)
                    Padding (basic.dart)
                    PhysicalModel (basic.dart)
                    PhysicalShape (basic.dart)
                    RepaintBoundary (basic.dart)
                    RotatedBox (basic.dart)
                    Semantics (basic.dart)
                    ShaderMask (basic.dart)
                    SizeChangedLayoutNotifier (size_changed_layout_notifier.dart)
                    SizedBox (basic.dart)
                    SizedOverflowBox (basic.dart)
                    SliverFillRemaining (sliver.dart)
                    SliverOverlapAbsorber (nested_scroll_view.dart)
                    SliverOverlapInjector (nested_scroll_view.dart)
                    SliverPadding (basic.dart)
                    SliverToBoxAdapter (basic.dart)
                    Transform (basic.dart)
                    UnconstrainedBox (basic.dart)
                SliverWithKeepAliveWidget (sliver.dart)
                    SliverMultiBoxAdaptorWidget (sliver.dart)
                        SliverFillViewport (sliver.dart)
                        SliverFixedExtentList (sliver.dart)
                        SliverGrid (sliver.dart)
                        SliverList (sliver.dart)
                        SliverPrototypeExtentList (sliver_prototype_extent_list.dart)
                Table (table.dart)

StatefulWidget

Diagnosticable (diagnostics.dart)
    DiagnosticableTree (diagnostics.dart)
        Widget (framework.dart)
            StatefulWidget (framework.dart)
                _AccountDetails (user_accounts_drawer_header.dart)
                _BorderContainer (input_decorator.dart)
                _CupertinoActionSheetCancelButton (action_sheet.dart)
                _CupertinoAlertActionSection (action_sheet.dart)
                _CupertinoAlertActionSection (dialog.dart)
                _CupertinoBackGestureDetector (route.dart)
                _DatePickerDialog (date_picker.dart)
                _Dial (time_picker.dart)
                _DropdownMenu (dropdown.dart)
                _FloatingActionButtonTransition (scaffold.dart)
                _FloatingAppBar (app_bar.dart)
                _HelperError (input_decorator.dart)
                _ModalBottomSheet (bottom_sheet.dart)
                _ModalScope (routes.dart)
                _OutlineButton (outline_button.dart)
                _OverlayEntry (overlay.dart)
                _PersistentBottomSheet (scaffold.dart)
                _PressableActionButton (action_sheet.dart)
                _PressableActionButton (dialog.dart)
                _ReorderableListContent (reorderable_list.dart)
                _SearchPage (search.dart)
                _SortArrow (data_table.dart)
                _TabSwitchingView (tab_scaffold.dart)
                _TextSelectionHandleOverlay (text_selection.dart)
                _TimePickerDialog (time_picker.dart)
                AndroidView (platform_view.dart)
                AnimatedCrossFade (animated_cross_fade.dart)
                AnimatedList (animated_list.dart)
                AnimatedSwitcher (animated_switcher.dart)
                AnimatedWidget (transitions.dart)
                    _Shaker (input_decorator.dart)
                    _TabStyle (tabs.dart)
                    AlignTransition (transitions.dart)
                    AnimatedBuilder (transitions.dart)
                    AnimatedModalBarrier (modal_barrier.dart)
                    DecoratedBoxTransition (transitions.dart)
                    DefaultTextStyleTransition (transitions.dart)
                    PositionedTransition (transitions.dart)
                    RelativePositionedTransition (transitions.dart)
                    RotationTransition (transitions.dart)
                    ScaleTransition (transitions.dart)
                    SizeTransition (transitions.dart)
                    SlideTransition (transitions.dart)
                AppBar (app_bar.dart)
                AutomaticKeepAlive (automatic_keep_alive.dart)
                BottomAppBar (bottom_app_bar.dart)
                BottomNavigationBar (bottom_navigation_bar.dart)
                BottomSheet (bottom_sheet.dart)
                Checkbox (checkbox.dart)
                CupertinoActivityIndicator (activity_indicator.dart)
                CupertinoApp (app.dart)
                CupertinoButton (button.dart)
                CupertinoDatePicker (date_picker.dart)
                CupertinoNavigationBar (nav_bar.dart)
                CupertinoPageScaffold (page_scaffold.dart)
                CupertinoPicker (picker.dart)
                CupertinoScrollbar (scrollbar.dart)
                CupertinoSegmentedControl (segmented_control.dart)
                CupertinoSlider (slider.dart)
                CupertinoSliverNavigationBar (nav_bar.dart)
                CupertinoSliverRefreshControl (refresh.dart)
                CupertinoSwitch (switch.dart)
                CupertinoTabScaffold (tab_scaffold.dart)
                CupertinoTabView (tab_view.dart)
                CupertinoTextField (text_field.dart)
                CupertinoTimerPicker (date_picker.dart)
                DefaultTabController (tab_controller.dart)
                Dismissible (dismissible.dart)
                Draggable (drag_target.dart)
                    LongPressDraggable (drag_target.dart)
                DraggableScrollableSheet (draggable_scrollable_sheet.dart)
                DragTarget (drag_target.dart)
                DrawerController (drawer.dart)
                DropdownButton (dropdown.dart)
                EditableText (editable_text.dart)
                ExpandIcon (expand_icon.dart)
                ExpansionPanelList (expansion_panel.dart)
                ExpansionTile (expansion_tile.dart)
                FadeInImage (fade_in_image.dart)
                FlexibleSpaceBar (flexible_space_bar.dart)
                FocusScope (focus_scope.dart)
                Form (form.dart)
                FormField (form.dart)
                    DropdownButtonFormField (dropdown.dart)
                    TextFormField (text_form_field.dart)
                FutureBuilder (async.dart)
                GlowingOverscrollIndicator (overscroll_indicator.dart)
                Hero (heroes.dart)
                Image (image.dart)
                ImplicitlyAnimatedWidget (implicit_animations.dart)
                    _MaterialInterior (material.dart)
                    AnimatedAlign (implicit_animations.dart)
                    AnimatedContainer (implicit_animations.dart)
                    AnimatedDefaultTextStyle (implicit_animations.dart)
                    AnimatedOpacity (implicit_animations.dart)
                    AnimatedPadding (implicit_animations.dart)
                    AnimatedPhysicalModel (implicit_animations.dart)
                    AnimatedPositioned (implicit_animations.dart)
                    AnimatedPositionedDirectional (implicit_animations.dart)
                    AnimatedTheme (theme.dart)
                Ink (ink_decoration.dart)
                InkResponse (ink_well.dart)
                    InkWell (ink_well.dart)
                    TableRowInkWell (data_table.dart)
                InputDecorator (input_decorator.dart)
                LicensePage (about.dart)
                ListWheelScrollView (list_wheel_scroll_view.dart)
                Localizations (localizations.dart)
                Material (material.dart)
                MaterialApp (app.dart)
                MergeableMaterial (mergeable_material.dart)
                MonthPicker (date_picker.dart)
                Navigator (navigator.dart)
                NestedScrollView (nested_scroll_view.dart)
                Overlay (overlay.dart)
                PageView (page_view.dart)
                PaginatedDataTable (paginated_data_table.dart)
                PopupMenuButton (popup_menu.dart)
                PopupMenuEntry (popup_menu.dart)
                    PopupMenuDivider (popup_menu.dart)
                    PopupMenuItem (popup_menu.dart)
                        CheckedPopupMenuItem (popup_menu.dart)
                ProgressIndicator (progress_indicator.dart)
                    CircularProgressIndicator (progress_indicator.dart)
                        RefreshProgressIndicator (progress_indicator.dart)
                    LinearProgressIndicator (progress_indicator.dart)
                Radio (radio.dart)
                RawChip (chip.dart)
                RawGestureDetector (gesture_detector.dart)
                RawKeyboardListener (raw_keyboard_listener.dart)
                RawMaterialButton (button.dart)
                RefreshIndicator (refresh_indicator.dart)
                ReorderableListView (reorderable_list.dart)
                Scaffold (scaffold.dart)
                Scrollable (scrollable.dart)
                    _FixedExtentScrollable (list_wheel_scroll_view.dart)
                Scrollbar (scrollbar.dart)
                SemanticsDebugger (semantics_debugger.dart)
                Slider (slider.dart)
                SliverAppBar (app_bar.dart)
                SnackBarAction (snack_bar.dart)
                StatefulBuilder (basic.dart)
                StatusTransitionWidget (status_transitions.dart)
                Stepper (stepper.dart)
                StreamBuilderBase (async.dart)
                    StreamBuilder (async.dart)
                Switch (switch.dart)
                TabBar (tabs.dart)
                TabBarView (tabs.dart)
                TextField (text_field.dart)
                TextSelectionGestureDetector (text_selection.dart)
                Tooltip (tooltip.dart)
                UiKitView (platform_view.dart)
                UniqueWidget (unique_widget.dart)
                UserAccountsDrawerHeader (user_accounts_drawer_header.dart)
                ValueListenableBuilder (value_listenable_builder.dart)
                WidgetInspector (widget_inspector.dart)
                WidgetsApp (app.dart)
                WillPopScope (will_pop_scope.dart)
                YearPicker (date_picker.dart)

StatelessWidget

Diagnosticable (diagnostics.dart)
    DiagnosticableTree (diagnostics.dart)
        Widget (framework.dart)
            StatelessWidget (framework.dart)
                _AccountPictures (user_accounts_drawer_header.dart)
                _AffixText (input_decorator.dart)
                _BackChevron (nav_bar.dart)
                _BackLabel (nav_bar.dart)
                _BodyBuilder (scaffold.dart)
                _BottomNavigationTile (bottom_navigation_bar.dart)
                _CupertinoAlertContentSection (action_sheet.dart)
                _CupertinoAlertContentSection (dialog.dart)
                _DateHeaderButton (date_picker.dart)
                _DatePickerHeader (date_picker.dart)
                _DayPeriodControl (time_picker.dart)
                _DropdownRoutePage (dropdown.dart)
                _FadeUpwardsPageTransition (page_transitions_theme.dart)
                _HourControl (time_picker.dart)
                _Label (bottom_navigation_bar.dart)
                _MinuteControl (time_picker.dart)
                _NavigationBarTransition (nav_bar.dart)
                _OpenUpwardsPageTransition (page_transitions_theme.dart)
                _PersistentNavigationBar (nav_bar.dart)
                _PopupMenu (popup_menu.dart)
                _ShapeBorderPaint (material.dart)
                _StringFragment (time_picker.dart)
                _TextSelectionToolbar (text_selection.dart)
                _TextSelectionToolbar (text_selection.dart)
                _TileIcon (bottom_navigation_bar.dart)
                _TimePickerHeader (time_picker.dart)
                _TooltipOverlay (tooltip.dart)
                _TransitionableNavigationBar (nav_bar.dart)
                AboutDialog (about.dart)
                AboutListTile (about.dart)
                ActionChip (chip.dart)
                AlertDialog (dialog.dart)
                AnimatedIcon (material_animated_icons)
                BackButton (back_button.dart)
                BackButtonIcon (back_button.dart)
                Banner (banner.dart)
                Builder (basic.dart)
                ButtonBar (button_bar.dart)
                Card (card.dart)
                CheckboxListTile (checkbox_list_tile.dart)
                CheckedModeBanner (banner.dart)
                Chip (chip.dart)
                ChoiceChip (chip.dart)
                CircleAvatar (circle_avatar.dart)
                CloseButton (back_button.dart)
                Container (container.dart)
                CupertinoActionSheet (action_sheet.dart)
                CupertinoActionSheetAction (action_sheet.dart)
                CupertinoAlertDialog (dialog.dart)
                CupertinoDialog (dialog.dart)
                CupertinoDialogAction (dialog.dart)
                CupertinoFullscreenDialogTransition (route.dart)
                CupertinoNavigationBarBackButton (nav_bar.dart)
                CupertinoPageTransition (route.dart)
                CupertinoPopupSurface (dialog.dart)
                CupertinoTabBar (bottom_tab_bar.dart)
                CupertinoTheme (theme.dart)
                DataTable (data_table.dart)
                DayPicker (date_picker.dart)
                Dialog (dialog.dart)
                Divider (divider.dart)
                Drawer (drawer.dart)
                DrawerHeader (drawer_header.dart)
                DropdownMenuItem (dropdown.dart)
                FilterChip (chip.dart)
                FloatingActionButton (floating_action_button.dart)
                FlutterLogo (flutter_logo.dart)
                GestureDetector (gesture_detector.dart)
                GridPaper (grid_paper.dart)
                GridTile (grid_tile.dart)
                GridTileBar (grid_tile_bar.dart)
                Icon (icon.dart)
                IconButton (icon_button.dart)
                ImageIcon (image_icon.dart)
                InputChip (chip.dart)
                KeyedSubtree (basic.dart)
                ListTile (list_tile.dart)
                MaterialButton (material_button.dart)
                    FlatButton (flat_button.dart)
                        _FlatButtonWithIcon (flat_button.dart)
                    OutlineButton (outline_button.dart)
                        _OutlineButtonWithIcon (outline_button.dart)
                    RaisedButton (raised_button.dart)
                        _RaisedButtonWithIcon (raised_button.dart)
                ModalBarrier (modal_barrier.dart)
                NavigationToolbar (navigation_toolbar.dart)
                NotificationListener (notification_listener.dart)
                OrientationBuilder (orientation_builder.dart)
                PageStorage (page_storage.dart)
                Placeholder (placeholder.dart)
                PositionedDirectional (basic.dart)
                PreferredSize (preferred_size.dart)
                RadioListTile (radio_list_tile.dart)
                SafeArea (safe_area.dart)
                ScrollView (scroll_view.dart)
                    BoxScrollView (scroll_view.dart)
                        GridView (scroll_view.dart)
                        ListView (scroll_view.dart)
                    CustomScrollView (scroll_view.dart)
                        _NestedScrollViewCustomScrollView (nested_scroll_view.dart)
                SimpleDialog (dialog.dart)
                SimpleDialogOption (dialog.dart)
                SingleChildScrollView (single_child_scroll_view.dart)
                SliverPersistentHeader (sliver_persistent_header.dart)
                SliverSafeArea (safe_area.dart)
                SnackBar (snack_bar.dart)
                Spacer (spacer.dart)
                SwitchListTile (switch_list_tile.dart)
                Tab (tabs.dart)
                TabPageSelector (tabs.dart)
                TabPageSelectorIndicator (tabs.dart)
                Text (text.dart)
                Theme (theme.dart)
                Title (title.dart)
                VerticalDivider (divider.dart)
                Visibility (visibility.dart)

示例:

import 'package:flutter/material.dart';

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

class MyApp extends StatelessWidget {
  @override
  Widget build(BuildContext context) {
    return MaterialApp(
        title: 'Flutter应用title',
        // 设置这一属性即可去除右上角Debug标签
        debugShowCheckedModeBanner: false,
        theme: ThemeData(
            //主题色
            primarySwatch: Colors.green,
            backgroundColor: Colors.deepOrangeAccent,
            primaryColor: Colors.amber,
            accentColor: Colors.cyanAccent),
        home: MyHomePage(),
        routes: {
          '/home': (BuildContext context) => MyHomePage(),
          '/detail': (BuildContext context) => DetailPage()
        });
  }
}

class MyHomePage extends StatefulWidget {
  @override
  State createState() {
    return _MyHomeState();
  }
}

class _MyHomeState extends State {
  var _pages = [];
  var _tabIndex = 0;

  @override
  void initState() {
    _pages
      ..add(MyColumn())
      ..add(MyTabBar())
      ..add(MyText("333"))
      ..add(MyText("444"));
    super.initState();
  }

  @override
  Widget build(BuildContext context) {
    return Scaffold(
      appBar: AppBar(
        leading: new Builder(builder: (BuildContext context) {
          return GestureDetector(
            child: Icon(
              Icons.arrow_back,
              color: Colors.white,
            ),
            onTap: () {
              print("==========onTap");
            },
            onLongPress: () {
              print("=============onLongPress");
            },
            onDoubleTap: () {
              print("=============onDoubleTap");
              Scaffold.of(context)
                  .showSnackBar(new SnackBar(content: Text("onDoubleTap")));
            },
          );
        }),
        title: Text('flutter页面Title'),
        centerTitle: true,
      ),
      body: _pages[_tabIndex],
      // 页面底部的导航栏
      bottomNavigationBar: BottomNavigationBar(
        type: BottomNavigationBarType.fixed,
        iconSize: 24.0,
        currentIndex: _tabIndex,
        onTap: (int index) {
          setState(() {
            _tabIndex = index;
          });
        },
        fixedColor: Colors.deepPurple,
        items: [
          BottomNavigationBarItem(
              title: Text("Home"),
              icon: Icon(Icons.home),
              backgroundColor: Colors.green),
          BottomNavigationBarItem(
              title: Text("List"),
              icon: Icon(Icons.list),
              backgroundColor: Colors.deepPurple),
          BottomNavigationBarItem(
              title: Text("Menu"),
              icon: Icon(Icons.menu),
              backgroundColor: Colors.deepOrangeAccent),
          BottomNavigationBarItem(
            title: Text("Other"),
            icon: Icon(Icons.devices_other),
            backgroundColor: Colors.lightBlue,
          ),
        ],
      ),
      drawer: Drawer(
          child: Column(
        children: [
          DrawerItem(1, '列表1'),
          DrawerItem(2, '列表2'),
          DrawerItem(3, '列表3'),
          DrawerItem(4, '列表4'),
          DrawerItem(5, '列表5')
        ],
      )),
      floatingActionButton: FloatingActionButton(
        onPressed: () => Navigator.of(context)
            .push(MaterialPageRoute(builder: (context) => DetailPage())),
        child: Icon(Icons.navigate_next),
      ),
    );
  }
}

class MyTabBar extends StatefulWidget {
  @override
  State createState() {
    return _MyTabBarState();
  }
}

class _MyTabBarState extends State
    with SingleTickerProviderStateMixin {
//  ScrollController _scrollController;
  TabController _tabController;

  @override
  void initState() {
    super.initState();
//    _scrollController = ScrollController();
    _tabController = TabController(length: 6, vsync: this);
  }

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

  @override
  Widget build(BuildContext context) {
    return SizedBox(
      height: 800,
      child: Scaffold(
        body: TabBarView(controller: _tabController, children: [
          Text("TabBarView1"),
          Text("TabBarView2"),
          Text("TabBarView3"),
          Text("TabBarView4"),
          Text("TabBarView5"),
          Text("TabBarView6"),
        ]),
        appBar: AppBar(
          title: Text("title"),
          leading: Icon(Icons.home),
          backgroundColor: Colors.amber,
          bottom: TabBar(
              isScrollable: true,
              controller: _tabController,
              tabs: [
                Tab(
                  text: "tab1",
                ),
                Tab(
                  text: "tab2",
                ),
                Tab(
                  text: "tab3",
                ),
                Tab(
                  text: "tab4",
                ),
                Tab(
                  text: "tab5",
                ),
                Tab(
                  text: "tab6",
                ),
              ]),
        ),
      ),
    );
  }
}

class DetailPage extends StatelessWidget {
  @override
  Widget build(BuildContext context) {
    return Center(
        child: GestureDetector(
            onTap: () {
              Navigator.pushNamed(context, '/home');
            },
            child: Text('详情页,点击跳转首页',
                style: TextStyle(
                    fontSize: 20.0,
                    color: Colors.white,
                    decoration: TextDecoration.none))));
  }
}

class DrawerItem extends StatelessWidget {
  final int id;
  final String name;

  DrawerItem(this.id, this.name);

  @override
  Widget build(BuildContext context) {
    return Container(
      decoration: BoxDecoration(
        color: Colors.white,
        border:
            Border(bottom: BorderSide(width: 0.5, color: Color(0xFFd9d9d9))),
      ),
      height: 52.0,
      child: FlatButton(
          onPressed: () {},
          child: Row(
            crossAxisAlignment: CrossAxisAlignment.center,
            children: [Text(id.toString()), Text(' - '), Text(name)],
          )),
    );
  }
}

class MyText extends StatelessWidget {
  var data = "";

  MyText(this.data);

  @override
  Widget build(BuildContext context) {
    return Center(
      child: Text(data),
    );
  }
}

class MyColumn extends StatelessWidget {
  @override
  Widget build(BuildContext context) {
    return Column(
      mainAxisAlignment: MainAxisAlignment.center,
      children: [
        Center(
            child: GestureDetector(
                onTap: () {
                  Navigator.pushNamed(context, '/detail');
                },
                child: Text('首页,点击跳转详情页',
                    style: TextStyle(
                        fontSize: 20.0,
                        color: Colors.red,
                        decoration: TextDecoration.none)))),
        Builder(
          //如果 build 函数返回一个 Scaffold 对象,则由于 Scaffold 对象是这个 Widget 的子对象,
          // 所以使用这个 build 的 BuildContext 参数是不能查找到 ScaffoldState 对象的,
          // 这个时候,通过在 Scaffold 中使用一个 Builder 来提供一个新的 BuildConext :
          // Create an inner BuildContext so that the onPressed methods
          // can refer to the Scaffold with Scaffold.of().
          builder: (BuildContext context) {
            return new Center(
              child: new RaisedButton(
                child: new Text('SHOW A SNACKBAR'),
                onPressed: () {
                  Scaffold.of(context).showSnackBar(new SnackBar(
                    content: new Text('Hello!'),
                  ));
                },
              ),
            );
          },
        ),
      ],
    );
  }
}

你可能感兴趣的:(flutter)