Skip to content

Commit

Permalink
Updated to use recent language (null safety, super parameters)
Browse files Browse the repository at this point in the history
  • Loading branch information
eernstg committed Apr 25, 2023
1 parent 47e0510 commit cac2aed
Show file tree
Hide file tree
Showing 3 changed files with 15 additions and 14 deletions.
23 changes: 12 additions & 11 deletions lib/do_reflect.dart
Original file line number Diff line number Diff line change
Expand Up @@ -24,28 +24,28 @@ class A {
int arg0() => value;
int arg1(int x) => x - value;
int arg1to3(int x, int y, [int z = 0, w]) => x + y + z * value;
int argNamed(int x, int y, {int z: 42}) => x + y - z;
int operator +(x) => value + x;
int operator [](x) => value + x;
void operator []=(x, v) { f = x + v; }
int argNamed(int x, int y, {int z = 42}) => x + y - z;
int operator +(int x) => value + x;
int operator [](int x) => value + x;
void operator []=(int x, int v) { f = x + v; }
int operator -() => -f;
int operator ~() => f + value;

int f = 0;

static int noArguments() => 42;
static int oneArgument(x) => x - 42;
static int oneArgument(int x) => x - 42;
static int optionalArguments(x, y, [z = 0, w]) => x + y + z * 42;
static int namedArguments(int x, int y, {int z: 42}) => x + y - z;
static int namedArguments(int x, int y, {int z = 42}) => x + y - z;
}

String doReflect(int i) {
List<int> result = [];
List<Object?> result = [];

// Get hold of a few mirrors.
A instance = new A(i);
InstanceMirror instanceMirror = myReflectable.reflect(instance);
ClassMirror classMirror = myReflectable.reflectType(A);
var instanceMirror = myReflectable.reflect(instance);
var classMirror = myReflectable.reflectType(A) as ClassMirror;

// Invocations of methods accepting positional arguments.
result.add(instanceMirror.invoke("arg0", []));
Expand Down Expand Up @@ -75,9 +75,10 @@ String doReflect(int i) {
result.add(classMirror.invoke("namedArguments", [55, 29 + i]));
result.add(classMirror.invoke("namedArguments", [21, 21], {#z: i}));

return result.toString();

// Use a declaration in 'dart:ui'.
Color color = Color(0xFF42A5F5);
// ignore: unused_local_variable
ObjectMirror colorMirror = myReflectable.reflect(color);

return result.toString();
}
4 changes: 2 additions & 2 deletions lib/main.dart
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ class MyApp extends StatelessWidget {
}

class MyHomePage extends StatefulWidget {
MyHomePage({Key key, this.title}) : super(key: key);
MyHomePage({super.key, this.title = ''});

// This widget is the home page of your application. It is stateful, meaning
// that it has a State object (defined below) that contains fields that affect
Expand Down Expand Up @@ -101,7 +101,7 @@ class _MyHomePageState extends State<MyHomePage> {
),
new Text(
'$_counter',
style: Theme.of(context).textTheme.headline6,
style: Theme.of(context).textTheme.titleLarge,
),
new Text(
"${doReflect(_counter)}"
Expand Down
2 changes: 1 addition & 1 deletion pubspec.yaml
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
name: reflectable_flutter
description: A minimal example using reflectable with Flutter.
environment:
sdk: '>=2.13.0 <3.0.0'
sdk: '>=2.17.0 <3.0.0'

dependencies:
flutter:
Expand Down

0 comments on commit cac2aed

Please sign in to comment.