搜索插件、代码仓与 APP 分类

插件详情v2.0.1

mobile_sidebar

一个遵循 Material Design 的 Flutter 响应式侧边栏

近 30 天下载
27
喜欢数
31
Pub 分数
40

安装插件

flutter pub add mobile_sidebar

插件介绍

基于插件公开信息、社区数据与项目使用情况整理的选型参考。

一个符合 Material Design 指南的响应式侧边栏,可随屏幕尺寸动态调整布局,在各种设备上提供最佳导航体验。适用于需要一致且易于访问导航的应用程序,支持移动和桌面布局,并具有平滑的过渡效果。该包简化了可折叠侧边栏的实现,同时不牺牲设计保真度或可用性。

适合场景

  • 移动和桌面应用程序导航
  • 响应式 UI 与自适应布局
  • 跨设备的一致抽屉体验
  • 集成 Material Design 导航模式
  • 使用侧边栏菜单构建管理仪表板

主要特点

  • 符合 Material Design
  • 自动适应屏幕尺寸
  • 可折叠和可展开状态
  • 平滑过渡动画
  • 与现有 Flutter 应用轻松集成

适合对象

  • 开发响应式 Flutter 应用的开发者
  • 优先考虑 Material Design 一致性的团队
  • 需要可适应导航结构的项目
  • 面向多种设备形态的应用程序

使用建议

  • 超出 Material Design 的自定义功能有限
  • 无内置的从右到左布局支持
  • 需要手动处理状态管理
  • 未针对复杂的嵌套导航进行优化

原始 README

以下为关联源码仓库的 README 原文快照,最新内容请访问源码仓库。

Buy Me A Coffee Donate

mobile_sidebar

A Flutter plugin to show a sidebar on tablet and desktop then a list or gridview on mobile.

Demo here.

Screenshots

Example

import 'package:flutter/foundation.dart';
import 'package:flutter/material.dart';
import 'package:flutter/widgets.dart';

import 'package:mobile_sidebar/mobile_sidebar.dart';

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

class MyApp extends StatelessWidget {
  @override
  Widget build(BuildContext context) {
    return MaterialApp(
      debugShowCheckedModeBanner: false,
      theme: ThemeData.light(),
      home: HomeScreen(),
    );
  }
}

class HomeScreen extends StatefulWidget {
  @override
  _HomeScreenState createState() => _HomeScreenState();
}

class _HomeScreenState extends State<HomeScreen> {
  int index = 0;
  bool searching = false;
  bool _loggedIn = false;
  @override
  Widget build(BuildContext context) {
    return Scaffold(
      body: MobileSidebar(
        currentIndex: index,
        onTabChanged: (val) {
          if (mounted)
            setState(() {
              index = val;
            });
        },
        isSearching: searching,
        isSearchChanged: (val) {
          if (mounted)
            setState(() {
              searching = val;
            });
        },
        titleBuilder: (context) {
          return FancyTitle(
            title: Text("My Logo"),
            logo: FlutterLogo(),
          );
        },
        accountBuilder: (context) {
          if (_loggedIn) {
            return Padding(
              padding: const EdgeInsets.all(8.0),
              child: InkWell(
                onTap: () {
                  if (mounted)
                    setState(() {
                      _loggedIn = false;
                    });
                },
                child: CircleAvatar(
                  child: Icon(Icons.person),
                ),
              ),
            );
          }
          return FlatButton(
            child: Text("Sign In"),
            onPressed: () {
              if (mounted)
                setState(() {
                  _loggedIn = true;
                });
            },
          );
        },
        showSearchButton: true,
        tabs: <TabChild>[
          TabChild(
            icon: Icon(Icons.bluetooth),
            title: 'Light Blue',
            builder: (context) => NewScreen(
              color: Colors.lightBlue,
              name: 'Light Blue Screen',
            ),
          ),
          TabChild(
            icon: Icon(Icons.info),
            title: 'Light Green',
            builder: (context) => NewScreen(
              color: Colors.lightGreen,
              name: 'Light Green Screen',
            ),
          ),
          TabChild(
            icon: Icon(Icons.person),
            title: 'Red',
            builder: (context) => NewScreen(
              color: Colors.red,
              name: 'Red Screen',
            ),
          ),
          TabChild(
            icon: Icon(Icons.info),
            title: 'Light Green 3',
            builder: (context) => NewScreen(
              color: Colors.lightGreen,
              name: 'Light Green Screen',
            ),
          ),
          TabChild(
            icon: Icon(Icons.person),
            title: 'Red 3',
            builder: (context) => NewScreen(
              color: Colors.red,
              name: 'Red Screen',
            ),
          ),
          TabChild(
            icon: Icon(Icons.info),
            title: 'Light Green 4',
            builder: (context) => NewScreen(
              color: Colors.lightGreen,
              name: 'Light Green Screen',
            ),
          ),
          TabChild(
            icon: Icon(Icons.person),
            title: 'Red 4',
            builder: (context) => NewScreen(
              color: Colors.red,
              name: 'Red Screen',
            ),
          ),
        ],
      ),
    );
  }
}

class FancyTitle extends StatelessWidget {
  const FancyTitle({
    Key key,
    @required this.title,
    this.logo,
  }) : super(key: key);

  final Widget title;
  final Widget logo;

  @override
  Widget build(BuildContext context) {
    if (logo == null) {
      return logo;
    }
    return Row(
      children: <Widget>[
        logo,
        Container(width: 4.0),
        title,
      ],
    );
  }
}

class NewScreen extends StatelessWidget {
  const NewScreen({
    Key key,
    @required this.color,
    @required this.name,
  }) : super(key: key);

  final Color color;
  final String name;

  @override
  Widget build(BuildContext context) {
    return Container(
      color: color,
      child: Center(
        child: RaisedButton.icon(
          icon: Icon(Icons.arrow_right),
          label: Text("Push to Screen"),
          onPressed: () {
            Navigator.of(context).push(MaterialPageRoute(
              builder: (_) => Scaffold(
                appBar: AppBar(),
                body: NewScreen(color: color, name: name),
              ),
            ));
          },
        ),
      ),
    );
  }
}

所属分类

依赖

依赖清单 1 项

源码仓库

使用此插件的项目

暂无相关数据。