Pbtxt files using a subset config in multiple superset configs - protocol-buffers

Lets say I have two pbtxt files specifying details like so:
person1.pbtxt
person {
id: 001
name: "Jobava"
children: "Jiten"
children: "Jeffrey"
children: "Jassi"
}
and person2.pbtxt
person {
id: 002
name: "Jillian"
children: "Jiten"
children: "Jeffrey"
children: "Jassi"
}
As seen in this example, the children are the same. Is there a common location I can list the children, and merge them in to both person1.pbtxt and person2.pbtxt?
Something like:
children.pbtxt
children_common {
children: "Jiten"
children: "Jeffrey"
children: "Jassi"
}
and then
person1.pbtxt
person {
id: 001
name: "Jobava"
children: children_common
}
person1.pbtxt
person {
id: 002
name: "Jillian"
children: children_common
}
thank you!

Related

Flutter: Using image instead of icon

I have a sample code for a radiostream player.
The code provides for an icon to represent its state (paused or playing).
I would like to show an image instead of the icon.
Being a newby/noob with flutter im stuck.
Can sonebody push me in the right direction?
Here is the current code:
...........
default:
return Row(
crossAxisAlignment: CrossAxisAlignment.center,
mainAxisAlignment: MainAxisAlignment.center,
children: <Widget>[
IconButton(
onPressed: () async {
print("button press data: " +
snapshot.data.toString());
await _flutterRadioPlayer.playOrPause();
},
icon: snapshot.data ==
FlutterRadioPlayer
.flutter_radio_playing
? Icon(Icons.pause)
: Icon(Icons.play_arrow))
]);
break;
}
...............
So in short, i want to use an image, "pause.png" for Icons.pause and "play.png" for Icons.play_arrow.
Remove that IconButton thing and use this as a child of Future Builder
and the future builder will return this
Image.asset('pause.png'):Image.asset('play.png')
the icon is of type Widget so you can pass for example Image.asset([path to asset]) instead Icon()
here is the example
return Row(
crossAxisAlignment: CrossAxisAlignment.center,
mainAxisAlignment: MainAxisAlignment.center,
// replace Icon button to this custom button and wrap with Inkwell
children: <Widget>[
InkWell(
onTap: () async {
print("button press data: " +
snapshot.data.toString());
await _flutterRadioPlayer.playOrPause();
},
child : snapshot.data ==
FlutterRadioPlayer
.flutter_radio_playing
? Image.asset("image path")
: Image.asset("image path "))
]);
break;
}

Flutter: What kind of parameter type can have the argument type 'Image Function(dynamic)' assigned to it?

I'm just trying to load an image. I'm using the beta channel with web support. Flutter 1.19.0-4.3.pre. Dart 2.9.0
This is my pubspec:
flutter:
uses-material-design: true
assets:
- assets/
And this is my main.dart;
class _MyHomePageState extends State<MyHomePage> {
int _counter = 0;
void _incrementCounter() {
setState(() {
_counter++;
});
}
#override
Widget build(BuildContext context) {
return Scaffold(
appBar: AppBar(
centerTitle: true,
title: Text(widget.title),
),
body: Center(
child: Column(
mainAxisAlignment: MainAxisAlignment.center,
children: <Widget>[
Image(image: AssetImage('assets/logo.png')),
] < Widget > [
Text('Find happy, temporary, homes for your pets'),
],
),
),
);
}
}
Which I just copy/pasted from the documentation on the Flutter website. Where am I going wrong?
You don't have to have two arrays in a single <Widget>[] Column Class. I can see that you have done this:
<Widget>[
Image(image: AssetImage('assets/logo.png')),
] < Widget > [
Text('Find happy, temporary, homes for your pets'),
],
Which is indeed wrong. What a normal Column() accepts is like this. [To read more about Column class, please click here]
Column(
children: <Widget>[
// You multiple widget goes here not in multiple arrays
Widget1
Widget2
...
]
)
So to correct your code, you should do something like this, else, you have done correct in respect of assets
class _MyHomePageState extends State<MyHomePage> {
int _counter = 0;
void _incrementCounter() {
setState(() {
_counter++;
});
}
#override
Widget build(BuildContext context) {
return Scaffold(
appBar: AppBar(
centerTitle: true,
title: Text(widget.title),
),
body: Center(
child: Column(
mainAxisAlignment: MainAxisAlignment.center,
// One single array keeps your multiple widgets
children: <Widget>[
Image(image: AssetImage('assets/logo.png')),
Text('Find happy, temporary, homes for your pets'),
]
)
)
);
}
}
Let me know, if that works for you. Happy learning :)
Make sure your pubspec.yaml file's indentations are correct:
flutter:
assets:
- assets/
And then for your main.dart I think you don't need the Widget Builder. So your main.dart should look like this:
import 'package:flutter/material.dart';
void main() {
runApp(MyApp());
}
class MyApp extends StatelessWidget {
#override
Widget build(BuildContext context) {
return MaterialApp(
home: Scaffold(
body: Center(
child: Column(
mainAxisAlignment: MainAxisAlignment.center,
children: <Widget>[
Image(image: AssetImage('assets/logo.png'),
],
),
),
),
);
}
}

How To Compare Objects By Name In Query Flutter by Property

I am adding a search bar in my application and trying to query a object by an attribute name but, cant get it working.
EDIT 1) Future function:
Widget _buildDiner() {
return Padding(
padding: const EdgeInsets.all(8.0),
child: Column(
crossAxisAlignment: CrossAxisAlignment.start,
children: <Widget>[
FutureBuilder(
future: _setDiner,
builder: (context, AsyncSnapshot snapshot) {
var diner = snapshot.data;
if (snapshot.data == null) {
return Center(child: CircularProgressIndicator());
} else {
var sponsoredDiner = diner
.where((e) => e.sponsored == 'Yes')
.toList();
return Column(
children: <Widget>[
_makeDiner(sponsoredDiner),
_buildCoupon(),
_buildVendors()
],
);
}
})
]));
}
Diners =
class Diners {
String keyword;
int id;
String name;
String sponsored;
Diners({
this.keyword,
this.id,
this.name,
this.sponsored
});
factory Diners.fromJson(Map<String, dynamic> parsedJson) {
return Diners(
keyword: parsedJson['keyword'] as String,
id: parsedJson['id'],
name: parsedJson['name'] as String,
sponsored: parsedJson['sponsored'] as String
);
}
}
And I am comparing two instances of Diners( sponsored and diners)
I use this query to attempt to compare the text that is put in to the search bar:
final suggestionList = query.isEmpty
? sponsored
: diners
.where((p) => p.name.startsWith(query)).toList();
But I'm getting this error
"type '(dynamic) => dynamic' is not a subtype of type '(Diner) => bool' of 'test'
I'm not sure why

