-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
example: for depends on async format
- Loading branch information
Showing
18 changed files
with
295 additions
and
177 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -10,5 +10,4 @@ void main() { | |
example01.test(); | ||
example02.test(); | ||
example03.test(); | ||
|
||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
83 changes: 83 additions & 0 deletions
83
example/lib/03_1_depend_observable_sample/depends_on_sample.dart
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,83 @@ | ||
import 'package:flutter/material.dart'; | ||
import 'package:telescope/telescope.dart'; | ||
|
||
class DependObservableSampleLayout extends StatefulWidget { | ||
const DependObservableSampleLayout({Key? key}) : super(key: key); | ||
|
||
@override | ||
State<DependObservableSampleLayout> createState() => | ||
DependObservableSampleLayoutState(); | ||
} | ||
|
||
class DependObservableSampleLayoutState | ||
extends State<DependObservableSampleLayout> { | ||
// observables | ||
late Telescope<int> height; | ||
late Telescope<int> weight; | ||
late Telescope<double> bmi; | ||
late Telescope<String> showingText; | ||
|
||
@override | ||
void initState() { | ||
super.initState(); | ||
|
||
height = Telescope(186); | ||
weight = Telescope(72); | ||
|
||
bmi = Telescope.dependsOn([height, weight], () { | ||
return weight.value / ((height.value / 100) * (height.value / 100)); | ||
}); | ||
|
||
showingText = Telescope.dependsOn([bmi], () { | ||
return "weight is ${weight.value} and height is ${height.value} so bmi will be ${bmi.value.toString().substring(0, 5)}"; | ||
}); | ||
} | ||
|
||
@override | ||
Widget build(BuildContext context) { | ||
var style = const TextStyle(fontSize: 40); | ||
return Material( | ||
type: MaterialType.transparency, | ||
child: SafeArea( | ||
child: Container( | ||
color: Colors.white, | ||
child: Column( | ||
children: [ | ||
const SizedBox(height: 20), | ||
Text( | ||
"Weight(kg):", | ||
style: style, | ||
), | ||
Slider( | ||
value: weight.watch(this).toDouble(), | ||
min: 1, | ||
max: 200, | ||
label: weight.watch(this).round().toString(), | ||
onChanged: (double value) { | ||
weight.value = value.toInt(); | ||
}), | ||
Text( | ||
"Height(cm):", | ||
style: style, | ||
), | ||
Slider( | ||
value: height.watch(this).toDouble(), | ||
min: 1, | ||
max: 200, | ||
label: height.watch(this).round().toString(), | ||
onChanged: (double value) { | ||
height.value = value.toInt(); | ||
}), | ||
Text( | ||
"Result:", | ||
style: style, | ||
), | ||
Text( | ||
showingText.watch(this), | ||
style: style, | ||
), | ||
], | ||
), | ||
))); | ||
} | ||
} |
2 changes: 1 addition & 1 deletion
2
...lib/03_depend_observable_sample/main.dart → ...b/03_1_depend_observable_sample/main.dart
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
90 changes: 90 additions & 0 deletions
90
example/lib/03_2_depends_on_async/depends_on_async_sample.dart
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,90 @@ | ||
import 'package:flutter/material.dart'; | ||
import 'package:telescope/telescope.dart'; | ||
|
||
class DependObservableAsyncSampleLayout extends StatefulWidget { | ||
const DependObservableAsyncSampleLayout({Key? key}) : super(key: key); | ||
|
||
@override | ||
State<DependObservableAsyncSampleLayout> createState() => | ||
DependObservableAsyncSampleLayoutState(); | ||
} | ||
|
||
class DependObservableAsyncSampleLayoutState | ||
extends State<DependObservableAsyncSampleLayout> { | ||
// observables | ||
late Telescope<int> height; | ||
late Telescope<int> weight; | ||
late Telescope<double> bmi; | ||
late Telescope<String> showingText; | ||
|
||
@override | ||
void initState() { | ||
super.initState(); | ||
|
||
height = Telescope(186); | ||
weight = Telescope(72); | ||
|
||
bmi = Telescope.dependsOnAsync(0, [height, weight], () async { | ||
return await calculateBMI(height.value, weight.value); | ||
}); | ||
|
||
showingText = Telescope.dependsOn([height, weight, bmi], () { | ||
var bmis = bmi.value.toString(); | ||
bmis = bmis.length > 5 ? bmis.substring(0, 5) : bmis; | ||
return "weight is ${weight.value} and height is ${height.value} so bmi will be $bmis"; | ||
}); | ||
} | ||
|
||
@override | ||
Widget build(BuildContext context) { | ||
var style = const TextStyle(fontSize: 40); | ||
return Material( | ||
type: MaterialType.transparency, | ||
child: SafeArea( | ||
child: Container( | ||
color: Colors.white, | ||
child: Column( | ||
children: [ | ||
const SizedBox(height: 20), | ||
Text( | ||
"Weight(kg):", | ||
style: style, | ||
), | ||
Slider( | ||
value: weight.watch(this).toDouble(), | ||
min: 1, | ||
max: 200, | ||
label: weight.watch(this).round().toString(), | ||
onChanged: (double value) { | ||
weight.value = value.toInt(); | ||
}), | ||
Text( | ||
"Height(cm):", | ||
style: style, | ||
), | ||
Slider( | ||
value: height.watch(this).toDouble(), | ||
min: 1, | ||
max: 200, | ||
label: height.watch(this).round().toString(), | ||
onChanged: (double value) { | ||
height.value = value.toInt(); | ||
}), | ||
Text( | ||
"Result:", | ||
style: style, | ||
), | ||
Text( | ||
showingText.watch(this), | ||
style: style, | ||
), | ||
], | ||
), | ||
))); | ||
} | ||
} | ||
|
||
Future<double> calculateBMI(int w, int h) async { | ||
await Future.delayed(const Duration(seconds: 2)); | ||
return w / ((h / 100) * (h / 100)); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
import 'package:app/03_2_depends_on_async/depends_on_async_sample.dart'; | ||
import 'package:flutter/material.dart'; | ||
|
||
void main() { | ||
runApp(const MyApp()); | ||
} | ||
|
||
class MyApp extends StatelessWidget { | ||
const MyApp({Key? key}) : super(key: key); | ||
|
||
@override | ||
Widget build(BuildContext context) { | ||
return MaterialApp( | ||
theme: ThemeData(fontFamily: 'IranSans'), | ||
debugShowCheckedModeBanner: false, | ||
home: const DependObservableAsyncSampleLayout()); | ||
} | ||
} |
83 changes: 0 additions & 83 deletions
83
example/lib/03_depend_observable_sample/depends_on_sample.dart
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.