Combine Concat Two Strings Using Flutter Android App

admin_img Posted By Bajarangi soft , Posted On 12-10-2020

String Concatenation is used to marge two or multiple string into single string. As we all know string a group of multiple characters with no limit in all programming language. In Dart combing two string into single string is very easy by using Plus ( + ) symbol. All we have to do is place a plus sign between two strings and save the strings into a variable using assign = equal operator.

Combine Concat Two Strings Using Flutter Android App

Combine Concat Two Strings
Complete Code For Combine Concat Two Strings In Flutter
main.dart

import 'package:flutter/material.dart';

void main() => runApp(MyApp());

class MyApp extends StatelessWidget {
  @override
  Widget build(BuildContext context) {
    return MaterialApp(
      debugShowCheckedModeBanner: false,
      home: Scaffold(
          appBar: AppBar(
            backgroundColor: Colors.green,
            title: Text("String Concat in Dart"),
          ),
          body: SafeArea(
              child : Center(
                child:NextWidget(),
              )
          )
      ),
    );
  }
}

class NextWidget extends StatefulWidget {
  @override
  StateNextWidget createState() => StateNextWidget();
}

class StateNextWidget extends State<NextWidget> {
  String one = 'Hello';
  String two = 'Guys';
  String three ;
  void join(){
    setState(() {
      three = one + ' ' + two ;
    });
  }

  Widget build(BuildContext context) {
    return Center(child: Column(
      mainAxisAlignment: MainAxisAlignment.center,
      children: <Widget>[
        Text('$three', style: TextStyle(fontSize: 24),),
        RaisedButton(
          child: Text('Combine Two Strings on Button Press'),
          onPressed: join,
          color: Colors.green,
          textColor: Colors.white,
          padding: EdgeInsets.fromLTRB(10, 10, 10, 10),
        ),
      ],
    ));
  }
}

Related Post