Executing rxjs observable function recursively

I'm new to RxJs. I'm trying to run observable function recursively with no luck. I want to print in this order.
form textbox icon textarea
Here is what I tried so far. Any help will be very much appreciated.
const args = {
name: 'form',
children: [{
name: 'textbox',
children: [{
name: 'icon',
children: []
}]
}, {
name: 'textarea',
children: []
}]
};
import { of, from, Observable, concat } from 'rxjs';
import { map, concatAll, combineAll } from 'rxjs/operators';
const render = (component) => {
return new Observable<any>(observer => {
console.log(component.name);
concat(...component.children.map(x => render(x)))
.subscribe(() => observer.next());
});
};
render(args).subscribe(() => console.log('done'));
This gives the correct order. If I've missed something, please comment:
const { of, concat } = rxjs;
const args = {
name: 'form',
children: [
{
name: 'textbox',
children: [
{
name: 'icon',
children: []
}
]
},
{
name: 'textarea',
children: []
}
]
};
const render = (component) => concat(of(component), ...component.children.map(render));
render(args).subscribe(({name}) => console.log(name));
<script src="https://unpkg.com/#reactivex/rxjs#6.4/dist/global/rxjs.umd.js"></script>

GraphQL association issue

Before diving into the code, here is a high-level explanation of my question:
In my GraphQL schema, I have two root types: Developers and Projects. I'm attempting to find all developers who are part of a given project. The query might look like this:
{
project(id:2) {
title
developers {
firstName
lastName
}
}
}
Currently, I'm getting a null value for developers.
Dummy data
const developers = [
{
id: '1',
firstName: 'Brent',
lastName: 'Journeyman',
projectIds: ['1', '2']
},
{
id: '2',
firstName: 'Laura',
lastName: 'Peterson',
projectIds: ['2']
}
]
const projects = [
{
id: '1',
title: 'Experimental Drug Bonanza',
company: 'Pfizer',
duration: 20,
},
{
id: '2',
title: 'Terrible Coffee Holiday Sale',
company: 'Starbucks',
duration: 45,
}
]
So, Brent has worked on both projects. Laura has worked on the second project. My issue is in the resolve function in ProjectType. I've tried many queries, but none seem to work.
ProjectType
const ProjectType = new GraphQLObjectType({
name: 'Project',
fields: () => ({
id: { type: GraphQLID },
title: { type: GraphQLString },
company: { type: GraphQLString },
duration: { type: GraphQLInt },
developers: {
type: GraphQLList(DeveloperType),
resolve(parent, args) {
///////////////////////
// HERE IS THE ISSUE //
//////////////////////
return _.find(developers, { id: ? });
}
}
})
})
DeveloperType
const DeveloperType = new GraphQLObjectType({
name: 'Developer',
fields: () => ({
id: { type: GraphQLID },
firstName: { type: GraphQLString },
lastName: { type: GraphQLString }
})
})
So you need to return all the developers having current project's id in their .projectIds, right?
First, _.find cannot help since it returns first matched element and you need to get array with developers(since field has GraphQLList type).
So how about
resolve(parent, args) {
return developers.filter(
({projectIds}) => projectIds.indexOf(parent.id) !== -1
);
}

Resources