Skip to content

Commit a61b81e

Browse files
committed
update project struct
1 parent f6d950a commit a61b81e

File tree

10 files changed

+612
-611
lines changed

10 files changed

+612
-611
lines changed

.idea/workspace.xml

Lines changed: 102 additions & 143 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

README.md

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -10,13 +10,20 @@ A dropdown menu for Flutter.
1010

1111
![showcase](https://github.com/jzoom/images/raw/master/dropdown_menu2.gif)
1212

13+
14+
## Table of contents
15+
16+
1317
## Installion
1418

19+
```
20+
dropdown_menu: ^1.1.0
1521
```
1622

17-
dropdown_menu : ^1.1.0
23+
## Build simple list menu
24+
## Build tree menu
25+
## Build custom menu
1826

19-
```
2027

2128
## Examples
2229

example/lib/main.dart

Lines changed: 70 additions & 73 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,8 @@
11
import 'dart:async';
22

33
import 'package:flutter/material.dart';
4-
import 'package:dropdown_menu/dropdown_header.dart';
5-
import 'dart:math' as math;
6-
import 'package:dropdown_menu/dropdown_templates.dart';
7-
import 'package:dropdown_menu/dropdown_sliver.dart';
84
import 'package:dropdown_menu/dropdown_menu.dart';
9-
import 'package:dropdown_menu/dropdown_list_menu.dart';
5+
import 'dart:math' as math;
106
import 'dart:io';
117
import 'dart:convert';
128

@@ -19,8 +15,7 @@ class MyApp extends StatelessWidget {
1915
return new MaterialApp(
2016
title: 'Flutter Demo',
2117
theme: new ThemeData(
22-
primarySwatch: Colors.blue,
23-
scaffoldBackgroundColor: Colors.white),
18+
primarySwatch: Colors.blue, scaffoldBackgroundColor: Colors.white),
2419
home: new MyHomePage(title: 'Flutter Demo Home Page'),
2520
);
2621
}
@@ -138,76 +133,78 @@ class _MyHomePageState extends State<MyHomePage> {
138133
);
139134
},
140135
height: kDropdownMenuItemHeight * ORDERS.length),
141-
new DropdownMenuBuilder(builder: (BuildContext context) {
142-
return new DropdownTreeMenu(
143-
selectedIndex: 0,
144-
subSelectedIndex: 0,
145-
itemExtent: 45.0,
146-
background: Colors.red,
147-
subBackground: Colors.blueAccent,
148-
itemBuilder: (BuildContext context, dynamic data, bool selected) {
149-
if (!selected) {
150-
return new DecoratedBox(
151-
decoration: new BoxDecoration(
152-
border: new Border(
153-
right: Divider.createBorderSide(context))),
154-
child: new Padding(
155-
padding: const EdgeInsets.only(left: 15.0),
156-
child: new Row(
157-
children: <Widget>[
158-
new Text(data['title']),
159-
],
160-
)));
161-
} else {
162-
return new DecoratedBox(
163-
decoration: new BoxDecoration(
164-
border: new Border(
165-
top: Divider.createBorderSide(context),
166-
bottom: Divider.createBorderSide(context))),
167-
child: new Container(
168-
color: Theme.of(context).scaffoldBackgroundColor,
169-
child: new Row(
170-
children: <Widget>[
171-
new Container(
172-
color: Theme.of(context).primaryColor,
173-
width: 3.0,
174-
height: 20.0),
175-
new Padding(
176-
padding: new EdgeInsets.only(left: 12.0),
177-
child: new Text(data['title'])),
178-
],
179-
)));
180-
}
181-
},
182-
subItemBuilder:
183-
(BuildContext context, dynamic data, bool selected) {
184-
Color color = selected
185-
? Theme.of(context).primaryColor
186-
: Theme.of(context).textTheme.body1.color;
136+
new DropdownMenuBuilder(
137+
builder: (BuildContext context) {
138+
return new DropdownTreeMenu(
139+
selectedIndex: 0,
140+
subSelectedIndex: 0,
141+
itemExtent: 45.0,
142+
background: Colors.red,
143+
subBackground: Colors.blueAccent,
144+
itemBuilder:
145+
(BuildContext context, dynamic data, bool selected) {
146+
if (!selected) {
147+
return new DecoratedBox(
148+
decoration: new BoxDecoration(
149+
border: new Border(
150+
right: Divider.createBorderSide(context))),
151+
child: new Padding(
152+
padding: const EdgeInsets.only(left: 15.0),
153+
child: new Row(
154+
children: <Widget>[
155+
new Text(data['title']),
156+
],
157+
)));
158+
} else {
159+
return new DecoratedBox(
160+
decoration: new BoxDecoration(
161+
border: new Border(
162+
top: Divider.createBorderSide(context),
163+
bottom: Divider.createBorderSide(context))),
164+
child: new Container(
165+
color: Theme.of(context).scaffoldBackgroundColor,
166+
child: new Row(
167+
children: <Widget>[
168+
new Container(
169+
color: Theme.of(context).primaryColor,
170+
width: 3.0,
171+
height: 20.0),
172+
new Padding(
173+
padding: new EdgeInsets.only(left: 12.0),
174+
child: new Text(data['title'])),
175+
],
176+
)));
177+
}
178+
},
179+
subItemBuilder:
180+
(BuildContext context, dynamic data, bool selected) {
181+
Color color = selected
182+
? Theme.of(context).primaryColor
183+
: Theme.of(context).textTheme.body1.color;
187184

188-
return new SizedBox(
189-
height: 45.0,
190-
child: new Row(
191-
children: <Widget>[
192-
new Text(
193-
data['title'],
194-
style: new TextStyle(color: color),
185+
return new SizedBox(
186+
height: 45.0,
187+
child: new Row(
188+
children: <Widget>[
189+
new Text(
190+
data['title'],
191+
style: new TextStyle(color: color),
192+
),
193+
new Expanded(
194+
child: new Align(
195+
alignment: Alignment.centerRight,
196+
child: new Text(data['count'].toString())))
197+
],
195198
),
196-
new Expanded(
197-
child: new Align(
198-
alignment: Alignment.centerRight,
199-
child: new Text(data['count'].toString())))
200-
],
201-
),
199+
);
200+
},
201+
getSubData: (dynamic data) {
202+
return data['children'];
203+
},
204+
data: FOODS,
202205
);
203206
},
204-
getSubData: (dynamic data) {
205-
return data['children'];
206-
},
207-
data: FOODS,
208-
209-
);
210-
},height: 450.0)
207+
height: 450.0)
211208
]);
212209
}
213210

File renamed without changes.

lib/dropdown_header.dart renamed to lib/_src/dropdown_header.dart

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ import 'package:flutter/foundation.dart';
33

44
import 'package:flutter/material.dart';
55

6-
import 'package:dropdown_menu/drapdown_common.dart';
6+
import 'package:dropdown_menu/_src/drapdown_common.dart';
77

88
typedef void DropdownMenuHeadTapCallback(int index);
99

lib/dropdown_list_menu.dart renamed to lib/_src/dropdown_list_menu.dart

Lines changed: 63 additions & 36 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
import 'package:flutter/material.dart';
22
import 'package:flutter/widgets.dart';
33

4-
import 'package:dropdown_menu/drapdown_common.dart';
4+
import 'package:dropdown_menu/_src/drapdown_common.dart';
55

66
typedef Widget MenuItemBuilder<T>(BuildContext context, T data, bool selected);
77
typedef void MenuItemOnTap<T>(T data, int index);
@@ -36,12 +36,6 @@ class _MenuListState<T> extends DropdownState<DropdownListMenu<T>> {
3636
super.initState();
3737
}
3838

39-
@override
40-
void didChangeDependencies() {
41-
// TODO: implement didChangeDependencies
42-
super.didChangeDependencies();
43-
}
44-
4539
Widget buildItem(BuildContext context, int index) {
4640
final List<T> list = widget.data;
4741

@@ -53,10 +47,8 @@ class _MenuListState<T> extends DropdownState<DropdownListMenu<T>> {
5347
setState(() {
5448
_selectedIndex = index;
5549
});
56-
5750
assert(controller != null);
5851
controller.select(data, index: index);
59-
// if (onTap != null) onTap(data, index);
6052
},
6153
);
6254
}
@@ -84,30 +76,63 @@ class _MenuListState<T> extends DropdownState<DropdownListMenu<T>> {
8476
}
8577
}
8678

79+
/// This widget is just like this:
80+
/// ----------------|---------------------
81+
/// MainItem1 |SubItem1
82+
/// MainItem2 |SubItem2
83+
/// MainItem3 |SubItem3
84+
/// ----------------|---------------------
85+
/// When you tap "MainItem1", the sub list of this widget will
86+
/// 1. call `getSubData(widget.data[0])`, this will return a list of data for sub list
87+
/// 2. Refresh the sub list of the widget by using the list above.
88+
///
89+
///
8790
class DropdownTreeMenu<T, E> extends DropdownWidget {
91+
/// data from this widget
8892
final List<T> data;
93+
94+
/// selected index of main list
8995
final int selectedIndex;
96+
97+
/// item builder for main list
9098
final MenuItemBuilder<T> itemBuilder;
9199

100+
//selected index of sub list
92101
final int subSelectedIndex;
102+
103+
/// A function to build right item of the tree
93104
final MenuItemBuilder<E> subItemBuilder;
94105

106+
/// A callback to get sub list from left list data, eg.
107+
/// When you set List<MyData> to left,
108+
/// a callback (MyData data)=>data.children; must be provided
95109
final GetSubData<T, E> getSubData;
96110

111+
/// `itemExtent` of main list
97112
final double itemExtent;
98113

114+
/// `itemExtent` of sub list
115+
final double subItemExtent;
116+
117+
/// background for main list
99118
final Color background;
100119

120+
/// background for sub list
101121
final Color subBackground;
102122

123+
/// flex for main list
103124
final int flex;
125+
126+
/// flex for sub list,
127+
/// if `subFlex`==2 and `flex`==1,then sub list will be 2 times larger than main list
104128
final int subFlex;
105129

106130
DropdownTreeMenu({
107131
this.data,
108132
double itemExtent,
109133
this.selectedIndex,
110134
this.itemBuilder,
135+
this.subItemExtent,
111136
this.subItemBuilder,
112137
this.getSubData,
113138
this.background: const Color(0xfffafafa),
@@ -196,33 +221,35 @@ class _TreeMenuList<T, E> extends DropdownState<DropdownTreeMenu> {
196221
@override
197222
Widget build(BuildContext context) {
198223
return new Row(
199-
crossAxisAlignment: CrossAxisAlignment.start,
200-
children: <Widget>[
201-
new Expanded(
202-
flex: widget.flex,
203-
child: new Container(
204-
child: new ListView.builder(
205-
itemExtent: widget.itemExtent,
206-
itemBuilder: buildItem,
207-
itemCount: this._data == null ? 0 : this._data.length,
208-
),
209-
color: widget.background,
210-
)),
211-
new Expanded(
212-
flex: widget.subFlex,
213-
child: new Container(
214-
color: widget.subBackground,
215-
child: new CustomScrollView(
216-
slivers: <Widget>[
217-
new SliverList(
218-
delegate: new SliverChildBuilderDelegate( buildSubItem,childCount: this._subData == null ? 0 : this._subData.length,))
219-
],
220-
221-
222-
),
223-
))
224-
],
225-
);
224+
crossAxisAlignment: CrossAxisAlignment.start,
225+
children: <Widget>[
226+
new Expanded(
227+
flex: widget.flex,
228+
child: new Container(
229+
child: new ListView.builder(
230+
itemExtent: widget.itemExtent,
231+
itemBuilder: buildItem,
232+
itemCount: this._data == null ? 0 : this._data.length,
233+
),
234+
color: widget.background,
235+
)),
236+
new Expanded(
237+
flex: widget.subFlex,
238+
child: new Container(
239+
color: widget.subBackground,
240+
child: new CustomScrollView(
241+
slivers: <Widget>[
242+
new SliverList(
243+
delegate: new SliverChildBuilderDelegate(
244+
buildSubItem,
245+
childCount:
246+
this._subData == null ? 0 : this._subData.length,
247+
))
248+
],
249+
),
250+
))
251+
],
252+
);
226253
}
227254

228255
@override

0 commit comments

Comments
 (0)