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'),
),
],
),
],
),
),
);
}
}
--
Watch video How to convert an Android Java code to Dart code and run as web or Android app? online without registration, duration 05 minute 59 second in high hd quality. This video was added by user Programmer World 20 July 2024, don't forget to share it with your friends and acquaintances, it has been viewed on our site 177 once and liked it 6 people.