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
| SingleChildScrollView( | |
| padding: EdgeInsets.symmetric(horizontal: 24, vertical: 48), | |
| child: Column( | |
| crossAxisAlignment: CrossAxisAlignment.start, | |
| children: <Widget>[ | |
| Text( | |
| _currentMovie.title.replaceAll(" ", "\n").toUpperCase(), | |
| style: TextStyle( | |
| shadows: [ | |
| Shadow( |
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
| //On Android | |
| class MainActivity() : FlutterActivity() { | |
| override fun onCreate(savedInstanceState: Bundle?) { | |
| super.onCreate(savedInstanceState) | |
| GeneratedPluginRegistrant.registerWith(this) | |
| MethodChannel(flutterView, "samples.flutter.io/battery").setMethodCallHandler { call, result -> | |
| if (call.method == "getBatteryLevel") { | |
| val batteryLevel = getBatteryLevel() |
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
| //From Flutter | |
| Future<String> _getBatteryLevel() async { | |
| String batteryLevel; | |
| try { | |
| //invoke the platform specific code | |
| //wait for the result | |
| final int result = await platform.invokeMethod('getBatteryLevel'); | |
| batteryLevel = 'Battery level at $result % .'; | |
| } on PlatformException catch (e) { | |
| batteryLevel = "Failed to get battery level: '${e.message}'."; |
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 SearchViewModel(application: Application) : AndroidViewModel(application), CoroutineScope { | |
| private val job = Job() | |
| override val coroutineContext: CoroutineContext | |
| get() = job + Dispatchers.Main | |
| private val mutableViewState = MutableLiveData<SearchViewState>() | |
| val viewState : LiveData<SearchViewState> = mutableViewState | |
| private val repository by lazy { | |
| mainApplication.omdbRepository |
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
| interface OMDBApi { | |
| @GET("/") | |
| fun searchMovies(@Query("s") name: String, @Query("apiKey") apikey: String) : Deferred<SearchResponse> | |
| companion object { | |
| val apiKey = "YOUR_KEY" | |
| val baseUrl = "http://www.omdbapi.com/" | |
| } | |
| } |
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 Movie { | |
| @SerializedName("Title") | |
| var title : String = "" | |
| @SerializedName("Year") | |
| var year : String = "" | |
| @SerializedName("ImdbID") | |
| var imdbID : String = "" | |
| @SerializedName("Type") | |
| var type : String = "" | |
| @SerializedName("Poster") |
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
| part 'Movie.g.dart'; | |
| @JsonSerializable() | |
| class Movie { | |
| @JsonKey(name: "Title") | |
| final String title; | |
| @JsonKey(name: "Year") | |
| final String year; | |
| @JsonKey(name: "ImdbID") | |
| final String imdbID; |
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 OmdbRepository { | |
| final apiKey = "my_key"; | |
| const OmdbRepository(); | |
| Future<List<Movie>> searchMovies(String byName) async { | |
| final response = await http.get('http://www.omdbapi.com/?s=$byName&apikey=$apiKey'); | |
| final jsonValue = json.decode(response.body); | |
| return SearchResponse.fromJson(jsonValue).movies; | |
| } | |
| } |
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 SearchViewModel { | |
| //Stream <=> MediatorLiveData | |
| final StreamController<SearchViewState> _viewModelController = StreamController(); | |
| final OmdbRepository _repository; | |
| //Stream <=> LiveData | |
| Stream<SearchViewState> get viewState => _viewModelController.stream; | |
| //constructor | |
| SearchViewModel(this._repository) { |
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
| User use = molki(User.class) | |
| .given(user -> user.getName()).willReturn(3) | |
| .given(user -> user.getFirstName()).willReturn(4) |