flutter_sliding_up_panel 0.0.1 copy "flutter_sliding_up_panel: ^0.0.1" to clipboard
flutter_sliding_up_panel: ^0.0.1 copied to clipboard

outdated

A sliding up panel widget.

example/lib/main.dart

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

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

class MyApp extends StatefulWidget {
  @override
  State<StatefulWidget> createState() {
    // TODO: implement createState
    return _MyAppState();
  }
}

class _MyAppState extends State<MyApp> {
  bool showPerformance = false;

  onSettingCallback() {
    setState(() {
      showPerformance = !showPerformance;
    });
  }

  @override
  Widget build(BuildContext context) {
    // TODO: implement build
    final appTitle = 'Sliding up panel Example';
    return MaterialApp(
      title: appTitle,
      showPerformanceOverlay: showPerformance,
      home: LayoutBuilder(
        builder: (BuildContext context, BoxConstraints constraints) {
          return MyHomePage(
            title: appTitle,
            onSetting: onSettingCallback,
          );
        },
      ),
    );
  }
}

// The StatefulWidget's job is to take in some data and create a State class.
// In this case, the Widget takes a title, and creates a _MyHomePageState.
class MyHomePage extends StatefulWidget {
  final String title;

  final VoidCallback onSetting;

  MyHomePage({Key key, this.title, this.onSetting}) : super(key: key);

  @override
  _MyHomePageState createState() => _MyHomePageState();
}

// The State class is responsible for two things: holding some data you can
// update and building the UI using that data.
class _MyHomePageState extends State<MyHomePage> {
  // Whether the green box should be visible or invisible

  ScrollController scrollController;

  ///The controller of sliding up panel
  SlidingUpPanelController panelController = SlidingUpPanelController();

  @override
  void initState() {
    scrollController = ScrollController();
    scrollController.addListener(() {
      if (scrollController.offset >=
              scrollController.position.maxScrollExtent &&
          !scrollController.position.outOfRange) {
        panelController.expand();
      } else if (scrollController.offset <=
              scrollController.position.minScrollExtent &&
          !scrollController.position.outOfRange) {
        panelController.anchor();
      } else {}
    });
    super.initState();
  }

  @override
  Widget build(BuildContext context) {
    return Stack(
      children: <Widget>[
        Scaffold(
          appBar: AppBar(
            title: Text(widget.title),
            actions: <Widget>[
              IconButton(
                icon: Icon(Icons.settings),
                onPressed: () {
                  widget.onSetting?.call();
                },
              )
            ],
          ),
          body: Center(
            child: ListView(
              padding: EdgeInsets.symmetric(horizontal: 50.0),
              children: <Widget>[
                Padding(
                  padding: EdgeInsets.only(top: 50.0),
                ),
                RaisedButton(
                  child: Text('Show panel'),
                  onPressed: () {
                    panelController.expand();
                  },
                ),
                Padding(
                  padding: EdgeInsets.only(top: 50.0),
                ),
                RaisedButton(
                  child: Text('Anchor panel'),
                  onPressed: () {
                    panelController.anchor();
                  },
                ),
                Padding(
                  padding: EdgeInsets.only(top: 50.0),
                ),
                RaisedButton(
                  child: Text('Expand panel'),
                  onPressed: () {
                    panelController.expand();
                  },
                ),
                Padding(
                  padding: EdgeInsets.only(top: 50.0),
                ),
                RaisedButton(
                  child: Text('Collapse panel'),
                  onPressed: () {
                    panelController.collapse();
                  },
                ),
                Padding(
                  padding: EdgeInsets.only(top: 50.0),
                ),
                RaisedButton(
                  child: Text('Hide panel'),
                  onPressed: () {
                    panelController.hide();
                  },
                ),
              ],
            ),
          ),
        ),
        SlidingUpPanelWidget(
          child: Column(
            children: <Widget>[
              Container(
                color: Colors.white,
                alignment: Alignment.center,
                child: Row(
                  children: <Widget>[
                    Image.asset(
                      'assets/ic_menu_black_24dp.png',
                      width: 34.0,
                      height: 34.0,
                      fit: BoxFit.fill,
                    ),
                    Padding(
                      padding: EdgeInsets.only(
                        left: 8.0,
                      ),
                    ),
                    Text(
                      'click or drag',
                    )
                  ],
                  mainAxisAlignment: MainAxisAlignment.center,
                ),
                height: 50.0,
              ),
              Divider(
                height: 0.5,
                color: Colors.grey,
              ),
              Flexible(
                child: Container(
                  child: ListView.separated(
                    controller: scrollController,
                    physics: ClampingScrollPhysics(),
                    itemBuilder: (context, index) {
                      return ListTile(
                        title: Text('list item $index'),
                      );
                    },
                    separatorBuilder: (context, index) {
                      return Divider(
                        height: 0.5,
                      );
                    },
                    shrinkWrap: true,
                    itemCount: 20,
                  ),
                  color: Colors.white,
                ),
              ),
            ],
            mainAxisSize: MainAxisSize.min,
          ),
          controlHeight: 50.0,
          anchor: 0.4,
          panelController: panelController,
        ),
      ],
    );
  }
}