This file contains hidden or 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
import 'dart:async'; | |
import 'dart:math' show Random; | |
main() async { | |
print('Compute π using the Monte Carlo method.'); | |
await for (final estimate in computePi().take(100)) { | |
print('π ≅ $estimate'); | |
} | |
} | |
/// Generates a stream of increasingly accurate estimates of π. |
This file contains hidden or 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
// In null-safe Dart, none of these can ever be null. | |
var widget = Text('Hello'); | |
final status = GetStatus(); | |
String m = ''; |
This file contains hidden or 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
void honk(int? loudness) { | |
if (loudness == null) { | |
// No loudness specified, notify the developer | |
// with maximum loudness. | |
_playSound('error.wav', volume: 11); | |
return; | |
} | |
// Loudness is non-null, let's just clamp it to acceptable levels. | |
_playSound('honk.wav', volume: loudness.clamp(0, 11)); | |
} |
This file contains hidden or 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
class StatusLine extends StatelessWidget { | |
final Status status; | |
StatusLine({this.status: Status.failed}); | |
@override | |
Widget build(BuildContext context) { | |
// This local variable is non-nullable, but not initialized. | |
String statusText; | |
if (status == Status.ok) { | |
statusText = 'Update succeeded'; | |
} else { |
This file contains hidden or 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
// These are all nullable variables. | |
Text? t = Text('Hello'); // Can be null later. | |
final Status? s = getStatus(); // Maybe the function returns null. | |
String? n; // Is null at first. Can be null at any later time, too. |
This file contains hidden or 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
// In function parameters. | |
void initialize(int? count) { | |
// It's possible that count is null. | |
} | |
// In function return values. | |
static List<double?>? getTemperatures() { | |
// Can return null instead of a List, and the list can contain nulls. | |
} |
This file contains hidden or 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
class MyApp extends StatelessWidget { | |
@override | |
Widget build(BuildContext context) { | |
// Get data from services. Note: in a real application, | |
// these would be async calls, but we're using sync calls | |
// for simplicity. | |
final localizedAppName = Config.getAppName(); | |
final temperatures = WeatherService.getTemperatures(); | |
return MaterialApp( | |
home: Scaffold( |
This file contains hidden or 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
import 'package:filepicker_windows/filepicker_windows.dart'; | |
void main() { | |
final file = OpenFilePicker() | |
..filterSpecification = { | |
'Word Document (*.doc)': '*.doc', | |
'Web Page (*.htm; *.html)': '*.htm;*.html', | |
'Text Document (*.txt)': '*.txt', | |
'All Files': '*.*' | |
} |
This file contains hidden or 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
import 'dart:ffi'; | |
import 'package:ffi/ffi.dart'; | |
// more imports | |
import 'IModalWindow.dart'; | |
/// @nodoc | |
const IID_IFileDialog = '{42f85136-db7e-439c-85f1-e4075d135fc8}'; |
This file contains hidden or 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
#include "windows.h" | |
#include "Shobjidl.h" | |
// vtable_start 4 | |
MIDL_INTERFACE("42f85136-db7e-439c-85f1-e4075d135fc8") | |
IFileDialog : public IModalWindow | |
{ | |
public: | |
virtual HRESULT STDMETHODCALLTYPE SetFileTypes( | |
/* [in] */ UINT cFileTypes, |