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
| // The completions endpoint | |
| static final Uri completionsEndpoint = Uri.parse('https://api.openai.com/v1/completions'); |
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
| // The headers for the completions endpoint, which are the same for all requests | |
| static final Map<String, String> headers = { | |
| 'Content-Type': 'application/json', | |
| 'Authorization': 'Bearer $openAIApiKey', | |
| }; |
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
| /// Gets a "weather forecast" from the OpenAI completions endpoint | |
| static Future<CompletionsResponse> getNewForecast() async { | |
| debugPrint('Getting a new weather forecast'); | |
| CompletionsRequest request = CompletionsRequest( | |
| model: 'text-curie-001', | |
| prompt: 'Today's forecast is', | |
| maxTokens: 9, | |
| temperature: 0.6, | |
| ); |
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
| return FutureBuilder( | |
| future: CompletionsApi.getForecast(constraints.maxWidth < 300 ? 6 : 9), | |
| builder: (BuildContext context, AsyncSnapshot<String?> forecast) { | |
| if (forecast.hasData) { | |
| dailyForecast = forecast.data; | |
| return Text(dailyForecast); | |
| } else { | |
| // Display a loading indicator while waiting for the forecast | |
| return const CircularProgressIndicator(); | |
| } |
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
| <?xml version="1.0" encoding="utf-8"?> | |
| <adaptive-icon xmlns:android="http://schemas.android.com/apk/res/android"> | |
| <background android:drawable="@drawable/ic_launcher_background" /> | |
| <foreground android:drawable="@mipmap/ic_launcher_foreground" /> | |
| <monochrome android:drawable="@mipmap/ic_launcher_monochrome" /> | |
| </adaptive-icon> |
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 SimpleClass { | |
| // Public variable, accessible from outside the class | |
| String publicVariable; | |
| // Private variable, accessible only within this class | |
| String _privateVariable; | |
| SimpleClass(this.publicVariable, this._privateVariable); | |
| } |
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
| /// A controller class designed for driving a clock interface in a Flutter application. | |
| class ClockController with ChangeNotifier { | |
| /// The current time in 12-hour format. | |
| late DateTime _currentTime; | |
| // Getter for the current time | |
| DateTime get currentTime => _currentTime; | |
| ClockController() { | |
| _currentTime = DateTime.now(); |
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
| /// A controller class designed for driving a clock interface in a Flutter application. | |
| class ClockController with ChangeNotifier { | |
| /// The current time in 12-hour format. | |
| late DateTime _currentTime; | |
| // Getter for the current time | |
| DateTime get currentTime => _currentTime; | |
| /// A [DateTime] when the alarm should be triggered | |
| DateTime? _alarm; |
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
| /// This is a setter used to set the value of the private variable, `_alarm` | |
| set alarm(DateTime alarmTime) { | |
| if(alarmTime.hour < 5) { | |
| throw Exception('Nope. That is far to early to set an alarm.'); | |
| } else { | |
| _alarm = alarmTime; | |
| } | |
| } | |
| /// This is an equivalent function, also used to set the value of the private variable, `_alarm` |
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
| /// This block uses the setter defined in the previous example. | |
| try { | |
| alarm = alarmTime; | |
| print('Alarm set for: $alarm'); | |
| } catch (e) { | |
| print('Error: $e'); | |
| } | |
| /// This block uses the equivalent function defined in the previous example. | |
| try { |