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

null-safety #130

Open
wants to merge 5 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
52 changes: 18 additions & 34 deletions example/lib/main.dart
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ class ExampleNumber {
};

String get numberString {
return (map.containsKey(number) ? map[number] : "unknown");
return (map.containsKey(number) ? map[number] ?? "unknown" : "unknown");
}

ExampleNumber(this.number);
Expand All @@ -51,8 +51,8 @@ class MyApp extends StatefulWidget {

class _MyAppState extends State<MyApp> {
bool asTabs = false;
String selectedValue;
String preselectedValue = "dolor sit";
String selectedValue = '';
String preselectedValue = 'dolor sit';
ExampleNumber selectedNumber;
List<int> selectedItems = [];
final List<DropdownMenuItem> items = [];
Expand All @@ -64,12 +64,7 @@ class _MyAppState extends State<MyApp> {
@override
void initState() {
String wordPair = "";
loremIpsum
.toLowerCase()
.replaceAll(",", "")
.replaceAll(".", "")
.split(" ")
.forEach((word) {
loremIpsum.toLowerCase().replaceAll(",", "").replaceAll(".", "").split(" ").forEach((word) {
if (wordPair.isEmpty) {
wordPair = word + " ";
} else {
Expand Down Expand Up @@ -217,7 +212,7 @@ class _MyAppState extends State<MyApp> {
))));
},
doneButton: (selectedItemsDone, doneContext) {
return (RaisedButton(
return (ElevatedButton(
onPressed: () {
Navigator.pop(doneContext);
setState(() {});
Expand All @@ -227,16 +222,12 @@ class _MyAppState extends State<MyApp> {
closeButton: null,
style: TextStyle(fontStyle: FontStyle.italic),
searchFn: (String keyword, items) {
List<int> ret = List<int>();
List<int> ret = <int>[];
if (keyword != null && items != null && keyword.isNotEmpty) {
keyword.split(" ").forEach((k) {
int i = 0;
items.forEach((item) {
if (k.isNotEmpty &&
(item.value
.toString()
.toLowerCase()
.contains(k.toLowerCase()))) {
if (k.isNotEmpty && (item.value.toString().toLowerCase().contains(k.toLowerCase()))) {
ret.add(i);
}
i++;
Expand All @@ -253,9 +244,7 @@ class _MyAppState extends State<MyApp> {
label: "Label for multi",
underline: Container(
height: 1.0,
decoration: BoxDecoration(
border:
Border(bottom: BorderSide(color: Colors.teal, width: 3.0))),
decoration: BoxDecoration(border: Border(bottom: BorderSide(color: Colors.teal, width: 3.0))),
),
iconDisabledColor: Colors.brown,
iconEnabledColor: Colors.indigo,
Expand All @@ -278,7 +267,7 @@ class _MyAppState extends State<MyApp> {
});
},
doneButton: (selectedItemsDone, doneContext) {
return (RaisedButton(
return (ElevatedButton(
onPressed: selectedItemsDone.length != 3
? null
: () {
Expand Down Expand Up @@ -337,16 +326,15 @@ class _MyAppState extends State<MyApp> {
return Row(
mainAxisAlignment: MainAxisAlignment.spaceBetween,
children: <Widget>[
RaisedButton(
ElevatedButton(
onPressed: () {
setState(() {
selectedItems.clear();
selectedItems.addAll(
Iterable<int>.generate(items.length).toList());
selectedItems.addAll(Iterable<int>.generate(items.length).toList());
});
},
child: Text("Select all")),
RaisedButton(
ElevatedButton(
onPressed: () {
setState(() {
selectedItems.clear();
Expand Down Expand Up @@ -375,16 +363,15 @@ class _MyAppState extends State<MyApp> {
return Row(
mainAxisAlignment: MainAxisAlignment.spaceBetween,
children: <Widget>[
RaisedButton(
ElevatedButton(
onPressed: () {
setState(() {
selectedItems.clear();
selectedItems.addAll(
Iterable<int>.generate(items.length).toList());
selectedItems.addAll(Iterable<int>.generate(items.length).toList());
});
},
child: Text("Select all")),
RaisedButton(
ElevatedButton(
onPressed: () {
setState(() {
selectedItems.clear();
Expand Down Expand Up @@ -417,8 +404,7 @@ class _MyAppState extends State<MyApp> {
),
"Single dialog object": SearchableDropdown.single(
items: ExampleNumber.list.map((exNum) {
return (DropdownMenuItem(
child: Text(exNum.numberString), value: exNum));
return (DropdownMenuItem(child: Text(exNum.numberString), value: exNum));
}).toList(),
value: selectedNumber,
hint: "Select one number",
Expand Down Expand Up @@ -518,7 +504,7 @@ class _MyAppState extends State<MyApp> {
},
isExpanded: true,
),
FlatButton(
ElevatedButton(
child: Text("Select $preselectedValue"),
onPressed: () {
setState(() {
Expand All @@ -540,9 +526,7 @@ class _MyAppState extends State<MyApp> {
actions: appBarActions,
bottom: TabBar(
isScrollable: true,
tabs: Iterable<int>.generate(widgets.length)
.toList()
.map((i) {
tabs: Iterable<int>.generate(widgets.length).toList().map((i) {
return (Tab(
text: (i + 1).toString(),
));
Expand Down
2 changes: 1 addition & 1 deletion example/pubspec.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ version: 0.0.1
publish_to: 'none'

environment:
sdk: ">=2.1.0 <3.0.0"
sdk: '>=3.1.0 <4.0.0'

dependencies:
flutter:
Expand Down
Loading