Move to real generic method syntax (#7235)

This commit is contained in:
Ian Hickson
2017-01-21 20:58:44 -08:00
committed by GitHub
parent 2e196037f5
commit 15a7eb3b6c
60 changed files with 154 additions and 157 deletions

View File

@@ -77,15 +77,15 @@ class DesertDataSource extends DataTableSource {
new Desert('Coconut slice and KitKat', 677, 41.0, 72, 8.5, 63, 12, 12),
];
void _sort/*<T>*/(Comparable<dynamic/*=T*/> getField(Desert d), bool ascending) {
void _sort<T>(Comparable<T> getField(Desert d), bool ascending) {
_deserts.sort((Desert a, Desert b) {
if (!ascending) {
final Desert c = a;
a = b;
b = c;
}
final Comparable<dynamic/*=T*/> aValue = getField(a);
final Comparable<dynamic/*=T*/> bValue = getField(b);
final Comparable<T> aValue = getField(a);
final Comparable<T> bValue = getField(b);
return Comparable.compare(aValue, bValue);
});
notifyListeners();
@@ -153,8 +153,8 @@ class _DataTableDemoState extends State<DataTableDemo> {
bool _sortAscending = true;
DesertDataSource _desertsDataSource = new DesertDataSource();
void _sort/*<T>*/(Comparable<dynamic/*=T*/> getField(Desert d), int columnIndex, bool ascending) {
_desertsDataSource._sort/*<T>*/(getField, ascending);
void _sort<T>(Comparable<T> getField(Desert d), int columnIndex, bool ascending) {
_desertsDataSource._sort<T>(getField, ascending);
setState(() {
_sortColumnIndex = columnIndex;
_sortAscending = ascending;
@@ -178,44 +178,44 @@ class _DataTableDemoState extends State<DataTableDemo> {
columns: <DataColumn>[
new DataColumn(
label: new Text('Dessert (100g serving)'),
onSort: (int columnIndex, bool ascending) => _sort/*<String>*/((Desert d) => d.name, columnIndex, ascending)
onSort: (int columnIndex, bool ascending) => _sort<String>((Desert d) => d.name, columnIndex, ascending)
),
new DataColumn(
label: new Text('Calories'),
tooltip: 'The total amount of food energy in the given serving size.',
numeric: true,
onSort: (int columnIndex, bool ascending) => _sort/*<num>*/((Desert d) => d.calories, columnIndex, ascending)
onSort: (int columnIndex, bool ascending) => _sort<num>((Desert d) => d.calories, columnIndex, ascending)
),
new DataColumn(
label: new Text('Fat (g)'),
numeric: true,
onSort: (int columnIndex, bool ascending) => _sort/*<num>*/((Desert d) => d.fat, columnIndex, ascending)
onSort: (int columnIndex, bool ascending) => _sort<num>((Desert d) => d.fat, columnIndex, ascending)
),
new DataColumn(
label: new Text('Carbs (g)'),
numeric: true,
onSort: (int columnIndex, bool ascending) => _sort/*<num>*/((Desert d) => d.carbs, columnIndex, ascending)
onSort: (int columnIndex, bool ascending) => _sort<num>((Desert d) => d.carbs, columnIndex, ascending)
),
new DataColumn(
label: new Text('Protein (g)'),
numeric: true,
onSort: (int columnIndex, bool ascending) => _sort/*<num>*/((Desert d) => d.protein, columnIndex, ascending)
onSort: (int columnIndex, bool ascending) => _sort<num>((Desert d) => d.protein, columnIndex, ascending)
),
new DataColumn(
label: new Text('Sodium (mg)'),
numeric: true,
onSort: (int columnIndex, bool ascending) => _sort/*<num>*/((Desert d) => d.sodium, columnIndex, ascending)
onSort: (int columnIndex, bool ascending) => _sort<num>((Desert d) => d.sodium, columnIndex, ascending)
),
new DataColumn(
label: new Text('Calcium (%)'),
tooltip: 'The amount of calcium as a percentage of the recommended daily amount.',
numeric: true,
onSort: (int columnIndex, bool ascending) => _sort/*<num>*/((Desert d) => d.calcium, columnIndex, ascending)
onSort: (int columnIndex, bool ascending) => _sort<num>((Desert d) => d.calcium, columnIndex, ascending)
),
new DataColumn(
label: new Text('Iron (%)'),
numeric: true,
onSort: (int columnIndex, bool ascending) => _sort/*<num>*/((Desert d) => d.iron, columnIndex, ascending)
onSort: (int columnIndex, bool ascending) => _sort<num>((Desert d) => d.iron, columnIndex, ascending)
),
],
source: _desertsDataSource

View File

@@ -65,12 +65,12 @@ class DialogDemoState extends State<DialogDemo> {
_selectedTime = new TimeOfDay(hour: now.hour, minute: now.minute);
}
void showDemoDialog/*<T>*/({ BuildContext context, Widget child }) {
showDialog/*<T>*/(
void showDemoDialog<T>({ BuildContext context, Widget child }) {
showDialog<T>(
context: context,
child: child
)
.then((dynamic/*=T*/ value) { // The value passed to Navigator.pop() or null.
.then((T value) { // The value passed to Navigator.pop() or null.
if (value != null) {
_scaffoldKey.currentState.showSnackBar(new SnackBar(
content: new Text('You selected: $value')
@@ -95,7 +95,7 @@ class DialogDemoState extends State<DialogDemo> {
new RaisedButton(
child: new Text('ALERT'),
onPressed: () {
showDemoDialog/*<DialogDemoAction>*/(
showDemoDialog<DialogDemoAction>(
context: context,
child: new AlertDialog(
content: new Text(
@@ -119,7 +119,7 @@ class DialogDemoState extends State<DialogDemo> {
new RaisedButton(
child: new Text('ALERT WITH TITLE'),
onPressed: () {
showDemoDialog/*<DialogDemoAction>*/(
showDemoDialog<DialogDemoAction>(
context: context,
child: new AlertDialog(
title: new Text('Use Google\'s location service?'),
@@ -144,7 +144,7 @@ class DialogDemoState extends State<DialogDemo> {
new RaisedButton(
child: new Text('SIMPLE'),
onPressed: () {
showDemoDialog/*<String>*/(
showDemoDialog<String>(
context: context,
child: new SimpleDialog(
title: new Text('Set backup account'),

View File

@@ -15,7 +15,7 @@ class ModalBottomSheetDemo extends StatelessWidget {
child: new RaisedButton(
child: new Text('SHOW BOTTOM SHEET'),
onPressed: () {
showModalBottomSheet/*<Null>*/(context: context, builder: (BuildContext context) {
showModalBottomSheet<Null>(context: context, builder: (BuildContext context) {
return new Container(
child: new Padding(
padding: const EdgeInsets.all(32.0),

View File

@@ -27,7 +27,7 @@ class _PersistentBottomSheetDemoState extends State<PersistentBottomSheetDemo> {
setState(() { // disable the button
_showBottomSheetCallback = null;
});
_scaffoldKey.currentState.showBottomSheet/*<Null>*/((BuildContext context) {
_scaffoldKey.currentState.showBottomSheet<Null>((BuildContext context) {
final ThemeData themeData = Theme.of(context);
return new Container(
decoration: new BoxDecoration(

View File

@@ -51,7 +51,7 @@ class ShrinePageState extends State<ShrinePage> {
}
void _showShoppingCart() {
showModalBottomSheet/*<Null>*/(context: context, builder: (BuildContext context) {
showModalBottomSheet<Null>(context: context, builder: (BuildContext context) {
if (config.shoppingCart.isEmpty) {
return new Padding(
padding: const EdgeInsets.all(24.0),

View File

@@ -80,7 +80,7 @@ class TextFieldDemoState extends State<TextFieldDemo> {
if (!_formWasEdited || form.validate())
return new Future<bool>.value(true);
return showDialog/*<bool>*/(
return showDialog<bool>(
context: context,
child: new AlertDialog(
title: new Text('This form has errors'),

View File

@@ -300,7 +300,7 @@ class StockHomeState extends State<StockHome> {
}
void _handleCreateCompany() {
showModalBottomSheet/*<Null>*/(
showModalBottomSheet<Null>(
context: context,
builder: (BuildContext context) => new _CreateCompanySheet()
);