How can i load an image in between a text in Flutter - android

I need to display content containing text and images from an API on my android app, when I save it in a variable of type String, the texts get displayed but the images shows as url. How do I load the get the links to load in between the texts?

I needed to insert an Image inline with a sentence of texts.
So for that I used this:
final String paragraph1 =
'Advanciti App is an app where you can study and make friends with people living near your home. Advanciti is an Edtech Startup based out of Pune, Maharashtra, India.\n';
RichText(
text: TextSpan(
children: [
TextSpan(text: "The "),
WidgetSpan(child: Container(width: 20.0, child: Image.asset('assets/app_icon.png', scale: 1))),
TextSpan(text: paragraph1),
],
),
),

if you want to show images you need to convert your data to HTML or Markdown. in MarkDown and HTML, you can show much more then the image. these are packages for HTML and MarkDown:
flutter_html
flutter_markdown

You can use the following to place an image between two texts vertically:
Column(
children: <Widget>[
Text("Hello"),
Image.network(
'REPLACE HERE WITH YOUR IMG URL'),
Text("World")
],
),
or you can use this to place an image between two texts horizontally:
Row(
children: <Widget>[
Text("Hello"),
Image.network(
'REPLACE HERE WITH YOUR IMG URL'),
Text("World")
],
),

Related

my question about my project app flutter after publishing on play store

i have flutter app project and i publishing him on play store but my app have like a custom scroll view contain some pictures that i want to update them every 2 week can i update him without releasing my app and building again ??
is the database like (SQF lite) will benefit me to this topic
the code in below contain some picture that i want update them i wrote it like example
Container(
child: Row(
mainAxisAlignment: MainAxisAlignment.spaceBetween,
children: [
Expanded(child:
Column(
crossAxisAlignment: CrossAxisAlignment.start,
children: [
Text("Explore", style: TextStyle(color: textColor, fontSize: 24, fontWeight: FontWeight.w600),),
],
)
),
IconBox(child: SvgPicture.asset("assets/icons/filter.svg", width: 20, height: 20,),)
],
),
);
}
and thanks

How to add whatsapp image in floating action button in flutter

How to add whatsapp image in floating action button in flutter because whatsapp icon is not in flutter icon list. Tell me a simple method.
Row(
children: [
FloatingActionButton(
child: const Icon(Icons.chat),
backgroundColor: Colors.green.shade800,
onPressed: () {
String url =
"https://wa.me/+923045873730/?text=Hello";
launch(url);
},
),
],
),
Font Awesome has a flutter package that helps with most icons that are not in flutter default icon set, https://pub.dev/packages/font_awesome_flutter. It also includes all icons listed in font Awesome Offical website https://fontawesome.com/icons
import 'package:font_awesome_flutter/font_awesome_flutter.dart';
Row(
children: [
FloatingActionButton(
child: FaIcon(FontAwesomeIcons.whatsapp),
backgroundColor: Colors.green.shade800,
onPressed: () {
String url =
"https://wa.me/+923045873730/?text=Hello";
launch(url);
},
),
],
),
The easiest way that comes to my mind is that downloading the icon image of Whatsapp (from flaticon or other website), adding it to the project's assets and adding it as a child( for example asset image).

FLUTTER: How to use text widget inside a string

I have a list of text widgets like this:
List<Widgets> widgets = [
Text('Theo', style: TextStyle(color: Colors.green)),
Text('Luca', style: TextStyle(color: Colors.blue))
]
and I have list of Strings like this:
'My name is #name',
'#name how old are you ?'
I want to replace the #name by a text widget in the list to print the right name with the right color.
Do you know a way to do it ?
you probably looking for rich text widget check this
RichText
It's not possible in Text Widget, use RichText Widget which takes TextSpan as children.
Change Text to Text Span
List<Widgets> widgets = [
TextSpan(text: 'Theo', style: TextStyle(color: Colors.green)),
TextSpan(text: 'Luca', style: TextStyle(color: Colors.blue))
]
Each line is a RichText. RichText takes TextSpan as children where the text and the corresponding style has to be specified.
widgets.map((textSpan) {
return Column(
children: [
RichText(
text: TextSpan(
text: 'My name is ',
style: DefaultTextStyle.of(context).style,
children: <TextSpan>[
textSpan // Name with color will appear here
],
),
RichText(
children: <TextSpan>[
textSpan // Name with color will appear here
TextSpan (
text: 'How old are you? ',
style: DefaultTextStyle.of(context).style,
),
],
),
],
)
}
Alternatively this can replicated by using Row and Text widgets but then it won't be a single line.

Scrolling to a TextSpan inside a RichText

The problem is that I have a RichText inside a Scrollable Widget(SingleChildScrollView or ListView) and I need to Scroll to a specific TextSpan inside the RichText. Also, I cannot use ScrollablePositionedList because the texts should write in the end of the last one and if there was no space to continue the text should go to the next line so I have to use RichText.
Similar to
Sample Code:
ListView(
children:[
RichText(
children: AListOfTextSpansThatICreateWithIndexes(),
),
],
),
Sample Text That I want to show:
This is TextSpan1 and it is a bit
long. This is TextSpan2 and its ok.
Similar to Scrollable position of a TextSpan within a RichText
There is a way to make sure a key is visible on the screen using the Scrollable.ensureVisible method. (credits to the person who deleted their comment)
you should first generate keys for your list:
var keys = List.generate(LENGTH, (i) => GlobalKey());
Then use the keys behind each TextSpan:
Text.rich(
TextSpan(
children: Iterable.generate(LENGTH, (i) => i)
.expand((i) => [
WidgetSpan(
child: SizedBox.fromSize(
size: Size.zero,
key: keys[i],
),
),
TextSpan(
text: 'this is text number $i',
),
])
.toList(),
),
),
Finally, call this function(where there is access to the context) to scroll to the desired key:
Scrollable.ensureVisible(
keys[i].currentContext,
alignment: 0.2,
duration: Duration(milliseconds: 500),
),

Why is the text widget underlined?

Hey guys I have a question. I tried to ad a new text widget in my code (just as always), but it is red underlined. I don´t know why. In my opinion everything is right. I copied the same text widget one line below and in that line it isn´t underlined. Can anybody say my what the reason therefore is? (I added a link in which you should find the part of the code.
This is the code
pic of the widgets
You have to add , after RaisedButton.
Column(
children: <Widget>[
RaisedButton(
child: Text("Button"),
onPressed: (){
},
), // <--- here
Text("Simple"),
Text("simple"),
],
),
It's underline because it's missing a comma before your Text Widget :
RaisedButton(
child: Text(startStopButtonDesign),
onPressed: () {
startOrStop();
},
), //Missing commma
Text(_time.toString()),

Categories

Resources