This guide outlines the conversion process for running existing Java-based Android apps on both web and mobile platforms through Dart, the language powering Flutter. This enables multi-platform deployment with a single codebase for efficient development and wider app reach.
I hope you like this video. For any questions, suggestions or appreciation please contact us at: or email at: programmerworld1990
Complete source code and other details/ steps of this video are posted in the below link:
However, the main Java and Dart code is copied below also for reference:
package com.programmerworld.counterandroidapp;
import android.os.Bundle;
import android.view.View;
import android.widget.TextView;
import androidx.activity.EdgeToEdge;
import androidx.appcompat.app.AppCompatActivity;
import androidx.core.graphics.Insets;
import androidx.core.view.ViewCompat;
import androidx.core.view.WindowInsetsCompat;
public class MainActivity extends AppCompatActivity {
private int value = 0;
private TextView textView;
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
EdgeToEdge.enable(this);
setContentView(R.layout.activity_main);
ViewCompat.setOnApplyWindowInsetsListener(findViewById(R.id.main), (v, insets) - {
Insets systemBars = insets.getInsets(WindowInsetsCompat.Type.systemBars());
v.setPadding(systemBars.left, systemBars.top, systemBars.right, systemBars.bottom);
return insets;
});
textView = findViewById(R.id.textView);
}
public void increment(View view) {
value = value + 5;
textView.setText(String.valueOf(value));
}
}
--
Dart Code:
import 'package:flutter/material.dart';
void main() {
runApp(MyApp());
}
class MyApp extends StatelessWidget {
Widget build(BuildContext context) {
return MaterialApp(
home: MyHomePage(),
);
}
}
class MyHomePage extends StatefulWidget {
State MyHomePage createState() = _MyHomePageState();
}
class _MyHomePageState extends State MyHomePage {
int value = 0;
Widget build(BuildContext context) {
return Scaffold(
body: Padding(
padding: EdgeInsets.only(
left: MediaQuery.of(context).viewInsets.left,
top: MediaQuery.of(context).viewInsets.top,
right: MediaQuery.of(context).viewInsets.right,
bottom: MediaQuery.of(context).viewInsets.bottom,
),
child: Row(
mainAxisAlignment: MainAxisAlignment.center,
children: [
Column(
mainAxisAlignment: MainAxisAlignment.center,
children: [
Text(
'$value',
style: TextStyle(fontSize: 32),
),
ElevatedButton(
onPressed: () = setState(() = value += 5),
child: Text('Increment'),
),
],
),
],
),
),
);
}
}
--
Смотрите видео How to convert an Android Java code to Dart code and run as web or Android app? онлайн без регистрации, длительностью 05 минут 59 секунд в хорошем hd качестве. Это видео добавил пользователь Programmer World 20 Июль 2024, не забудьте поделиться им ссылкой с друзьями и знакомыми, на нашем сайте его посмотрели 177 раз и оно понравилось 6 людям.