in packages/sampler/lib/main.dart [367:562]
Widget build(BuildContext context) {
List<ExpansionPanel> panels = const <ExpansionPanel>[];
List<SourceElement> elements;
if (Model.instance.currentElement == null) {
elements = Model.instance.elements?.toList() ?? <SourceElement>[];
} else {
elements = <SourceElement>[Model.instance.currentElement!];
}
int index = 0;
elements.sort((SourceElement a, SourceElement b) {
switch (sortBy) {
case SortBy.name:
final int compare = a.elementName.compareTo(b.elementName);
if (compare != 0) {
return compare;
}
return a.type.index.compareTo(b.type.index);
case SortBy.lineNumber:
return a.startLine.compareTo(b.startLine);
}
});
panels = elements.where((SourceElement element) {
return showTypes.contains(element.type) &&
(!showOnlySamples || element.sampleCount != 0) &&
(showOverrides || !element.override);
}).map<ExpansionPanel>(
(SourceElement element) {
final ExpansionPanel result = _createExpansionPanel(element, index,
isExpanded: index == expandedIndex);
index++;
return result;
},
).toList();
return Scaffold(
appBar: AppBar(
title: Text(widget.title),
),
body: Container(
padding: const EdgeInsets.all(8.0),
color: Colors.deepPurple.shade50,
child: Stack(
alignment: Alignment.center,
children: <Widget>[
if (filesLoading)
const CircularProgressIndicator.adaptive(value: null),
Column(
children: <Widget>[
Padding(
padding: const EdgeInsets.all(8.0),
child: Row(
children: <Widget>[
Padding(
padding: const EdgeInsetsDirectional.only(end: 8.0),
child: Text('Framework File:',
style: Theme.of(context)
.textTheme
.subtitle1!
.copyWith(fontWeight: FontWeight.bold)),
),
Expanded(
child: Autocomplete<File>(
fieldViewBuilder: _buildFileField,
optionsBuilder: _fileOptions,
displayStringForOption: (File file) {
if (path.isWithin(Model.instance.flutterRoot.path,
file.absolute.path)) {
return path.relative(file.absolute.path,
from: Model.instance.flutterRoot.absolute.path);
} else {
return file.absolute.path;
}
},
onSelected: (File file) {
expandedIndex = -1;
Model.instance
.setWorkingFile(file)
.onError((Exception e, StackTrace trace) {
if (e is! SnippetException) {
throw e;
}
final ScaffoldMessengerState? scaffold =
ScaffoldMessenger.maybeOf(context);
scaffold?.showSnackBar(
SnackBar(
backgroundColor: Colors.red,
duration: const Duration(seconds: 10),
content: Text(e.toString()),
),
);
});
},
)),
],
),
),
Padding(
padding: const EdgeInsetsDirectional.all(8.0),
child: Row(
children: <Widget>[
Expanded(
flex: 4,
child: Wrap(
direction: Axis.horizontal,
crossAxisAlignment: WrapCrossAlignment.center,
children: <Widget>[
IconButton(
tooltip: sortBy == SortBy.lineNumber
? 'Sort Alphabetically'
: 'Sort By Line Number',
onPressed: () {
setState(() {
switch (sortBy) {
case SortBy.name:
sortBy = SortBy.lineNumber;
break;
case SortBy.lineNumber:
sortBy = SortBy.name;
break;
}
});
},
icon: Icon(
sortBy == SortBy.lineNumber
? Icons.sort_by_alpha
: Icons.sort_rounded,
),
),
LabeledCheckbox(
value: showOnlySamples,
onChanged: (bool? value) {
setState(() {
showOnlySamples = value!;
});
},
label: const Text('has samples'),
),
for (final SourceElementType type
in SourceElementType.values.where(
(SourceElementType type) =>
type != SourceElementType.unknownType))
LabeledCheckbox(
value: showTypes.contains(type),
onChanged: (bool? value) {
setState(() {
if (value!) {
showTypes.add(type);
} else {
showTypes.remove(type);
}
});
},
label: Text(sourceElementTypeAsString(type)),
),
LabeledCheckbox(
value: showOverrides,
onChanged: (bool? value) {
setState(() {
showOverrides = value!;
});
},
label: const Text('overrides'),
),
],
),
),
Expanded(
child: Text(_getSampleStats(),
textAlign: TextAlign.end,
style: Theme.of(context).textTheme.caption),
),
],
),
),
Expanded(
child: ListView(
children: <Widget>[
ExpansionPanelList(
elevation: 0,
children: panels,
expansionCallback: (int index, bool expanded) {
setState(() {
expandedIndex = expanded ? -1 : index;
});
},
),
],
),
),
],
),
],
),
),
);
}