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: https://programmerworld.co/contact/ or email at: programmerworld1990@gmail.com
Complete source code and other details/ steps of this video are posted in the below link:
https://programmerworld.co/android/ho...
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;
@Override
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 {
@override
Widget build(BuildContext context) {
return MaterialApp(
home: MyHomePage(),
);
}
}
class MyHomePage extends StatefulWidget {
@override
State MyHomePage createState() = _MyHomePageState();
}
class _MyHomePageState extends State MyHomePage {
int value = 0;
@override
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'),
),
],
),
],
),
),
);
}
}
--
In questa pagina del sito puoi guardare il video online How to convert an Android Java code to Dart code and run as web or Android app? della durata di ore minuti seconda in buona qualità , che l'utente ha caricato Programmer World 20 luglio 2024, condividi il link con amici e conoscenti, su youtube questo video è già stato visto 1,179 volte e gli è piaciuto 10 spettatori. Buona visione!