问:
ranges views size does not compile
```<code>#include <iostream>
#include <cstdlib>
#include <vector>
#include <ranges>
#include <algorithm>
using namespace std;

int main()
{
    vector<int> ints = {1,2,3,4,5};
    auto v = ints | views::take_while([](int i){return i<3;}) ;
    for (int i : v) std::cout << i << ' ';
    std::cout << '\n';
    int size = v.size();
    std::cout << size << std::endl;
}
</code>```

v.size() does not compile. How do you do this ?

```<code>prog.cc: In function 'int main()':
prog.cc:16:23: error: no matching function for call to 'std::ranges::take_while_view<std::ranges::ref_view<std::vector<int> >, main()::<lambda(int)> >::size()'
   16 |     int size = v.size();
      |                       ^
In file included from prog.cc:5:
/opt/wandbox/gcc-10.2.0/include/c++/10.2.0/ranges:144:7: note: candidate: 'constexpr auto std::ranges::view_interface<_Derived>::size() requires (forward_range<_Derived>) && (sized_sentinel_for<decltype(std::ranges::__cust::end((declval<_Tp&>)())), decltype(std::__detail::__ranges_begin((declval<_Container&>)()))>) [with _Derived = std::ranges::take_while_view<std::ranges::ref_view<std::vector<int> >, main()::<lambda(int)> >]'
  144 |       size()
      |       ^~~~
/opt/wandbox/gcc-10.2.0/include/c++/10.2.0/ranges:144:7: note: constraints not satisfied
In file included from /opt/wandbox/gcc-10.2.0/include/c++/10.2.0/bits/stl_iterator_base_types.h:71,
                 from /opt/wandbox/gcc-10.2.0/include/c++/10.2.0/bits/stl_algobase.h:65,
                 from /opt/wandbox/gcc-10.2.0/include/c++/10.2.0/bits/char_traits.h:39,
                 from /opt/wandbox/gcc-10.2.0/include/c++/10.2.0/ios:40,
                 from /opt/wandbox/gcc-10.2.0/include/c++/10.2.0/ostream:38,
                 from /opt/wandbox/gcc-10.2.0/include/c++/10.2.0/iostream:39,
                 from prog.cc:2:
/opt/wandbox/gcc-10.2.0/include/c++/10.2.0/bits/iterator_concepts.h: In instantiation of 'constexpr auto std::ranges::view_interface<_Derived>::size() requires (forward_range<_Derived>) && (sized_sentinel_for<decltype(std::ranges::__cust::end((declval<_Tp&>)())), decltype(std::__detail::__ranges_begin((declval<_Container&>)()))>) [with _Derived = std::ranges::take_while_view<std::ranges::ref_view<std::vector<int> >, main()::<lambda(int)> >]':
prog.cc:16:23:   required from here
/opt/wandbox/gcc-10.2.0/include/c++/10.2.0/bits/iterator_concepts.h:555:13:   required for the satisfaction of 'sized_sentinel_for<std::ranges::sentinel_t<_Tp>, decltype (std::__detail::__ranges_begin(declval<_Container&>()))>' [with _Tp = std::ranges::take_while_view<std::ranges::ref_view<std::vector<int, std::allocator<int> > >, main::._anon_124>; _Container = std::ranges::take_while_view<std::ranges::ref_view<std::vector<int, std::allocator<int> > >, main::._anon_124>]
/opt/wandbox/gcc-10.2.0/include/c++/10.2.0/bits/iterator_concepts.h:557:8:   in requirements with 'const _Iter& __i', 'const _Sent& __s' [with _Arg = __gnu_cxx::__normal_iterator<int*, std::vector<int, std::allocator<int> > >; _Sent = std::ranges::take_while_view<std::ranges::ref_view<std::vector<int, std::allocator<int> > >, main::._anon_124>::_Sentinel<true>; _Iter = __gnu_cxx::__normal_iterator<int*, std::vector<int, std::allocator<int> > >]
/opt/wandbox/gcc-10.2.0/include/c++/10.2.0/bits/iterator_concepts.h:559:13: note: the required expression '(__s - __i)' is invalid
  559 |       { __s - __i } -> same_as<iter_difference_t<_Iter>>;
      |         ~~~~^~~~~
/opt/wandbox/gcc-10.2.0/include/c++/10.2.0/bits/iterator_concepts.h:560:13: note: the required expression '(__i - __s)' is invalid
  560 |       { __i - __s } -> same_as<iter_difference_t<_Iter>>;
      |         ~~~~^~~~~
cc1plus: note: set '-fconcepts-diagnostics-depth=' to at least 2 for more detail
In file included from prog.cc:5:
/opt/wandbox/gcc-10.2.0/include/c++/10.2.0/ranges:150:7: note: candidate: 'constexpr auto std::ranges::view_interface<_Derived>::size() const requires (forward_range<const _Derived>) && (sized_sentinel_for<decltype(std::ranges::__cust::end((declval<const _Range&>)())), decltype(std::__detail::__ranges_begin((declval<const _Range&>)()))>) [with _Derived = std::ranges::take_while_view<std::ranges::ref_view<std::vector<int> >, main()::<lambda(int)> >]'
  150 |       size() const
      |       ^~~~
/opt/wandbox/gcc-10.2.0/include/c++/10.2.0/ranges:150:7: note: constraints not satisfied
In file included from /opt/wandbox/gcc-10.2.0/include/c++/10.2.0/bits/stl_iterator_base_types.h:71,
                 from /opt/wandbox/gcc-10.2.0/include/c++/10.2.0/bits/stl_algobase.h:65,
                 from /opt/wandbox/gcc-10.2.0/include/c++/10.2.0/bits/char_traits.h:39,
                 from /opt/wandbox/gcc-10.2.0/include/c++/10.2.0/ios:40,
                 from /opt/wandbox/gcc-10.2.0/include/c++/10.2.0/ostream:38,
                 from /opt/wandbox/gcc-10.2.0/include/c++/10.2.0/iostream:39,
                 from prog.cc:2:
/opt/wandbox/gcc-10.2.0/include/c++/10.2.0/bits/iterator_concepts.h: In instantiation of 'constexpr auto std::ranges::view_interface<_Derived>::size() const requires (forward_range<const _Derived>) && (sized_sentinel_for<decltype(std::ranges::__cust::end((declval<const _Range&>)())), decltype(std::__detail::__ranges_begin((declval<const _Range&>)()))>) [with _Derived = std::ranges::take_while_view<std::ranges::ref_view<std::vector<int> >, main()::<lambda(int)> >]':
prog.cc:16:23:   required from here
/opt/wandbox/gcc-10.2.0/include/c++/10.2.0/bits/iterator_concepts.h:555:13:   required for the satisfaction of 'sized_sentinel_for<std::ranges::sentinel_t<const _Range>, decltype (std::__detail::__ranges_begin(declval<const _Range&>()))>' [with _Range = std::ranges::take_while_view<std::ranges::ref_view<std::vector<int, std::allocator<int> > >, main::._anon_124>]
/opt/wandbox/gcc-10.2.0/include/c++/10.2.0/bits/iterator_concepts.h:557:8:   in requirements with 'const _Iter& __i', 'const _Sent& __s' [with _Arg = __gnu_cxx::__normal_iterator<int*, std::vector<int, std::allocator<int> > >; _Sent = std::ranges::take_while_view<std::ranges::ref_view<std::vector<int, std::allocator<int> > >, main::._anon_124>::_Sentinel<true>; _Iter = __gnu_cxx::__normal_iterator<int*, std::vector<int, std::allocator<int> > >]
/opt/wandbox/gcc-10.2.0/include/c++/10.2.0/bits/iterator_concepts.h:559:13: note: the required expression '(__s - __i)' is invalid
  559 |       { __s - __i } -> same_as<iter_difference_t<_Iter>>;
      |         ~~~~^~~~~
/opt/wandbox/gcc-10.2.0/include/c++/10.2.0/bits/iterator_concepts.h:560:13: note: the required expression '(__i - __s)' is invalid
  560 |       { __i - __s } -> same_as<iter_difference_t<_Iter>>;
      |         ~~~~^~~~~
</code>```

答:
Since take_while and its ilk shorten the size of the list in unpredictable ways, those range adaptors cannot return a sized_range, even if the input itself is sized. sized_range requires that the range can compute the size in O(1) time, and take_while's view cannot do that.

So if you want the size (and you shouldn't), you will have to compute it yourself. You could also use std::ranges::distance on the range.

Title: ranges views size does not compile

Body:
#include <iostream>
#include <cstdlib>
#include <vector>
#include <ranges>
#include <algorithm>
using namespace std;

int main()
{
    vector<int> ints = {1,2,3,4,5};
    auto v = ints | views::take_while([](int i){return i<3;}) ;
    for (int i : v) std::cout << i << ' ';
    std::cout << '\n';
    int size = v.size();
    std::cout << size << std::endl;
}

v.size() does not compile. How do you do this ?

prog.cc: In function 'int main()':
prog.cc:16:23: error: no matching function for call to 'std::ranges::take_while_view<std::ranges::ref_view<std::vector<int> >, main()::<lambda(int)> >::size()'
   16 |     int size = v.size();
      |                       ^
In file included from prog.cc:5:
/opt/wandbox/gcc-10.2.0/include/c++/10.2.0/ranges:144:7: note: candidate: 'constexpr auto std::ranges::view_interface<_Derived>::size() requires (forward_range<_Derived>) && (sized_sentinel_for<decltype(std::ranges::__cust::end((declval<_Tp&>)())), decltype(std::__detail::__ranges_begin((declval<_Container&>)()))>) [with _Derived = std::ranges::take_while_view<std::ranges::ref_view<std::vector<int> >, main()::<lambda(int)> >]'
  144 |       size()
      |       ^~~~
/opt/wandbox/gcc-10.2.0/include/c++/10.2.0/ranges:144:7: note: constraints not satisfied
In file included from /opt/wandbox/gcc-10.2.0/include/c++/10.2.0/bits/stl_iterator_base_types.h:71,
                 from /opt/wandbox/gcc-10.2.0/include/c++/10.2.0/bits/stl_algobase.h:65,
                 from /opt/wandbox/gcc-10.2.0/include/c++/10.2.0/bits/char_traits.h:39,
                 from /opt/wandbox/gcc-10.2.0/include/c++/10.2.0/ios:40,
                 from /opt/wandbox/gcc-10.2.0/include/c++/10.2.0/ostream:38,
                 from /opt/wandbox/gcc-10.2.0/include/c++/10.2.0/iostream:39,
                 from prog.cc:2:
/opt/wandbox/gcc-10.2.0/include/c++/10.2.0/bits/iterator_concepts.h: In instantiation of 'constexpr auto std::ranges::view_interface<_Derived>::size() requires (forward_range<_Derived>) && (sized_sentinel_for<decltype(std::ranges::__cust::end((declval<_Tp&>)())), decltype(std::__detail::__ranges_begin((declval<_Container&>)()))>) [with _Derived = std::ranges::take_while_view<std::ranges::ref_view<std::vector<int> >, main()::<lambda(int)> >]':
prog.cc:16:23:   required from here
/opt/wandbox/gcc-10.2.0/include/c++/10.2.0/bits/iterator_concepts.h:555:13:   required for the satisfaction of 'sized_sentinel_for<std::ranges::sentinel_t<_Tp>, decltype (std::__detail::__ranges_begin(declval<_Container&>()))>' [with _Tp = std::ranges::take_while_view<std::ranges::ref_view<std::vector<int, std::allocator<int> > >, main::._anon_124>; _Container = std::ranges::take_while_view<std::ranges::ref_view<std::vector<int, std::allocator<int> > >, main::._anon_124>]
/opt/wandbox/gcc-10.2.0/include/c++/10.2.0/bits/iterator_concepts.h:557:8:   in requirements with 'const _Iter& __i', 'const _Sent& __s' [with _Arg = __gnu_cxx::__normal_iterator<int*, std::vector<int, std::allocator<int> > >; _Sent = std::ranges::take_while_view<std::ranges::ref_view<std::vector<int, std::allocator<int> > >, main::._anon_124>::_Sentinel<true>; _Iter = __gnu_cxx::__normal_iterator<int*, std::vector<int, std::allocator<int> > >]
/opt/wandbox/gcc-10.2.0/include/c++/10.2.0/bits/iterator_concepts.h:559:13: note: the required expression '(__s - __i)' is invalid
  559 |       { __s - __i } -> same_as<iter_difference_t<_Iter>>;
      |         ~~~~^~~~~
/opt/wandbox/gcc-10.2.0/include/c++/10.2.0/bits/iterator_concepts.h:560:13: note: the required expression '(__i - __s)' is invalid
  560 |       { __i - __s } -> same_as<iter_difference_t<_Iter>>;
      |         ~~~~^~~~~
cc1plus: note: set '-fconcepts-diagnostics-depth=' to at least 2 for more detail
In file included from prog.cc:5:
/opt/wandbox/gcc-10.2.0/include/c++/10.2.0/ranges:150:7: note: candidate: 'constexpr auto std::ranges::view_interface<_Derived>::size() const requires (forward_range<const _Derived>) && (sized_sentinel_for<decltype(std::ranges::__cust::end((declval<const _Range&>)())), decltype(std::__detail::__ranges_begin((declval<const _Range&>)()))>) [with _Derived = std::ranges::take_while_view<std::ranges::ref_view<std::vector<int> >, main()::<lambda(int)> >]'
  150 |       size() const
      |       ^~~~
/opt/wandbox/gcc-10.2.0/include/c++/10.2.0/ranges:150:7: note: constraints not satisfied
In file included from /opt/wandbox/gcc-10.2.0/include/c++/10.2.0/bits/stl_iterator_base_types.h:71,
                 from /opt/wandbox/gcc-10.2.0/include/c++/10.2.0/bits/stl_algobase.h:65,
                 from /opt/wandbox/gcc-10.2.0/include/c++/10.2.0/bits/char_traits.h:39,
                 from /opt/wandbox/gcc-10.2.0/include/c++/10.2.0/ios:40,
                 from /opt/wandbox/gcc-10.2.0/include/c++/10.2.0/ostream:38,
                 from /opt/wandbox/gcc-10.2.0/include/c++/10.2.0/iostream:39,
                 from prog.cc:2:
/opt/wandbox/gcc-10.2.0/include/c++/10.2.0/bits/iterator_concepts.h: In instantiation of 'constexpr auto std::ranges::view_interface<_Derived>::size() const requires (forward_range<const _Derived>) && (sized_sentinel_for<decltype(std::ranges::__cust::end((declval<const _Range&>)())), decltype(std::__detail::__ranges_begin((declval<const _Range&>)()))>) [with _Derived = std::ranges::take_while_view<std::ranges::ref_view<std::vector<int> >, main()::<lambda(int)> >]':
prog.cc:16:23:   required from here
/opt/wandbox/gcc-10.2.0/include/c++/10.2.0/bits/iterator_concepts.h:555:13:   required for the satisfaction of 'sized_sentinel_for<std::ranges::sentinel_t<const _Range>, decltype (std::__detail::__ranges_begin(declval<const _Range&>()))>' [with _Range = std::ranges::take_while_view<std::ranges::ref_view<std::vector<int, std::allocator<int> > >, main::._anon_124>]
/opt/wandbox/gcc-10.2.0/include/c++/10.2.0/bits/iterator_concepts.h:557:8:   in requirements with 'const _Iter& __i', 'const _Sent& __s' [with _Arg = __gnu_cxx::__normal_iterator<int*, std::vector<int, std::allocator<int> > >; _Sent = std::ranges::take_while_view<std::ranges::ref_view<std::vector<int, std::allocator<int> > >, main::._anon_124>::_Sentinel<true>; _Iter = __gnu_cxx::__normal_iterator<int*, std::vector<int, std::allocator<int> > >]
/opt/wandbox/gcc-10.2.0/include/c++/10.2.0/bits/iterator_concepts.h:559:13: note: the required expression '(__s - __i)' is invalid
  559 |       { __s - __i } -> same_as<iter_difference_t<_Iter>>;
      |         ~~~~^~~~~
/opt/wandbox/gcc-10.2.0/include/c++/10.2.0/bits/iterator_concepts.h:560:13: note: the required expression '(__i - __s)' is invalid
  560 |       { __i - __s } -> same_as<iter_difference_t<_Iter>>;
      |         ~~~~^~~~~


来源: stackexchange

问:
Discord.js API "Missing Access" while registering my slash commands
I have a small discord bot I made 3 years ago in Typescript and is present on over 80 guilds, I recently decided to update it from discord.js-v12.3.1-dev to discord.js-v13.6, while adding the famous slash commands.

But when I register them with the discord.js's Routes.applicationGuildCommands routine in my "ready" event when I map over each Guild where my bot is present, the methode Routes.applicationGuildCommands return me an error Missing Access on most of my guilds (but not all !):

```<code>Trace: S[50001]: Missing Access
    at Q.runRequest (/home/user/bot/node_modules/@discordjs/rest/src/lib/handlers/SequentialHandler.ts:487:11)
    at processTicksAndRejections (node:internal/process/task_queues:96:5)
    at async Q.queueRequest (/home/user/bot/node_modules/@discordjs/rest/src/lib/handlers/SequentialHandler.ts:200:11)
    at async /home/user/bot/src/discord.ts:21:9
    at async Promise.all (index 50)
    at async Client.<anonymous> (/home/user/bot/src/discord.ts:19:5) {
  rawError: { message: 'Missing Access', code: 50001 },
  code: 50001,
  status: 403,
  method: 'put',
  url: 'https://discord.com/api/v9/applications/642935463048642470/guilds/907457626412628088/commands',
  requestBody: { files: undefined, json: [ [Object], [Object] ] }
}
    at /home/user/bot/src/discord.ts:21:17
    at processTicksAndRejections (node:internal/process/task_queues:96:5)
    at async Promise.all (index 50)
    at async Client.<anonymous> (/home/user/botsrc/discord.ts:19:5)
</code>```

Here is my code snipet (it's just some part of my code, I cut all unrelated part of the code).

I know the methode Routes.applicationCommands exist but it's the same result, and I want to push my commands separatly over my guilds in order to traduct my commands descriptions later.

import { Client, Intents, Guild } from 'discord.js';
import { REST                   } from '@discordjs/rest';
import { Routes                 } from 'discord-api-types/v9';
import * as commands              from "./commands/";

export const bot: Client = new Client({
  intents: [
    Intents.FLAGS.GUILDS,
    Intents.FLAGS.GUILD_MEMBERS,
    Intents.FLAGS.GUILD_MESSAGES,
    Intents.FLAGS.DIRECT_MESSAGES,
    Intents.FLAGS.GUILD_MESSAGE_REACTIONS
  ]
});

bot.on("ready", async (): Promise<void> => {
    const commandsList: any[] = Object.keys(commands)?.map((name: string) => commands[name]);
    console.log(`Curently connected on (${bot.guilds.cache.size}) servers:`);
    await Promise.all(bot.guilds.cache.map(async (guild: Guild) => {
      try {
        await rest.put(Routes.applicationGuildCommands(bot.user.id, guild.id), { body: commandsList });
        console.log(` - ${guild.name} ✔`);
      } catch (error) {
        console.log(` - ${guild.name} ❌`);
        console.trace(error);
      }
    }));
    console.log(`${commandsList.length} imported command${commandsList.length ? 's' : ''}.`);
    await bot.user.setActivity("le Krosmoz", { type: "WATCHING" });
});
```
<p>my <code>commandsList</code> object created at the first line of my <code>ready</code> event <strong>is valid</strong> and looks like this:</p>
<pre class="lang-js prettyprint-override"><code>commandsList = [
  {
    name: 'help',
    description: 'Print the list of commands'
  },
  {
    name: 'toto',
    description: 'Lorem ipsum dolor sit amet, consectetur adipiscing elit'
    options: [
      {
        name: 'date',
        description: "The toto's date",
        type: 3,
        required: false
      },
      {
        name: 'item',
        description: "The toto's item",
        type: 3,
        required: false
      }
    ]
  }
]
</code>```

My code above somelike "works", but all my servers where my bots is present don't have the commands registered, a list of all my servers and if the Routes.applicationGuildCommands succeded or not is shown in the bot's console like this:

```<code>Curently connected on (9) servers:
 - Guild1 ❌
 - Guild2 ✔
 - Guild3 ❌
 - Guild4 ❌
 - Guild5 ❌
 - Guild6 ❌
 - Guild7 ❌
 - Guild8 ✔
 - Guild9 ❌
</code>```

Resulting from the console.log( - ${guild.name} ✔); or console.log( - ${guild.name} ❌);, (When the ❌ show up, it means the Missing Access where encountered).

My question is: How can I successfully register my slash commands on all my bot's guild ?

Some of it's guild where he successfully registered them (no Missing Access error and a ✔) don't have my bot's commands (even with reloading the discord clients and waiting for hours and days in case of cache's issues), some of my bot's guild where the Missing Access is encountered can still have the list of my bot's commands working...

When all my bot's guild added him, the applications.commands didn't even existed so may be if each guild's owner kick him and reinvite him would fix it, but a lot of bots (such as big one like MEE6, Tatsumaki & co) successfully pushed their slash commands regardless of their permissions on the guild, without needing to be kicked and reinvited. Even grant administrator permission on my bot's don't allow him to successfully register his commands on a mere test server.

I already read the whole "Application Commands" part of https://discord.com/developers/docs/interactions/application-commands 's guide but no clues, found on StackOverflow the application.commands.update scope should be added (but not present in my bot's portal).

I am missing something ?

And I really don't wanna kick my bot of all of his guilds to reinvite it with the applications.commands scope while a lot of other bots didn't needed to do it.

答:
Unfortunately, if your app does not have the applications.commands intent in a guild, it cannot create slash commands there. You could send a message in guilds with a new oauth link to add the bot with the applications.commands intent when someone uses a non-slash command.

Regarding:
And I really don't wanna kick my bot of all of his guilds to reinvite it with the applications.commands scope while a lot of other bots didn't needed to do it.

Discord added the applications.commands intent to all guilds with existing bots in them, but if the bot was added after this without the intent it wouldn’t work.

ContentLicense: CC BY-SA 4.0

Body:
I have a small discord bot I made 3 years ago in Typescript and is present on over 80 guilds, I recently decided to update it from discord.js-v12.3.1-dev to discord.js-v13.6, while adding the famous slash commands.

But when I register them with the discord.js's Routes.applicationGuildCommands routine in my "ready" event when I map over each Guild where my bot is present, the methode Routes.applicationGuildCommands return me an error Missing Access on most of my guilds (but not all !):

Trace: S[50001]: Missing Access
    at Q.runRequest (/home/user/bot/node_modules/@discordjs/rest/src/lib/handlers/SequentialHandler.ts:487:11)
    at processTicksAndRejections (node:internal/process/task_queues:96:5)
    at async Q.queueRequest (/home/user/bot/node_modules/@discordjs/rest/src/lib/handlers/SequentialHandler.ts:200:11)
    at async /home/user/bot/src/discord.ts:21:9
    at async Promise.all (index 50)
    at async Client.<anonymous> (/home/user/bot/src/discord.ts:19:5) {
  rawError: { message: 'Missing Access', code: 50001 },
  code: 50001,
  status: 403,
  method: 'put',
  url: 'https://discord.com/api/v9/applications/642935463048642470/guilds/907457626412628088/commands',
  requestBody: { files: undefined, json: [ [Object], [Object] ] }
}
    at /home/user/bot/src/discord.ts:21:17
    at processTicksAndRejections (node:internal/process/task_queues:96:5)
    at async Promise.all (index 50)
    at async Client.<anonymous> (/home/user/botsrc/discord.ts:19:5)

Here is my code snipet (it's just some part of my code, I cut all unrelated part of the code).

I know the methode Routes.applicationCommands exist but it's the same result, and I want to push my commands separatly over my guilds in order to traduct my commands descriptions later.

import { Client, Intents, Guild } from 'discord.js';
import { REST                   } from '@discordjs/rest';
import { Routes                 } from 'discord-api-types/v9';
import * as commands              from "./commands/";

export const bot: Client = new Client({
  intents: [
    Intents.FLAGS.GUILDS,
    Intents.FLAGS.GUILD_MEMBERS,
    Intents.FLAGS.GUILD_MESSAGES,
    Intents.FLAGS.DIRECT_MESSAGES,
    Intents.FLAGS.GUILD_MESSAGE_REACTIONS
  ]
});

bot.on("ready", async (): Promise<void> => {
    const commandsList: any[] = Object.keys(commands)?.map((name: string) => commands[name]);
    console.log(`Curently connected on (${bot.guilds.cache.size}) servers:`);
    await Promise.all(bot.guilds.cache.map(async (guild: Guild) => {
      try {
        await rest.put(Routes.applicationGuildCommands(bot.user.id, guild.id), { body: commandsList });
        console.log(` - ${guild.name} ✔`);
      } catch (error) {
        console.log(` - ${guild.name} ❌`);
        console.trace(error);
      }
    }));
    console.log(`${commandsList.length} imported command${commandsList.length ? 's' : ''}.`);
    await bot.user.setActivity("le Krosmoz", { type: "WATCHING" });
});

my commandsList object created at the first line of my ready event is valid and looks like this:

commandsList = [
  {
    name: 'help',
    description: 'Print the list of commands'
  },
  {
    name: 'toto',
    description: 'Lorem ipsum dolor sit amet, consectetur adipiscing elit'
    options: [
      {
        name: 'date',
        description: "The toto's date",
        type: 3,
        required: false
      },
      {
        name: 'item',
        description: "The toto's item",
        type: 3,
        required: false
      }
    ]
  }
]

My code above somelike "works", but all my servers where my bots is present don't have the commands registered, a list of all my servers and if the Routes.applicationGuildCommands succeded or not is shown in the bot's console like this:

Curently connected on (9) servers:
 - Guild1 ❌
 - Guild2 ✔
 - Guild3 ❌
 - Guild4 ❌
 - Guild5 ❌
 - Guild6 ❌
 - Guild7 ❌
 - Guild8 ✔
 - Guild9 ❌

Resulting from the console.log( - ${guild.name} ✔); or console.log( - ${guild.name} ❌);, (When the ❌ show up, it means the Missing Access where encountered).

My question is: How can I successfully register my slash commands on all my bot's guild ?

Some of it's guild where he successfully registered them (no Missing Access error and a ✔) don't have my bot's commands (even with reloading the discord clients and waiting for hours and days in case of cache's issues), some of my bot's guild where the Missing Access is encountered can still have the list of my bot's commands working...

When all my bot's guild added him, the applications.commands didn't even existed so may be if each guild's owner kick him and reinvite him would fix it, but a lot of bots (such as big one like MEE6, Tatsumaki & co) successfully pushed their slash commands regardless of their permissions on the guild, without needing to be kicked and reinvited. Even grant administrator permission on my bot's don't allow him to successfully register his commands on a mere test server.

I already read the whole "Application Commands" part of https://discord.com/developers/docs/interactions/application-commands 's guide but no clues, found on StackOverflow the application.commands.update scope should be added (but not present in my bot's portal).

I am missing something ?

And I really don't wanna kick my bot of all of his guilds to reinvite it with the applications.commands scope while a lot of other bots didn't needed to do it.


问:
Empirically determine value category of C++11 expression?
Each expression in C++11 has a value category.  One of lvalue, xvalue or prvalue.

Is there a way to write a macro that, given any expression as an argument, will produce a string "lvalue", "xvalue" or "prvalue" as appropriate?

For example:

```<code>int main()
{
    int x;

    cout << VALUE_CAT(x) << endl; // prints lvalue
    cout << VALUE_CAT(move(x)) << endl; // prints xvalue
    cout << VALUE_CAT(42) << endl; // prints prvalue
}
</code>```

How could VALUE_CAT be implemented?

答:
```<code>#ifndef _TPF_TYPE_NAME_H
#define _TPF_TYPE_NAME_H

template <typename T>
constexpr bool is_lvalue_helper = std::is_lvalue_reference<T>::value;

template <typename T>
constexpr bool is_xvalue_helper = std::is_rvalue_reference<T>::value;

template <typename T>
constexpr bool is_prvalue_helper = !(is_lvalue_helper<T> || is_xvalue_helper<T>);

template <typename T>
constexpr bool is_rvalue_helper = is_xvalue_helper<T> || is_prvalue_helper<T>;

template <typename T>
constexpr bool is_glvalue_helper = is_xvalue_helper<T> || is_lvalue_helper<T>;

#define is_lvalue(type_instance) is_lvalue_helper<decltype((type_instance))>
#define is_xvalue(type_instance) is_xvalue_helper<decltype((type_instance))>
#define is_prvalue(type_instance)is_prvalue_helper<decltype((type_instance))>
#define is_rvalue(type_instance) is_rvalue_helper<decltype((type_instance))>
#define is_glvalue(type_instance)is_glvalue_helper<decltype((type_instance))>

#endif // end of _TPF_TYPE_NAME_H
</code>```

ContentLicense: CC BY-SA 3.0

Body:
Each expression in C++11 has a value category.  One of lvalue, xvalue or prvalue.

Is there a way to write a macro that, given any expression as an argument, will produce a string "lvalue", "xvalue" or "prvalue" as appropriate?

For example:

int main()
{
    int x;

    cout << VALUE_CAT(x) << endl; // prints lvalue
    cout << VALUE_CAT(move(x)) << endl; // prints xvalue
    cout << VALUE_CAT(42) << endl; // prints prvalue
}

How could VALUE_CAT be implemented?


问:
Flutter - How can i play Randoms video from YouTube using a special title
is it possible to add Randoms video to my flutter app from YouTube   using a specific  title
for example I want to display Randoms "Football" video in my app ?</p>

答:
It is possible to add youtube videos to Flutter applications through a variety of methods. Refer This plugin

For more info: Refer this medium article

The plugin supports a variety of features like custom buffering progress indicator, custom progress bar, standard audio/video control configurations.

Let's take an example URL: youtube.com/watch?v=123iamosum456

The value after "v=" is the video ID of that particular video which you would need to provide.


问:
Owned entity causes InvalidOperationException after upgrading to EF Core 6.0
After upgrading Microsoft.AspNetCore.Identity.EntityFrameworkCore, Microsoft.EntityFrameworkCore.Tools and Npgsql.EntityFrameworkCore.PostgreSQL nugget packages to version 6.0.0, my .NET 6.0 Web API started throwing this exception:

The entity type 'RefreshToken' has been marked as owned and must be
referenced from another entity type via a navigation. Add a navigation
to an entity type that points at 'RefreshToken' or don't configure it
as owned.

The exception seems to be thrown whenever executing any operation that involves the database.
If I understand the error correctly, it does not find the navigation in RefreshToken entity configuration, however my automatically generated ModelSnapshot does seem to contain it.

RefreshToken.cs (some properties were removed for simplification purposes)

```<code>[Owned]
public class RefreshToken
{
    [Key]
    public int Id { get; set; }
    public string Token { get; set; }
    public virtual User User { get; set; }
}
</code>```

User.cs

```<code>public class User : IdentityUser
{
    public List<RefreshToken> RefreshTokens { get; set; }
}
</code>```

Excerpt from BuildModel(ModelBuilder modelBuilder)

```<code>modelBuilder.Entity("API.Models.User", b =>
    {
        b.OwnsMany("API.Models.RefreshToken", "RefreshTokens", b1 =>
            {
                b1.Property<int>("Id")
                    .ValueGeneratedOnAdd()
                    .HasColumnType("integer")
                    .HasAnnotation("Npgsql:ValueGenerationStrategy", NpgsqlValueGenerationStrategy.IdentityByDefaultColumn);

                b1.Property<string>("Token")
                    .HasColumnType("text");

                b1.Property<string>("UserId")
                    .IsRequired()
                    .HasColumnType("text");

                b1.HasKey("Id");

                b1.HasIndex("UserId");

                b1.ToTable("RefreshTokens");

                b1.WithOwner()
                    .HasForeignKey("UserId");
            });

        b.Navigation("RefreshTokens");
    });
</code>```

I've looked through EF Core 6.0 Breaking Changes (https://learn.microsoft.com/en-us/ef/core/what-is-new/ef-core-6.0/breaking-changes#owned-index) but could not find what would cause this issue.

答:
I got a reply on that github thread I linked to, which contains a fix for me that works. In my case I do not use the Attributes, so you might have to switch to the fluent API.

The thread also has a reference to a 7.0.0 milestone, so that might be worth checking out if you are from the future.

```<code>modelBuilder.Entity<DerivedDerivedClass>().OwnsOne(d => d.OwnedType);

modelBuilder.Entity<DerivedClass>().OwnsOne(d => d.OwnedType);
</code>```

As a workaround avoid calling modelBuilder.Entity().OwnsOne(d => d.OwnedType);

As I understand it, you only want to configure it ONCE on the derived class, and not configure it again on the DerivedDerivedClass.

Body:
After upgrading Microsoft.AspNetCore.Identity.EntityFrameworkCore, Microsoft.EntityFrameworkCore.Tools and Npgsql.EntityFrameworkCore.PostgreSQL nugget packages to version 6.0.0, my .NET 6.0 Web API started throwing this exception:

The entity type 'RefreshToken' has been marked as owned and must be
referenced from another entity type via a navigation. Add a navigation
to an entity type that points at 'RefreshToken' or don't configure it
as owned.

The exception seems to be thrown whenever executing any operation that involves the database.
If I understand the error correctly, it does not find the navigation in RefreshToken entity configuration, however my automatically generated ModelSnapshot does seem to contain it.

RefreshToken.cs (some properties were removed for simplification purposes)

[Owned]
public class RefreshToken
{
    [Key]
    public int Id { get; set; }
    public string Token { get; set; }
    public virtual User User { get; set; }
}

User.cs

public class User : IdentityUser
{
    public List<RefreshToken> RefreshTokens { get; set; }
}

Excerpt from BuildModel(ModelBuilder modelBuilder)

modelBuilder.Entity("API.Models.User", b =>
    {
        b.OwnsMany("API.Models.RefreshToken", "RefreshTokens", b1 =>
            {
                b1.Property<int>("Id")
                    .ValueGeneratedOnAdd()
                    .HasColumnType("integer")
                    .HasAnnotation("Npgsql:ValueGenerationStrategy", NpgsqlValueGenerationStrategy.IdentityByDefaultColumn);

                b1.Property<string>("Token")
                    .HasColumnType("text");

                b1.Property<string>("UserId")
                    .IsRequired()
                    .HasColumnType("text");

                b1.HasKey("Id");

                b1.HasIndex("UserId");

                b1.ToTable("RefreshTokens");

                b1.WithOwner()
                    .HasForeignKey("UserId");
            });

        b.Navigation("RefreshTokens");
    });

I've looked through EF Core 6.0 Breaking Changes (https://learn.microsoft.com/en-us/ef/core/what-is-new/ef-core-6.0/breaking-changes#owned-index) but could not find what would cause this issue.

Body:
I got a reply on that github thread I linked to, which contains a fix for me that works. In my case I do not use the Attributes, so you might have to switch to the fluent API.

The thread also has a reference to a 7.0.0 milestone, so that might be worth checking out if you are from the future.

modelBuilder.Entity<DerivedDerivedClass>().OwnsOne(d => d.OwnedType);

modelBuilder.Entity<DerivedClass>().OwnsOne(d => d.OwnedType);

As a workaround avoid calling modelBuilder.Entity().OwnsOne(d => d.OwnedType);

As I understand it, you only want to configure it ONCE on the derived class, and not configure it again on the DerivedDerivedClass.


问:
KQL - is it possible to select the scope inside a request?
I specify cluster+database+table

```<code>cluster("my_company_kusto.westeurope").database("events").table("CourierEvents")
| where OrderId == "C61F4D3A8B93975111EC8A629DDBCF0E"
</code>```

but I get an error Please select a database to execute queries. until I select a table in the left menu and the scope appears on the top.

Is it possible to select the scope inside a request without selecting it in a left menu?

答:
I assume that you are using one of the tools (Kusto Explorer or the Kusto Web explorer), if so the answer is yes. See the connection panel topic in the Kusto Explorer docs, and here is the applicable example:

```<code>#connect cluster('help').database('Samples')

StormEvents | count
</code>```

Execute the first line, and it will set your context to the applicable cluster and database.

Body:
I specify cluster+database+table

cluster("my_company_kusto.westeurope").database("events").table("CourierEvents")
| where OrderId == "C61F4D3A8B93975111EC8A629DDBCF0E"

but I get an error Please select a database to execute queries. until I select a table in the left menu and the scope appears on the top.

Is it possible to select the scope inside a request without selecting it in a left menu?

Body:
I assume that you are using one of the tools (Kusto Explorer or the Kusto Web explorer), if so the answer is yes. See the connection panel topic in the Kusto Explorer docs, and here is the applicable example:

#connect cluster('help').database('Samples')

StormEvents | count

Execute the first line, and it will set your context to the applicable cluster and database.


问:
The gap still keeps 100% in running Gurobi model
I am solving a mixed-integer linear programming model on Python platform using the solver Gurobi. However, The gap of the model still keeps 100 % during the long-running time.
I am trying to use the codes to limit the running time. The solution is found, but I don't know why the gap in the model doesn't reduce.
I have attached the file below.
Could you help me to fix this problem?
Thank you very much!

答:
The gap is defined as:

```<code>gap = |bestfound - bestbound|/|bestfound|
</code>```

(see the Gurobi documentation).

The best bound in your screenshot stays at 0, so the gap does not change and remains 100%.

Body:
The gap is defined as:

gap = |bestfound - bestbound|/|bestfound|

(see the Gurobi documentation).

The best bound in your screenshot stays at 0, so the gap does not change and remains 100%.


问:
FLutter: FittedBox Text widget inside a column
I've a Column widget which contains Text widgets as its children. 2nd Text widget in Column widget should dynamically adjust the fontSize depending on screen size so that it takes only 1 line. It tried wrapping the Text widget within a FittedBox.

```<code>Container(
  color: AppColors.hintBG,
  width: double.infinity,
  child: Padding(
    padding: const EdgeInsets.symmetric(
      vertical: AppDimens.VrPadding,
      horizontal: AppDimens.HrPadding / 2
    ),
    child: Column(
      crossAxisAlignment: CrossAxisAlignment.stretch,
      children: [
        Text(
          getRate(state.selectedSlot),
          style: context.textTheme.headline5,
        ),
        FittedBox(
          child: Text(
            getTime(state.selectedSlot),
            style: context.textTheme.subtitle1,
            textAlign: TextAlign.center,
          ),
        ),
      ],
    ),
  ),
)
</code>```

But it is not working within a column. I'm getting error:

```<code>======== Exception caught by rendering library =====================================================
The following assertion was thrown during performLayout():
'package:flutter/src/rendering/object.dart': Failed assertion: line 1785 pos 12: '!_debugDoingThisLayout': is not true.

Either the assertion indicates an error in the framework itself, or we should provide substantially more information in this error message to help you determine and fix the underlying cause.
In either case, please report this assertion by filing a bug on GitHub:
  https://github.com/flutter/flutter/issues/new?template=2_bug.md

The relevant error-causing widget was:
  Stack Stack:file:///Users/sarath/StudioProjects/astrog/lib/screens/booking/consultation_book_slot_step1.dart:69:14
When the exception was thrown, this was the stack:
#2      RenderObject.layout (package:flutter/src/rendering/object.dart:1785:12)
#3      RenderStack.layoutPositionedChild (package:flutter/src/rendering/stack.dart:497:11)
#4      RenderStack.performLayout (package:flutter/src/rendering/stack.dart:610:30)
#5      RenderObject.layout (package:flutter/src/rendering/object.dart:1858:7)
#6      RenderConstrainedBox.performLayout (package:flutter/src/rendering/proxy_box.dart:277:14)
#7      RenderObject.layout (package:flutter/src/rendering/object.dart:1858:7)
#8      MultiChildLayoutDelegate.layoutChild (package:flutter/src/rendering/custom_layout.dart:171:12)
#9      _ScaffoldLayout.performLayout (package:flutter/src/material/scaffold.dart:1097:7)
#10     MultiChildLayoutDelegate._callPerformLayout (package:flutter/src/rendering/custom_layout.dart:240:7)
#11     RenderCustomMultiChildLayoutBox.performLayout (package:flutter/src/rendering/custom_layout.dart:404:14)
#12     RenderObject.layout (package:flutter/src/rendering/object.dart:1858:7)
#13     RenderProxyBoxMixin.performLayout (package:flutter/src/rendering/proxy_box.dart:116:14)
#14     RenderObject.layout (package:flutter/src/rendering/object.dart:1858:7)
#15     RenderProxyBoxMixin.performLayout (package:flutter/src/rendering/proxy_box.dart:116:14)
#16     _RenderCustomClip.performLayout (package:flutter/src/rendering/proxy_box.dart:1388:11)
#17     RenderObject.layout (package:flutter/src/rendering/object.dart:1858:7)
#18     RenderProxyBoxMixin.performLayout (package:flutter/src/rendering/proxy_box.dart:116:14)
#19     RenderObject.layout (package:flutter/src/rendering/object.dart:1858:7)
#20     RenderProxyBoxMixin.performLayout (package:flutter/src/rendering/proxy_box.dart:116:14)
#21     RenderObject.layout (package:flutter/src/rendering/object.dart:1858:7)
#22     RenderProxyBoxMixin.performLayout (package:flutter/src/rendering/proxy_box.dart:116:14)
#23     RenderObject.layout (package:flutter/src/rendering/object.dart:1858:7)
#24     RenderProxyBoxMixin.performLayout (package:flutter/src/rendering/proxy_box.dart:116:14)
#25     RenderObject.layout (package:flutter/src/rendering/object.dart:1858:7)
#26     RenderProxyBoxMixin.performLayout (package:flutter/src/rendering/proxy_box.dart:116:14)
#27     RenderObject.layout (package:flutter/src/rendering/object.dart:1858:7)
#28     RenderProxyBoxMixin.performLayout (package:flutter/src/rendering/proxy_box.dart:116:14)
#29     RenderObject.layout (package:flutter/src/rendering/object.dart:1858:7)
#30     RenderProxyBoxMixin.performLayout (package:flutter/src/rendering/proxy_box.dart:116:14)
#31     RenderObject.layout (package:flutter/src/rendering/object.dart:1858:7)
#32     RenderProxyBoxMixin.performLayout (package:flutter/src/rendering/proxy_box.dart:116:14)
#33     RenderObject.layout (package:flutter/src/rendering/object.dart:1858:7)
#34     RenderProxyBoxMixin.performLayout (package:flutter/src/rendering/proxy_box.dart:116:14)
#35     RenderOffstage.performLayout (package:flutter/src/rendering/proxy_box.dart:3422:13)
#36     RenderObject.layout (package:flutter/src/rendering/object.dart:1858:7)
#37     RenderProxyBoxMixin.performLayout (package:flutter/src/rendering/proxy_box.dart:116:14)
#38     RenderObject.layout (package:flutter/src/rendering/object.dart:1858:7)
#39     _RenderTheatre.performLayout (package:flutter/src/widgets/overlay.dart:745:15)
#40     RenderObject.layout (package:flutter/src/rendering/object.dart:1858:7)
#41     RenderProxyBoxMixin.performLayout (package:flutter/src/rendering/proxy_box.dart:116:14)
#42     RenderObject.layout (package:flutter/src/rendering/object.dart:1858:7)
#43     RenderProxyBoxMixin.performLayout (package:flutter/src/rendering/proxy_box.dart:116:14)
#44     RenderObject.layout (package:flutter/src/rendering/object.dart:1858:7)
#45     RenderProxyBoxMixin.performLayout (package:flutter/src/rendering/proxy_box.dart:116:14)
#46     RenderObject.layout (package:flutter/src/rendering/object.dart:1858:7)
#47     ChildLayoutHelper.layoutChild (package:flutter/src/rendering/layout_helper.dart:56:11)
#48     RenderStack._computeSize (package:flutter/src/rendering/stack.dart:570:43)
#49     RenderStack.performLayout (package:flutter/src/rendering/stack.dart:597:12)
#50     RenderObject.layout (package:flutter/src/rendering/object.dart:1858:7)
#51     RenderProxyBoxMixin.performLayout (package:flutter/src/rendering/proxy_box.dart:116:14)
#52     RenderCustomPaint.performLayout (package:flutter/src/rendering/custom_paint.dart:545:11)
#53     RenderObject.layout (package:flutter/src/rendering/object.dart:1858:7)
#54     RenderProxyBoxMixin.performLayout (package:flutter/src/rendering/proxy_box.dart:116:14)
#55     RenderObject.layout (package:flutter/src/rendering/object.dart:1858:7)
#56     RenderProxyBoxMixin.performLayout (package:flutter/src/rendering/proxy_box.dart:116:14)
#57     RenderObject.layout (package:flutter/src/rendering/object.dart:1858:7)
#58     RenderProxyBoxMixin.performLayout (package:flutter/src/rendering/proxy_box.dart:116:14)
#59     RenderObject.layout (package:flutter/src/rendering/object.dart:1858:7)
#60     RenderProxyBoxMixin.performLayout (package:flutter/src/rendering/proxy_box.dart:116:14)
#61     RenderObject.layout (package:flutter/src/rendering/object.dart:1858:7)
#62     RenderView.performLayout (package:flutter/src/rendering/view.dart:165:14)
#63     RenderObject._layoutWithoutResize (package:flutter/src/rendering/object.dart:1713:7)
#64     PipelineOwner.flushLayout (package:flutter/src/rendering/object.dart:885:18)
#65     RendererBinding.drawFrame (package:flutter/src/rendering/binding.dart:453:19)
#66     WidgetsBinding.drawFrame (package:flutter/src/widgets/binding.dart:883:13)
#67     RendererBinding._handlePersistentFrameCallback (package:flutter/src/rendering/binding.dart:319:5)
#68     SchedulerBinding._invokeFrameCallback (package:flutter/src/scheduler/binding.dart:1143:15)
#69     SchedulerBinding.handleDrawFrame (package:flutter/src/scheduler/binding.dart:1080:9)
#70     SchedulerBinding.scheduleWarmUpFrame.<anonymous closure> (package:flutter/src/scheduler/binding.dart:863:7)
(elided 6 frames from class _AssertionError, class _RawReceivePortImpl, class _Timer, and dart:async-patch)
The following RenderObject was being processed when the exception was fired: RenderStack#dcea9 relayoutBoundary=up2 NEEDS-LAYOUT NEEDS-PAINT NEEDS-COMPOSITING-BITS-UPDATE
...  needs compositing
...  parentData: <none> (can use size)
...  constraints: BoxConstraints(0.0<=w<=320.0, h=584.0)
...  size: Size(320.0, 584.0)
...  alignment: AlignmentDirectional.topStart
...  textDirection: ltr
...  fit: loose
RenderObject: RenderStack#dcea9 relayoutBoundary=up2 NEEDS-LAYOUT NEEDS-PAINT NEEDS-COMPOSITING-BITS-UPDATE
  needs compositing
  parentData: <none> (can use size)
  constraints: BoxConstraints(0.0<=w<=320.0, h=584.0)
  size: Size(320.0, 584.0)
  alignment: AlignmentDirectional.topStart
  textDirection: ltr
  fit: loose
...  child 1: RenderFlex#b4631 relayoutBoundary=up3 NEEDS-PAINT NEEDS-COMPOSITING-BITS-UPDATE
...    needs compositing
...    parentData: not positioned; offset=Offset(0.0, 0.0) (can use size)
...    constraints: BoxConstraints(0.0<=w<=320.0, 0.0<=h<=584.0)
...    size: Size(320.0, 584.0)
...    direction: vertical
...    mainAxisAlignment: start
...    mainAxisSize: max
...    crossAxisAlignment: center
...    verticalDirection: down
...    child 1: RenderConstrainedBox#e9e18 relayoutBoundary=up4 NEEDS-PAINT NEEDS-COMPOSITING-BITS-UPDATE
...      parentData: offset=Offset(160.0, 0.0); flex=null; fit=null (can use size)
...      constraints: BoxConstraints(0.0<=w<=320.0, 0.0<=h<=Infinity)
...      size: Size(0.0, 16.0)
...      additionalConstraints: BoxConstraints(0.0<=w<=Infinity, h=16.0)
...    child 2: RenderPadding#470da relayoutBoundary=up4 NEEDS-PAINT NEEDS-COMPOSITING-BITS-UPDATE
...      parentData: offset=Offset(0.0, 16.0); flex=null; fit=null (can use size)
...      constraints: BoxConstraints(0.0<=w<=320.0, 0.0<=h<=Infinity)
...      size: Size(320.0, 69.0)
...      padding: EdgeInsets(32.0, 0.0, 20.0, 0.0)
...      textDirection: ltr
...      child: RenderFlex#39cb4 relayoutBoundary=up5 NEEDS-PAINT NEEDS-COMPOSITING-BITS-UPDATE
...        parentData: offset=Offset(32.0, 0.0) (can use size)
...        constraints: BoxConstraints(0.0<=w<=268.0, 0.0<=h<=Infinity)
...        size: Size(268.0, 69.0)
...        direction: horizontal
...        mainAxisAlignment: start
...        mainAxisSize: max
...        crossAxisAlignment: start
...        textDirection: ltr
...        verticalDirection: down
...        child 1: RenderSemanticsAnnotations#4bdda relayoutBoundary=up6 NEEDS-PAINT NEEDS-COMPOSITING-BITS-UPDATE
...          parentData: offset=Offset(0.0, 0.0); flex=null; fit=null (can use size)
...          constraints: BoxConstraints(unconstrained)
...          size: Size(24.0, 24.0)
...        child 2: RenderConstrainedBox#cdf9c relayoutBoundary=up6 NEEDS-PAINT NEEDS-COMPOSITING-BITS-UPDATE
...          parentData: offset=Offset(24.0, 0.0); flex=null; fit=null (can use size)
...          constraints: BoxConstraints(unconstrained)
...          size: Size(16.0, 0.0)
...          additionalConstraints: BoxConstraints(w=16.0, 0.0<=h<=Infinity)
...        child 3: RenderParagraph#31531 relayoutBoundary=up6 NEEDS-PAINT NEEDS-COMPOSITING-BITS-UPDATE
...          parentData: offset=Offset(40.0, 0.0); flex=1; fit=FlexFit.tight (can use size)
...          constraints: BoxConstraints(w=228.0, 0.0<=h<=Infinity)
...          size: Size(228.0, 69.0)
...          textAlign: start
...          textDirection: ltr
...          softWrap: wrapping at box width
...          overflow: clip
...          textScaleFactor: 1.3
...          locale: en
...          maxLines: unlimited
...    child 3: RenderConstrainedBox#3dd41 relayoutBoundary=up4 NEEDS-PAINT NEEDS-COMPOSITING-BITS-UPDATE
...      parentData: offset=Offset(160.0, 85.0); flex=null; fit=null (can use size)
...      constraints: BoxConstraints(0.0<=w<=320.0, 0.0<=h<=Infinity)
...      size: Size(0.0, 16.0)
...      additionalConstraints: BoxConstraints(0.0<=w<=Infinity, h=16.0)
...    child 4: RenderConstrainedBox#824e1 relayoutBoundary=up4 NEEDS-PAINT NEEDS-COMPOSITING-BITS-UPDATE
...      parentData: offset=Offset(0.0, 101.0); flex=null; fit=null (can use size)
...      constraints: BoxConstraints(0.0<=w<=320.0, 0.0<=h<=Infinity)
...      size: Size(320.0, 16.0)
...      additionalConstraints: BoxConstraints(0.0<=w<=Infinity, h=16.0)
...      child: RenderPositionedBox#60ff0 relayoutBoundary=up5 NEEDS-PAINT NEEDS-COMPOSITING-BITS-UPDATE
...        parentData: <none> (can use size)
...        constraints: BoxConstraints(0.0<=w<=320.0, h=16.0)
...        size: Size(320.0, 16.0)
...        alignment: Alignment.center
...        textDirection: ltr
...        widthFactor: expand
...        heightFactor: expand
...        child: RenderPadding#64ac5 relayoutBoundary=up6 NEEDS-PAINT NEEDS-COMPOSITING-BITS-UPDATE
...          parentData: offset=Offset(0.0, 0.0) (can use size)
...          constraints: BoxConstraints(0.0<=w<=320.0, 0.0<=h<=16.0)
...          size: Size(320.0, 16.0)
...          padding: EdgeInsets.zero
...          textDirection: ltr
...    child 5: RenderFlex#f3138 relayoutBoundary=up4 NEEDS-PAINT NEEDS-COMPOSITING-BITS-UPDATE
...      needs compositing
...      parentData: offset=Offset(0.0, 117.0); flex=null; fit=null (can use size)
...      constraints: BoxConstraints(0.0<=w<=320.0, 0.0<=h<=Infinity)
...      size: Size(320.0, 152.0)
...      direction: vertical
...      mainAxisAlignment: start
...      mainAxisSize: max
...      crossAxisAlignment: center
...      verticalDirection: down
...      child 1: RenderPadding#8a223 relayoutBoundary=up5 NEEDS-PAINT NEEDS-COMPOSITING-BITS-UPDATE
...        parentData: offset=Offset(0.0, 0.0); flex=null; fit=null (can use size)
...        constraints: BoxConstraints(0.0<=w<=320.0, 0.0<=h<=Infinity)
...        size: Size(320.0, 64.0)
...        padding: EdgeInsets.zero
...        textDirection: ltr
...        child: RenderDecoratedBox#300ee relayoutBoundary=up6 NEEDS-PAINT NEEDS-COMPOSITING-BITS-UPDATE
...          parentData: offset=Offset(0.0, 0.0) (can use size)
...          constraints: BoxConstraints(0.0<=w<=320.0, 0.0<=h<=Infinity)
...          size: Size(320.0, 64.0)
...          decoration: BoxDecoration
...          configuration: ImageConfiguration(bundle: PlatformAssetBundle#c08f0(), devicePixelRatio: 3.4, locale: en, textDirection: TextDirection.ltr, platform: android)
...      child 2: _RenderLayoutBuilder#023a3 relayoutBoundary=up5 NEEDS-PAINT NEEDS-COMPOSITING-BITS-UPDATE
...        needs compositing
...        parentData: offset=Offset(0.0, 64.0); flex=0; fit=FlexFit.loose (can use size)
...        constraints: BoxConstraints(0.0<=w<=320.0, 0.0<=h<=Infinity)
...        size: Size(320.0, 88.0)
...        child: RenderSemanticsGestureHandler#2bb42 relayoutBoundary=up6 NEEDS-PAINT NEEDS-COMPOSITING-BITS-UPDATE
...          needs compositing
...          parentData: offset=Offset(0.0, 0.0) (can use size)
...          constraints: BoxConstraints(0.0<=w<=320.0, 0.0<=h<=Infinity)
...          size: Size(320.0, 88.0)
...          behavior: deferToChild
...          gestures: vertical scroll
...    child 6: RenderConstrainedBox#332da relayoutBoundary=up4 NEEDS-PAINT NEEDS-COMPOSITING-BITS-UPDATE
...      parentData: offset=Offset(160.0, 269.0); flex=null; fit=null (can use size)
...      constraints: BoxConstraints(0.0<=w<=320.0, 0.0<=h<=Infinity)
...      size: Size(0.0, 12.0)
...      additionalConstraints: BoxConstraints(0.0<=w<=Infinity, h=12.0)
...    child 7: RenderConstrainedBox#3d77f relayoutBoundary=up4 NEEDS-PAINT NEEDS-COMPOSITING-BITS-UPDATE
...      parentData: offset=Offset(0.0, 281.0); flex=null; fit=null (can use size)
...      constraints: BoxConstraints(0.0<=w<=320.0, 0.0<=h<=Infinity)
...      size: Size(320.0, 16.0)
...      additionalConstraints: BoxConstraints(0.0<=w<=Infinity, h=16.0)
...      child: RenderPositionedBox#d3445 relayoutBoundary=up5 NEEDS-PAINT NEEDS-COMPOSITING-BITS-UPDATE
...        parentData: <none> (can use size)
...        constraints: BoxConstraints(0.0<=w<=320.0, h=16.0)
...        size: Size(320.0, 16.0)
...        alignment: Alignment.center
...        textDirection: ltr
...        widthFactor: expand
...        heightFactor: expand
...        child: RenderPadding#5dcf1 relayoutBoundary=up6 NEEDS-PAINT NEEDS-COMPOSITING-BITS-UPDATE
...          parentData: offset=Offset(0.0, 8.0) (can use size)
...          constraints: BoxConstraints(0.0<=w<=320.0, 0.0<=h<=16.0)
...          size: Size(320.0, 0.0)
...          padding: EdgeInsets.zero
...          textDirection: ltr
...    child 8: RenderRepaintBoundary#6f3d6 relayoutBoundary=up4 NEEDS-PAINT NEEDS-COMPOSITING-BITS-UPDATE
...      needs compositing
...      parentData: offset=Offset(0.0, 297.0); flex=1; fit=FlexFit.tight (can use size)
...      constraints: BoxConstraints(0.0<=w<=320.0, h=287.0)
...      layer: OffsetLayer#92b04
...        engine layer: OffsetEngineLayer#b0ee8
...        handles: 2
...        offset: Offset(0.0, 393.3)
...      size: Size(320.0, 287.0)
...      metrics: 0.0% useful (1 bad vs 0 good)
...      diagnosis: insufficient data to draw conclusion (less than five repaints)
...      child: RenderCustomPaint#eee2d relayoutBoundary=up5 NEEDS-PAINT NEEDS-COMPOSITING-BITS-UPDATE
...        needs compositing
...        parentData: <none> (can use size)
...        constraints: BoxConstraints(0.0<=w<=320.0, h=287.0)
...        size: Size(320.0, 287.0)
...        child: RenderRepaintBoundary#f3933 relayoutBoundary=up6 NEEDS-PAINT NEEDS-COMPOSITING-BITS-UPDATE
...          needs compositing
...          parentData: <none> (can use size)
...          constraints: BoxConstraints(0.0<=w<=320.0, h=287.0)
...          layer: OffsetLayer#6337d
...            engine layer: OffsetEngineLayer#7a705
...            handles: 2
...            offset: Offset(0.0, 0.0)
...          size: Size(320.0, 287.0)
...          metrics: 0.0% useful (1 bad vs 0 good)
...          diagnosis: insufficient data to draw conclusion (less than five repaints)
...  child 2: RenderPhysicalModel#2fcca relayoutBoundary=up3 NEEDS-LAYOUT NEEDS-PAINT NEEDS-COMPOSITING-BITS-UPDATE
...    needs compositing
...    parentData: right=0.0; bottom=0.0; left=0.0; offset=Offset(0.0, 0.0) (can use size)
...    constraints: BoxConstraints(w=320.0, 0.0<=h<=Infinity)
...    size: MISSING
...    elevation: 11.5
...    color: Color(0xffffffff)
...    shadowColor: Color(0xffffffff)
...    shape: BoxShape.rectangle
...    borderRadius: BorderRadius.zero
...    child: _RenderInkFeatures#2570b relayoutBoundary=up4 NEEDS-LAYOUT NEEDS-PAINT NEEDS-COMPOSITING-BITS-UPDATE
...      needs compositing
...      parentData: <none> (can use size)
...      constraints: BoxConstraints(w=320.0, 0.0<=h<=Infinity)
...      size: MISSING
...      child: RenderPadding#77952 relayoutBoundary=up5 NEEDS-LAYOUT NEEDS-PAINT NEEDS-COMPOSITING-BITS-UPDATE
...        needs compositing
...        parentData: <none> (can use size)
...        constraints: BoxConstraints(w=320.0, 0.0<=h<=Infinity)
...        size: MISSING
...        padding: EdgeInsets.all(20.0)
...        textDirection: ltr
...        child: RenderFlex#0c5d9 relayoutBoundary=up6 NEEDS-LAYOUT NEEDS-PAINT NEEDS-COMPOSITING-BITS-UPDATE
...          needs compositing
...          parentData: offset=Offset(20.0, 20.0) (can use size)
...          constraints: BoxConstraints(w=280.0, 0.0<=h<=Infinity)
...          size: MISSING
...          direction: horizontal
...          mainAxisAlignment: center
...          mainAxisSize: max
...          crossAxisAlignment: center
...          textDirection: ltr
...          verticalDirection: down
====================================================================================================
======== Exception caught by rendering library =====================================================
The following assertion was thrown during performLayout():
'package:flutter/src/rendering/object.dart': Failed assertion: line 1785 pos 12: '!_debugDoingThisLayout': is not true.

Either the assertion indicates an error in the framework itself, or we should provide substantially more information in this error message to help you determine and fix the underlying cause.
In either case, please report this assertion by filing a bug on GitHub:
  https://github.com/flutter/flutter/issues/new?template=2_bug.md

The relevant error-causing widget was:
  Stack Stack:file:///Users/sarath/StudioProjects/astrog/lib/screens/booking/consultation_book_slot_step1.dart:69:14
When the exception was thrown, this was the stack:
#2      RenderObject.layout (package:flutter/src/rendering/object.dart:1785:12)
#3      RenderStack.layoutPositionedChild (package:flutter/src/rendering/stack.dart:497:11)
</code>```

Edit:

```<code>class _BottomBar extends StatelessWidget {
  final AstrologerDetails details;

  const _BottomBar(this.details, {Key? key}) : super(key: key);

  @override
  Widget build(BuildContext context) {
    return Material(
      elevation: 11.5,
      color: Theme.of(context).scaffoldBackgroundColor,
      child: Padding(
        padding: EdgeInsets.all(AppDimens.MainPaddingLong),
        child: Row(
          mainAxisAlignment: MainAxisAlignment.center,
          children: [
            Expanded(child: _Rate()),
            Expanded(child: _BookButton(details)),
          ],
        ),
      ),
    );
  }
}

class _Rate extends StatelessWidget {
  const _Rate({Key? key}) : super(key: key);

  @override
  Widget build(BuildContext context) {
    return BlocBuilder<ConsultantSlotsBloc, ConsultantSlotsState>(
      builder: (_, state) {
        return Container(
          color: AppColors.hintBG,
          width: double.infinity,
          child: Padding(
            padding: const EdgeInsets.symmetric(
                vertical: 4, horizontal: AppDimens.HrPadding / 2),
            child: Column(
              crossAxisAlignment: CrossAxisAlignment.stretch,
              children: [
                Text(
                  getRate(state.selectedSlot),
                  style: context.textTheme.headline5,
                  textAlign: TextAlign.center,
                ),
                FittedBox(
                  child: Text(
                    getTime(state.selectedSlot),
                    style: context.textTheme.subtitle1,
                    textAlign: TextAlign.center,
                  ),
                ),
              ],
            ),
          ),
        );
      },
    );
  }

  String getRate(Slot? slot) {
    if (slot == null) {
      return '';
    }
    return '${UniCodes.RupeeSymbol} ${slot.rate}';
  }

  String getTime(Slot? slot) {
    if (slot == null) {
      return '';
    }
    final fmt = DateFormats.timeOnly;
    return '${fmt.format(slot.startTime.toLocal())} - ${fmt.format(slot.endTime.toLocal())}';
  }
}

class _BookButton extends StatelessWidget {
  final AstrologerDetails details;

  const _BookButton(this.details, {Key? key}) : super(key: key);

  @override
  Widget build(BuildContext context) {
    return BlocBuilder<ConsultantSlotsBloc, ConsultantSlotsState>(
      builder: (_, state) {
        return OutlinedButton(
          style: AppStyles.outlinedButtonSharp,
          child: FittedBox(
            child: Text(
              context.T.bookSlot.toUpperCase(),
              textAlign: TextAlign.center,
            ),
          ),
          onPressed: () {
            if (state.selectedSlot != null) {
              Navigator.pushNamed(context, ConsultationBookSlotStep2.routeName,
                  arguments: [details, state.selectedSlot!]).then((value) {
                final bloc = context.read<ConsultantSlotsBloc>();
                context
                    .read<ConsultantSlotsBloc>()
                    .add(SilentFetch(bloc.state.selectedDate, inMemory: false));
              });
            } else {
              App.showOkToDismissSnackBar(context.T.noSlotSelected);
            }
          },
        );
      },
    );
  }
}
</code>```

答:
try this:</p>
```<code>Text(
  "text",
  style: TextStyle(
    // MediaQuery.of(context).size.width is the width from the screen
    fontSize: MediaQuery.of(context).size.width * 0.001,
    ...
  ),
),
</code>```

Body:
I've a Column widget which contains Text widgets as its children. 2nd Text widget in Column widget should dynamically adjust the fontSize depending on screen size so that it takes only 1 line. It tried wrapping the Text widget within a FittedBox.

Container(
  color: AppColors.hintBG,
  width: double.infinity,
  child: Padding(
    padding: const EdgeInsets.symmetric(
      vertical: AppDimens.VrPadding,
      horizontal: AppDimens.HrPadding / 2
    ),
    child: Column(
      crossAxisAlignment: CrossAxisAlignment.stretch,
      children: [
        Text(
          getRate(state.selectedSlot),
          style: context.textTheme.headline5,
        ),
        FittedBox(
          child: Text(
            getTime(state.selectedSlot),
            style: context.textTheme.subtitle1,
            textAlign: TextAlign.center,
          ),
        ),
      ],
    ),
  ),
)

But it is not working within a column. I'm getting error:

======== Exception caught by rendering library =====================================================
The following assertion was thrown during performLayout():
'package:flutter/src/rendering/object.dart': Failed assertion: line 1785 pos 12: '!_debugDoingThisLayout': is not true.

Either the assertion indicates an error in the framework itself, or we should provide substantially more information in this error message to help you determine and fix the underlying cause.
In either case, please report this assertion by filing a bug on GitHub:
  https://github.com/flutter/flutter/issues/new?template=2_bug.md

The relevant error-causing widget was:
  Stack Stack:file:///Users/sarath/StudioProjects/astrog/lib/screens/booking/consultation_book_slot_step1.dart:69:14
When the exception was thrown, this was the stack:
#2      RenderObject.layout (package:flutter/src/rendering/object.dart:1785:12)
#3      RenderStack.layoutPositionedChild (package:flutter/src/rendering/stack.dart:497:11)
#4      RenderStack.performLayout (package:flutter/src/rendering/stack.dart:610:30)
#5      RenderObject.layout (package:flutter/src/rendering/object.dart:1858:7)
#6      RenderConstrainedBox.performLayout (package:flutter/src/rendering/proxy_box.dart:277:14)
#7      RenderObject.layout (package:flutter/src/rendering/object.dart:1858:7)
#8      MultiChildLayoutDelegate.layoutChild (package:flutter/src/rendering/custom_layout.dart:171:12)
#9      _ScaffoldLayout.performLayout (package:flutter/src/material/scaffold.dart:1097:7)
#10     MultiChildLayoutDelegate._callPerformLayout (package:flutter/src/rendering/custom_layout.dart:240:7)
#11     RenderCustomMultiChildLayoutBox.performLayout (package:flutter/src/rendering/custom_layout.dart:404:14)
#12     RenderObject.layout (package:flutter/src/rendering/object.dart:1858:7)
#13     RenderProxyBoxMixin.performLayout (package:flutter/src/rendering/proxy_box.dart:116:14)
#14     RenderObject.layout (package:flutter/src/rendering/object.dart:1858:7)
#15     RenderProxyBoxMixin.performLayout (package:flutter/src/rendering/proxy_box.dart:116:14)
#16     _RenderCustomClip.performLayout (package:flutter/src/rendering/proxy_box.dart:1388:11)
#17     RenderObject.layout (package:flutter/src/rendering/object.dart:1858:7)
#18     RenderProxyBoxMixin.performLayout (package:flutter/src/rendering/proxy_box.dart:116:14)
#19     RenderObject.layout (package:flutter/src/rendering/object.dart:1858:7)
#20     RenderProxyBoxMixin.performLayout (package:flutter/src/rendering/proxy_box.dart:116:14)
#21     RenderObject.layout (package:flutter/src/rendering/object.dart:1858:7)
#22     RenderProxyBoxMixin.performLayout (package:flutter/src/rendering/proxy_box.dart:116:14)
#23     RenderObject.layout (package:flutter/src/rendering/object.dart:1858:7)
#24     RenderProxyBoxMixin.performLayout (package:flutter/src/rendering/proxy_box.dart:116:14)
#25     RenderObject.layout (package:flutter/src/rendering/object.dart:1858:7)
#26     RenderProxyBoxMixin.performLayout (package:flutter/src/rendering/proxy_box.dart:116:14)
#27     RenderObject.layout (package:flutter/src/rendering/object.dart:1858:7)
#28     RenderProxyBoxMixin.performLayout (package:flutter/src/rendering/proxy_box.dart:116:14)
#29     RenderObject.layout (package:flutter/src/rendering/object.dart:1858:7)
#30     RenderProxyBoxMixin.performLayout (package:flutter/src/rendering/proxy_box.dart:116:14)
#31     RenderObject.layout (package:flutter/src/rendering/object.dart:1858:7)
#32     RenderProxyBoxMixin.performLayout (package:flutter/src/rendering/proxy_box.dart:116:14)
#33     RenderObject.layout (package:flutter/src/rendering/object.dart:1858:7)
#34     RenderProxyBoxMixin.performLayout (package:flutter/src/rendering/proxy_box.dart:116:14)
#35     RenderOffstage.performLayout (package:flutter/src/rendering/proxy_box.dart:3422:13)
#36     RenderObject.layout (package:flutter/src/rendering/object.dart:1858:7)
#37     RenderProxyBoxMixin.performLayout (package:flutter/src/rendering/proxy_box.dart:116:14)
#38     RenderObject.layout (package:flutter/src/rendering/object.dart:1858:7)
#39     _RenderTheatre.performLayout (package:flutter/src/widgets/overlay.dart:745:15)
#40     RenderObject.layout (package:flutter/src/rendering/object.dart:1858:7)
#41     RenderProxyBoxMixin.performLayout (package:flutter/src/rendering/proxy_box.dart:116:14)
#42     RenderObject.layout (package:flutter/src/rendering/object.dart:1858:7)
#43     RenderProxyBoxMixin.performLayout (package:flutter/src/rendering/proxy_box.dart:116:14)
#44     RenderObject.layout (package:flutter/src/rendering/object.dart:1858:7)
#45     RenderProxyBoxMixin.performLayout (package:flutter/src/rendering/proxy_box.dart:116:14)
#46     RenderObject.layout (package:flutter/src/rendering/object.dart:1858:7)
#47     ChildLayoutHelper.layoutChild (package:flutter/src/rendering/layout_helper.dart:56:11)
#48     RenderStack._computeSize (package:flutter/src/rendering/stack.dart:570:43)
#49     RenderStack.performLayout (package:flutter/src/rendering/stack.dart:597:12)
#50     RenderObject.layout (package:flutter/src/rendering/object.dart:1858:7)
#51     RenderProxyBoxMixin.performLayout (package:flutter/src/rendering/proxy_box.dart:116:14)
#52     RenderCustomPaint.performLayout (package:flutter/src/rendering/custom_paint.dart:545:11)
#53     RenderObject.layout (package:flutter/src/rendering/object.dart:1858:7)
#54     RenderProxyBoxMixin.performLayout (package:flutter/src/rendering/proxy_box.dart:116:14)
#55     RenderObject.layout (package:flutter/src/rendering/object.dart:1858:7)
#56     RenderProxyBoxMixin.performLayout (package:flutter/src/rendering/proxy_box.dart:116:14)
#57     RenderObject.layout (package:flutter/src/rendering/object.dart:1858:7)
#58     RenderProxyBoxMixin.performLayout (package:flutter/src/rendering/proxy_box.dart:116:14)
#59     RenderObject.layout (package:flutter/src/rendering/object.dart:1858:7)
#60     RenderProxyBoxMixin.performLayout (package:flutter/src/rendering/proxy_box.dart:116:14)
#61     RenderObject.layout (package:flutter/src/rendering/object.dart:1858:7)
#62     RenderView.performLayout (package:flutter/src/rendering/view.dart:165:14)
#63     RenderObject._layoutWithoutResize (package:flutter/src/rendering/object.dart:1713:7)
#64     PipelineOwner.flushLayout (package:flutter/src/rendering/object.dart:885:18)
#65     RendererBinding.drawFrame (package:flutter/src/rendering/binding.dart:453:19)
#66     WidgetsBinding.drawFrame (package:flutter/src/widgets/binding.dart:883:13)
#67     RendererBinding._handlePersistentFrameCallback (package:flutter/src/rendering/binding.dart:319:5)
#68     SchedulerBinding._invokeFrameCallback (package:flutter/src/scheduler/binding.dart:1143:15)
#69     SchedulerBinding.handleDrawFrame (package:flutter/src/scheduler/binding.dart:1080:9)
#70     SchedulerBinding.scheduleWarmUpFrame.<anonymous closure> (package:flutter/src/scheduler/binding.dart:863:7)
(elided 6 frames from class _AssertionError, class _RawReceivePortImpl, class _Timer, and dart:async-patch)
The following RenderObject was being processed when the exception was fired: RenderStack#dcea9 relayoutBoundary=up2 NEEDS-LAYOUT NEEDS-PAINT NEEDS-COMPOSITING-BITS-UPDATE
...  needs compositing
...  parentData: <none> (can use size)
...  constraints: BoxConstraints(0.0<=w<=320.0, h=584.0)
...  size: Size(320.0, 584.0)
...  alignment: AlignmentDirectional.topStart
...  textDirection: ltr
...  fit: loose
RenderObject: RenderStack#dcea9 relayoutBoundary=up2 NEEDS-LAYOUT NEEDS-PAINT NEEDS-COMPOSITING-BITS-UPDATE
  needs compositing
  parentData: <none> (can use size)
  constraints: BoxConstraints(0.0<=w<=320.0, h=584.0)
  size: Size(320.0, 584.0)
  alignment: AlignmentDirectional.topStart
  textDirection: ltr
  fit: loose
...  child 1: RenderFlex#b4631 relayoutBoundary=up3 NEEDS-PAINT NEEDS-COMPOSITING-BITS-UPDATE
...    needs compositing
...    parentData: not positioned; offset=Offset(0.0, 0.0) (can use size)
...    constraints: BoxConstraints(0.0<=w<=320.0, 0.0<=h<=584.0)
...    size: Size(320.0, 584.0)
...    direction: vertical
...    mainAxisAlignment: start
...    mainAxisSize: max
...    crossAxisAlignment: center
...    verticalDirection: down
...    child 1: RenderConstrainedBox#e9e18 relayoutBoundary=up4 NEEDS-PAINT NEEDS-COMPOSITING-BITS-UPDATE
...      parentData: offset=Offset(160.0, 0.0); flex=null; fit=null (can use size)
...      constraints: BoxConstraints(0.0<=w<=320.0, 0.0<=h<=Infinity)
...      size: Size(0.0, 16.0)
...      additionalConstraints: BoxConstraints(0.0<=w<=Infinity, h=16.0)
...    child 2: RenderPadding#470da relayoutBoundary=up4 NEEDS-PAINT NEEDS-COMPOSITING-BITS-UPDATE
...      parentData: offset=Offset(0.0, 16.0); flex=null; fit=null (can use size)
...      constraints: BoxConstraints(0.0<=w<=320.0, 0.0<=h<=Infinity)
...      size: Size(320.0, 69.0)
...      padding: EdgeInsets(32.0, 0.0, 20.0, 0.0)
...      textDirection: ltr
...      child: RenderFlex#39cb4 relayoutBoundary=up5 NEEDS-PAINT NEEDS-COMPOSITING-BITS-UPDATE
...        parentData: offset=Offset(32.0, 0.0) (can use size)
...        constraints: BoxConstraints(0.0<=w<=268.0, 0.0<=h<=Infinity)
...        size: Size(268.0, 69.0)
...        direction: horizontal
...        mainAxisAlignment: start
...        mainAxisSize: max
...        crossAxisAlignment: start
...        textDirection: ltr
...        verticalDirection: down
...        child 1: RenderSemanticsAnnotations#4bdda relayoutBoundary=up6 NEEDS-PAINT NEEDS-COMPOSITING-BITS-UPDATE
...          parentData: offset=Offset(0.0, 0.0); flex=null; fit=null (can use size)
...          constraints: BoxConstraints(unconstrained)
...          size: Size(24.0, 24.0)
...        child 2: RenderConstrainedBox#cdf9c relayoutBoundary=up6 NEEDS-PAINT NEEDS-COMPOSITING-BITS-UPDATE
...          parentData: offset=Offset(24.0, 0.0); flex=null; fit=null (can use size)
...          constraints: BoxConstraints(unconstrained)
...          size: Size(16.0, 0.0)
...          additionalConstraints: BoxConstraints(w=16.0, 0.0<=h<=Infinity)
...        child 3: RenderParagraph#31531 relayoutBoundary=up6 NEEDS-PAINT NEEDS-COMPOSITING-BITS-UPDATE
...          parentData: offset=Offset(40.0, 0.0); flex=1; fit=FlexFit.tight (can use size)
...          constraints: BoxConstraints(w=228.0, 0.0<=h<=Infinity)
...          size: Size(228.0, 69.0)
...          textAlign: start
...          textDirection: ltr
...          softWrap: wrapping at box width
...          overflow: clip
...          textScaleFactor: 1.3
...          locale: en
...          maxLines: unlimited
...    child 3: RenderConstrainedBox#3dd41 relayoutBoundary=up4 NEEDS-PAINT NEEDS-COMPOSITING-BITS-UPDATE
...      parentData: offset=Offset(160.0, 85.0); flex=null; fit=null (can use size)
...      constraints: BoxConstraints(0.0<=w<=320.0, 0.0<=h<=Infinity)
...      size: Size(0.0, 16.0)
...      additionalConstraints: BoxConstraints(0.0<=w<=Infinity, h=16.0)
...    child 4: RenderConstrainedBox#824e1 relayoutBoundary=up4 NEEDS-PAINT NEEDS-COMPOSITING-BITS-UPDATE
...      parentData: offset=Offset(0.0, 101.0); flex=null; fit=null (can use size)
...      constraints: BoxConstraints(0.0<=w<=320.0, 0.0<=h<=Infinity)
...      size: Size(320.0, 16.0)
...      additionalConstraints: BoxConstraints(0.0<=w<=Infinity, h=16.0)
...      child: RenderPositionedBox#60ff0 relayoutBoundary=up5 NEEDS-PAINT NEEDS-COMPOSITING-BITS-UPDATE
...        parentData: <none> (can use size)
...        constraints: BoxConstraints(0.0<=w<=320.0, h=16.0)
...        size: Size(320.0, 16.0)
...        alignment: Alignment.center
...        textDirection: ltr
...        widthFactor: expand
...        heightFactor: expand
...        child: RenderPadding#64ac5 relayoutBoundary=up6 NEEDS-PAINT NEEDS-COMPOSITING-BITS-UPDATE
...          parentData: offset=Offset(0.0, 0.0) (can use size)
...          constraints: BoxConstraints(0.0<=w<=320.0, 0.0<=h<=16.0)
...          size: Size(320.0, 16.0)
...          padding: EdgeInsets.zero
...          textDirection: ltr
...    child 5: RenderFlex#f3138 relayoutBoundary=up4 NEEDS-PAINT NEEDS-COMPOSITING-BITS-UPDATE
...      needs compositing
...      parentData: offset=Offset(0.0, 117.0); flex=null; fit=null (can use size)
...      constraints: BoxConstraints(0.0<=w<=320.0, 0.0<=h<=Infinity)
...      size: Size(320.0, 152.0)
...      direction: vertical
...      mainAxisAlignment: start
...      mainAxisSize: max
...      crossAxisAlignment: center
...      verticalDirection: down
...      child 1: RenderPadding#8a223 relayoutBoundary=up5 NEEDS-PAINT NEEDS-COMPOSITING-BITS-UPDATE
...        parentData: offset=Offset(0.0, 0.0); flex=null; fit=null (can use size)
...        constraints: BoxConstraints(0.0<=w<=320.0, 0.0<=h<=Infinity)
...        size: Size(320.0, 64.0)
...        padding: EdgeInsets.zero
...        textDirection: ltr
...        child: RenderDecoratedBox#300ee relayoutBoundary=up6 NEEDS-PAINT NEEDS-COMPOSITING-BITS-UPDATE
...          parentData: offset=Offset(0.0, 0.0) (can use size)
...          constraints: BoxConstraints(0.0<=w<=320.0, 0.0<=h<=Infinity)
...          size: Size(320.0, 64.0)
...          decoration: BoxDecoration
...          configuration: ImageConfiguration(bundle: PlatformAssetBundle#c08f0(), devicePixelRatio: 3.4, locale: en, textDirection: TextDirection.ltr, platform: android)
...      child 2: _RenderLayoutBuilder#023a3 relayoutBoundary=up5 NEEDS-PAINT NEEDS-COMPOSITING-BITS-UPDATE
...        needs compositing
...        parentData: offset=Offset(0.0, 64.0); flex=0; fit=FlexFit.loose (can use size)
...        constraints: BoxConstraints(0.0<=w<=320.0, 0.0<=h<=Infinity)
...        size: Size(320.0, 88.0)
...        child: RenderSemanticsGestureHandler#2bb42 relayoutBoundary=up6 NEEDS-PAINT NEEDS-COMPOSITING-BITS-UPDATE
...          needs compositing
...          parentData: offset=Offset(0.0, 0.0) (can use size)
...          constraints: BoxConstraints(0.0<=w<=320.0, 0.0<=h<=Infinity)
...          size: Size(320.0, 88.0)
...          behavior: deferToChild
...          gestures: vertical scroll
...    child 6: RenderConstrainedBox#332da relayoutBoundary=up4 NEEDS-PAINT NEEDS-COMPOSITING-BITS-UPDATE
...      parentData: offset=Offset(160.0, 269.0); flex=null; fit=null (can use size)
...      constraints: BoxConstraints(0.0<=w<=320.0, 0.0<=h<=Infinity)
...      size: Size(0.0, 12.0)
...      additionalConstraints: BoxConstraints(0.0<=w<=Infinity, h=12.0)
...    child 7: RenderConstrainedBox#3d77f relayoutBoundary=up4 NEEDS-PAINT NEEDS-COMPOSITING-BITS-UPDATE
...      parentData: offset=Offset(0.0, 281.0); flex=null; fit=null (can use size)
...      constraints: BoxConstraints(0.0<=w<=320.0, 0.0<=h<=Infinity)
...      size: Size(320.0, 16.0)
...      additionalConstraints: BoxConstraints(0.0<=w<=Infinity, h=16.0)
...      child: RenderPositionedBox#d3445 relayoutBoundary=up5 NEEDS-PAINT NEEDS-COMPOSITING-BITS-UPDATE
...        parentData: <none> (can use size)
...        constraints: BoxConstraints(0.0<=w<=320.0, h=16.0)
...        size: Size(320.0, 16.0)
...        alignment: Alignment.center
...        textDirection: ltr
...        widthFactor: expand
...        heightFactor: expand
...        child: RenderPadding#5dcf1 relayoutBoundary=up6 NEEDS-PAINT NEEDS-COMPOSITING-BITS-UPDATE
...          parentData: offset=Offset(0.0, 8.0) (can use size)
...          constraints: BoxConstraints(0.0<=w<=320.0, 0.0<=h<=16.0)
...          size: Size(320.0, 0.0)
...          padding: EdgeInsets.zero
...          textDirection: ltr
...    child 8: RenderRepaintBoundary#6f3d6 relayoutBoundary=up4 NEEDS-PAINT NEEDS-COMPOSITING-BITS-UPDATE
...      needs compositing
...      parentData: offset=Offset(0.0, 297.0); flex=1; fit=FlexFit.tight (can use size)
...      constraints: BoxConstraints(0.0<=w<=320.0, h=287.0)
...      layer: OffsetLayer#92b04
...        engine layer: OffsetEngineLayer#b0ee8
...        handles: 2
...        offset: Offset(0.0, 393.3)
...      size: Size(320.0, 287.0)
...      metrics: 0.0% useful (1 bad vs 0 good)
...      diagnosis: insufficient data to draw conclusion (less than five repaints)
...      child: RenderCustomPaint#eee2d relayoutBoundary=up5 NEEDS-PAINT NEEDS-COMPOSITING-BITS-UPDATE
...        needs compositing
...        parentData: <none> (can use size)
...        constraints: BoxConstraints(0.0<=w<=320.0, h=287.0)
...        size: Size(320.0, 287.0)
...        child: RenderRepaintBoundary#f3933 relayoutBoundary=up6 NEEDS-PAINT NEEDS-COMPOSITING-BITS-UPDATE
...          needs compositing
...          parentData: <none> (can use size)
...          constraints: BoxConstraints(0.0<=w<=320.0, h=287.0)
...          layer: OffsetLayer#6337d
...            engine layer: OffsetEngineLayer#7a705
...            handles: 2
...            offset: Offset(0.0, 0.0)
...          size: Size(320.0, 287.0)
...          metrics: 0.0% useful (1 bad vs 0 good)
...          diagnosis: insufficient data to draw conclusion (less than five repaints)
...  child 2: RenderPhysicalModel#2fcca relayoutBoundary=up3 NEEDS-LAYOUT NEEDS-PAINT NEEDS-COMPOSITING-BITS-UPDATE
...    needs compositing
...    parentData: right=0.0; bottom=0.0; left=0.0; offset=Offset(0.0, 0.0) (can use size)
...    constraints: BoxConstraints(w=320.0, 0.0<=h<=Infinity)
...    size: MISSING
...    elevation: 11.5
...    color: Color(0xffffffff)
...    shadowColor: Color(0xffffffff)
...    shape: BoxShape.rectangle
...    borderRadius: BorderRadius.zero
...    child: _RenderInkFeatures#2570b relayoutBoundary=up4 NEEDS-LAYOUT NEEDS-PAINT NEEDS-COMPOSITING-BITS-UPDATE
...      needs compositing
...      parentData: <none> (can use size)
...      constraints: BoxConstraints(w=320.0, 0.0<=h<=Infinity)
...      size: MISSING
...      child: RenderPadding#77952 relayoutBoundary=up5 NEEDS-LAYOUT NEEDS-PAINT NEEDS-COMPOSITING-BITS-UPDATE
...        needs compositing
...        parentData: <none> (can use size)
...        constraints: BoxConstraints(w=320.0, 0.0<=h<=Infinity)
...        size: MISSING
...        padding: EdgeInsets.all(20.0)
...        textDirection: ltr
...        child: RenderFlex#0c5d9 relayoutBoundary=up6 NEEDS-LAYOUT NEEDS-PAINT NEEDS-COMPOSITING-BITS-UPDATE
...          needs compositing
...          parentData: offset=Offset(20.0, 20.0) (can use size)
...          constraints: BoxConstraints(w=280.0, 0.0<=h<=Infinity)
...          size: MISSING
...          direction: horizontal
...          mainAxisAlignment: center
...          mainAxisSize: max
...          crossAxisAlignment: center
...          textDirection: ltr
...          verticalDirection: down
====================================================================================================
======== Exception caught by rendering library =====================================================
The following assertion was thrown during performLayout():
'package:flutter/src/rendering/object.dart': Failed assertion: line 1785 pos 12: '!_debugDoingThisLayout': is not true.

Either the assertion indicates an error in the framework itself, or we should provide substantially more information in this error message to help you determine and fix the underlying cause.
In either case, please report this assertion by filing a bug on GitHub:
  https://github.com/flutter/flutter/issues/new?template=2_bug.md

The relevant error-causing widget was:
  Stack Stack:file:///Users/sarath/StudioProjects/astrog/lib/screens/booking/consultation_book_slot_step1.dart:69:14
When the exception was thrown, this was the stack:
#2      RenderObject.layout (package:flutter/src/rendering/object.dart:1785:12)
#3      RenderStack.layoutPositionedChild (package:flutter/src/rendering/stack.dart:497:11)

Edit:

class _BottomBar extends StatelessWidget {
  final AstrologerDetails details;

  const _BottomBar(this.details, {Key? key}) : super(key: key);

  @override
  Widget build(BuildContext context) {
    return Material(
      elevation: 11.5,
      color: Theme.of(context).scaffoldBackgroundColor,
      child: Padding(
        padding: EdgeInsets.all(AppDimens.MainPaddingLong),
        child: Row(
          mainAxisAlignment: MainAxisAlignment.center,
          children: [
            Expanded(child: _Rate()),
            Expanded(child: _BookButton(details)),
          ],
        ),
      ),
    );
  }
}

class _Rate extends StatelessWidget {
  const _Rate({Key? key}) : super(key: key);

  @override
  Widget build(BuildContext context) {
    return BlocBuilder<ConsultantSlotsBloc, ConsultantSlotsState>(
      builder: (_, state) {
        return Container(
          color: AppColors.hintBG,
          width: double.infinity,
          child: Padding(
            padding: const EdgeInsets.symmetric(
                vertical: 4, horizontal: AppDimens.HrPadding / 2),
            child: Column(
              crossAxisAlignment: CrossAxisAlignment.stretch,
              children: [
                Text(
                  getRate(state.selectedSlot),
                  style: context.textTheme.headline5,
                  textAlign: TextAlign.center,
                ),
                FittedBox(
                  child: Text(
                    getTime(state.selectedSlot),
                    style: context.textTheme.subtitle1,
                    textAlign: TextAlign.center,
                  ),
                ),
              ],
            ),
          ),
        );
      },
    );
  }

  String getRate(Slot? slot) {
    if (slot == null) {
      return '';
    }
    return '${UniCodes.RupeeSymbol} ${slot.rate}';
  }

  String getTime(Slot? slot) {
    if (slot == null) {
      return '';
    }
    final fmt = DateFormats.timeOnly;
    return '${fmt.format(slot.startTime.toLocal())} - ${fmt.format(slot.endTime.toLocal())}';
  }
}

class _BookButton extends StatelessWidget {
  final AstrologerDetails details;

  const _BookButton(this.details, {Key? key}) : super(key: key);

  @override
  Widget build(BuildContext context) {
    return BlocBuilder<ConsultantSlotsBloc, ConsultantSlotsState>(
      builder: (_, state) {
        return OutlinedButton(
          style: AppStyles.outlinedButtonSharp,
          child: FittedBox(
            child: Text(
              context.T.bookSlot.toUpperCase(),
              textAlign: TextAlign.center,
            ),
          ),
          onPressed: () {
            if (state.selectedSlot != null) {
              Navigator.pushNamed(context, ConsultationBookSlotStep2.routeName,
                  arguments: [details, state.selectedSlot!]).then((value) {
                final bloc = context.read<ConsultantSlotsBloc>();
                context
                    .read<ConsultantSlotsBloc>()
                    .add(SilentFetch(bloc.state.selectedDate, inMemory: false));
              });
            } else {
              App.showOkToDismissSnackBar(context.T.noSlotSelected);
            }
          },
        );
      },
    );
  }
}

Body:
try this:

Text(
  "text",
  style: TextStyle(
    // MediaQuery.of(context).size.width is the width from the screen
    fontSize: MediaQuery.of(context).size.width * 0.001,
    ...
  ),
),


问:
Is there any way to convert the hex code from string to hex colour which discord.py supports?
I am trying to figure this out for so long,
but I am not able to convert the hex code from string to actual hex code like this 0xFFFFFF
since discord.py doesn't take hex code in str datatype.
Code Snippet:-

```<code>@client.command()
async def testing(ctx):
    # color = lgd.hexConvertor(colorCollection.find({},{"_id":0,"Hex":1}))
    c = "0xFFFFFF"
    inte = int(c,16)
    color = hex(inte)
    await ctx.send(embed = discord.Embed(description = "testing",color = color))
</code>```

Error:-

```<code>Traceback (most recent call last):
  File "/opt/virtualenvs/python3/lib/python3.8/site-packages/discord/ext/commands/core.py", line 85, in wrapped
    ret = await coro(*args, **kwargs)
  File "main.py", line 221, in testing
    await ctx.send(embed = discord.Embed(description = "testing",color = color))
  File "/opt/virtualenvs/python3/lib/python3.8/site-packages/discord/embeds.py", line 115, in __init__
    self.colour = colour
  File "/opt/virtualenvs/python3/lib/python3.8/site-packages/discord/embeds.py", line 230, in colour
    raise TypeError('Expected discord.Colour, int, or Embed.Empty but received %s instead.' % value.__class__.__name__)
TypeError: Expected discord.Colour, int, or Embed.Empty but received str instead.
</code>```

This is how I stored the hex codes in my mongodb atlas database->

Edit:-
It worked on using inte instead of color

答:
>>> color = "0xFFFFFF"
>>> int_color = int(color,16)
>>> hex(int_color)
'0xffffff'
>>> # basically the same thing
>>>
>>> from discord import Color
>>>
>>> Color(int_color)
<Colour value=16777215>
>>> #just ints work
```

discord.py documentation for colours

Body:
I am trying to figure this out for so long,
but I am not able to convert the hex code from string to actual hex code like this 0xFFFFFF
since discord.py doesn't take hex code in str datatype.
Code Snippet:-

@client.command()
async def testing(ctx):
    # color = lgd.hexConvertor(colorCollection.find({},{"_id":0,"Hex":1}))
    c = "0xFFFFFF"
    inte = int(c,16)
    color = hex(inte)
    await ctx.send(embed = discord.Embed(description = "testing",color = color))

Error:-

Traceback (most recent call last):
  File "/opt/virtualenvs/python3/lib/python3.8/site-packages/discord/ext/commands/core.py", line 85, in wrapped
    ret = await coro(*args, **kwargs)
  File "main.py", line 221, in testing
    await ctx.send(embed = discord.Embed(description = "testing",color = color))
  File "/opt/virtualenvs/python3/lib/python3.8/site-packages/discord/embeds.py", line 115, in __init__
    self.colour = colour
  File "/opt/virtualenvs/python3/lib/python3.8/site-packages/discord/embeds.py", line 230, in colour
    raise TypeError('Expected discord.Colour, int, or Embed.Empty but received %s instead.' % value.__class__.__name__)
TypeError: Expected discord.Colour, int, or Embed.Empty but received str instead.

This is how I stored the hex codes in my mongodb atlas database->

Edit:-
It worked on using inte instead of color

Body:
>>> color = "0xFFFFFF"
>>> int_color = int(color,16)
>>> hex(int_color)
'0xffffff'
>>> # basically the same thing
>>>
>>> from discord import Color
>>>
>>> Color(int_color)
<Colour value=16777215>
>>> #just ints work

discord.py documentation for colours


问:
Extract ranges from sequential values
Task 1:

I have my collection with documents in mongodb  with value from sequential ranges as follow :

```<code> {x:1}
 {x:2}
 {x:3}
 {x:5}
 {x:6}
 {x:7}
 {x:8}
 {x:20}
 {x:21}
</code>```

I need to extract a list of sequential ranges in the form(the count is not compulsory , but I need at least the first and last values from the range):

```<code> {x:[1,3] , count:3}
 {x:[5,8], count:4}
 {x:[20,21],count:2}
</code>```

or

```<code> { min:1 , max:3 , count:3}
 { min:5 , max:8 , count:4}
 { min:20 , max:21 , count:2}
</code>```

Please,  advice suitable solution , collection has ~100M docs , some of the values are in 10 digit ranges others in 15 digit ranges , but they are all sequentially incremental in their range?

Task 2:

Same think like in Task 1 , but taken based on custom sequence step ,
for example if the sequence step is 3:

```<code>{y:1}
{y:3}
{y:5}
{y:20}
{y:22}
</code>```

need to produce:

```<code>{y:[1,5] ,count:3}
{y:[20,22]} , count:2}
</code>```

Thanks!

P.S.
I succeeded partially to get some ranges picture by fetch distribution by  number of digits range  , but this seems to be very general:

```<code> db.collection.aggregate([
   {
     $addFields: {
       range: {
         $strLenCP: {
           $toString: "$x"
         }
       }
     }
   },
   {
     $group: {
       _id: "$range",
       minValue: {
         $min: "$x"
       },
       maxValue: {
         $max: "$x"
       },
       Count: {
         $sum: 1
       }
     }
   },
   {
     $addFields: {
       x: [
         {
           $toString: "$minValue"
         },
         {
           $toString: "$maxValue"
         }
       ]
     }
   },
   {
     $project: {
       range: "$_id",
       "_id": 0,
       x: 1,
       Count: 1
     }
   },
   {
     $sort: {
       range: 1
     }
   }
 ])
</code>```

playground

答:
using $reduce

if i'm not mistaken for task2 just change 1 in $cond, $ne to any sequence step you want

playground

```<code>db.collection.aggregate([
  {
    "$sort": {
      x: 1
    }
  },
  {
    $group: {
      _id: null,
      temp: {
        $push: "$$ROOT"
      }
    }
  },
  {
    "$project": {
      _id: 0,
      "temp_field": {
        "$reduce": {
          "input": "$temp",
          "initialValue": {
            "prev": -999999,
            "min": -999999,
            "count": 0,
            "ranges": []
          },
          "in": {
            "prev": "$$this.x",
            "count": {
              "$cond": [
                {
                  $gt: [
                    {
                      "$subtract": [
                        "$$this.x",
                        "$$value.prev"
                      ]
                    },
                    1//sequence step

                  ],

                },
                1,
                {
                  "$add": [
                    "$$value.count",
                    1
                  ]
                }
              ]
            },
            "min": {
              "$cond": [
                {
                  $gt: [
                    {
                      "$subtract": [
                        "$$this.x",
                        "$$value.prev"
                      ]
                    },
                    1//sequence step

                  ],

                },
                "$$this.x",
                "$$value.min"
              ]
            },
            "ranges": {
              "$concatArrays": [
                "$$value.ranges",
                {
                  "$cond": [
                    {
                      $gt: [
                        {
                          "$subtract": [
                            "$$this.x",
                            "$$value.prev"
                          ]
                        },
                        1//sequence step

                      ],

                    },
                    [
                      {
                        max: "$$value.prev",
                        min: "$$value.min",
                        count: "$$value.count"
                      }
                    ],
                    []
                  ]
                }
              ]
            }
          }
        }
      }
    }
  },
  {
    "$project": {
      ranges: {
        "$concatArrays": [
          "$temp_field.ranges",
          [
            {
              max: "$temp_field.prev",
              min: "$temp_field.min",
              count: "$temp_field.count"
            }
          ]
        ]
      }
    }
  }
])
</code>```

and at the end pop the first element from array

Comment by R2D2 after testing in the real use case I hit the memory limit with allowDiskUse: true:

```<code>   2022-02-14T09:38:27.575+0100 E QUERY    [js] Error: command failed: {
    "ok" : 0,
    "errmsg" : "$push used too much memory and cannot spill to disk. Memory limit: 104857600 bytes",
    "code" : 146,
    "codeName" : "ExceededMemoryLimit",
</code>```

Increased the memory to 2GB ( max allowed ) with:

```<code> db.adminCommand({setParameter:1 ,  internalQueryMaxPushBytes: 2048576000 })
</code>```

But still faced the limit , then decided to split the collection to small ones so finally got my results , thank you once again!

Title: Extract ranges from sequential values

Body:
Task 1:

I have my collection with documents in mongodb  with value from sequential ranges as follow :

 {x:1}
 {x:2}
 {x:3}
 {x:5}
 {x:6}
 {x:7}
 {x:8}
 {x:20}
 {x:21}

I need to extract a list of sequential ranges in the form(the count is not compulsory , but I need at least the first and last values from the range):

 {x:[1,3] , count:3}
 {x:[5,8], count:4}
 {x:[20,21],count:2}

or

 { min:1 , max:3 , count:3}
 { min:5 , max:8 , count:4}
 { min:20 , max:21 , count:2}

Please,  advice suitable solution , collection has ~100M docs , some of the values are in 10 digit ranges others in 15 digit ranges , but they are all sequentially incremental in their range?

Task 2:

Same think like in Task 1 , but taken based on custom sequence step ,
for example if the sequence step is 3:

{y:1}
{y:3}
{y:5}
{y:20}
{y:22}

need to produce:

{y:[1,5] ,count:3}
{y:[20,22]} , count:2}

Thanks!

P.S.
I succeeded partially to get some ranges picture by fetch distribution by  number of digits range  , but this seems to be very general:

 db.collection.aggregate([
   {
     $addFields: {
       range: {
         $strLenCP: {
           $toString: "$x"
         }
       }
     }
   },
   {
     $group: {
       _id: "$range",
       minValue: {
         $min: "$x"
       },
       maxValue: {
         $max: "$x"
       },
       Count: {
         $sum: 1
       }
     }
   },
   {
     $addFields: {
       x: [
         {
           $toString: "$minValue"
         },
         {
           $toString: "$maxValue"
         }
       ]
     }
   },
   {
     $project: {
       range: "$_id",
       "_id": 0,
       x: 1,
       Count: 1
     }
   },
   {
     $sort: {
       range: 1
     }
   }
 ])

playground

Body:
using $reduce

if i'm not mistaken for task2 just change 1 in $cond, $ne to any sequence step you want

playground

db.collection.aggregate([
  {
    "$sort": {
      x: 1
    }
  },
  {
    $group: {
      _id: null,
      temp: {
        $push: "$$ROOT"
      }
    }
  },
  {
    "$project": {
      _id: 0,
      "temp_field": {
        "$reduce": {
          "input": "$temp",
          "initialValue": {
            "prev": -999999,
            "min": -999999,
            "count": 0,
            "ranges": []
          },
          "in": {
            "prev": "$$this.x",
            "count": {
              "$cond": [
                {
                  $gt: [
                    {
                      "$subtract": [
                        "$$this.x",
                        "$$value.prev"
                      ]
                    },
                    1//sequence step

                  ],

                },
                1,
                {
                  "$add": [
                    "$$value.count",
                    1
                  ]
                }
              ]
            },
            "min": {
              "$cond": [
                {
                  $gt: [
                    {
                      "$subtract": [
                        "$$this.x",
                        "$$value.prev"
                      ]
                    },
                    1//sequence step

                  ],

                },
                "$$this.x",
                "$$value.min"
              ]
            },
            "ranges": {
              "$concatArrays": [
                "$$value.ranges",
                {
                  "$cond": [
                    {
                      $gt: [
                        {
                          "$subtract": [
                            "$$this.x",
                            "$$value.prev"
                          ]
                        },
                        1//sequence step

                      ],

                    },
                    [
                      {
                        max: "$$value.prev",
                        min: "$$value.min",
                        count: "$$value.count"
                      }
                    ],
                    []
                  ]
                }
              ]
            }
          }
        }
      }
    }
  },
  {
    "$project": {
      ranges: {
        "$concatArrays": [
          "$temp_field.ranges",
          [
            {
              max: "$temp_field.prev",
              min: "$temp_field.min",
              count: "$temp_field.count"
            }
          ]
        ]
      }
    }
  }
])

and at the end pop the first element from array

Comment by R2D2 after testing in the real use case I hit the memory limit with allowDiskUse: true:

   2022-02-14T09:38:27.575+0100 E QUERY    [js] Error: command failed: {
    "ok" : 0,
    "errmsg" : "$push used too much memory and cannot spill to disk. Memory limit: 104857600 bytes",
    "code" : 146,
    "codeName" : "ExceededMemoryLimit",

Increased the memory to 2GB ( max allowed ) with:

 db.adminCommand({setParameter:1 ,  internalQueryMaxPushBytes: 2048576000 })

But still faced the limit , then decided to split the collection to small ones so finally got my results , thank you once again!


问:
Dev Client: No common URI schemes could be found for the native iOS and Android projects
I'm trying to run project on React Native using command expo run:android. Connected an android device.
Build successful. Then I get this message in console

BUILD SUCCESSFUL in 30s 294 actionable tasks: 2 executed, 292
up-to-date

Dev Client: No common URI schemes could be found for the native iOS
and Android projects, this is required for opening the project

Add a common scheme with npx uri-scheme add my-scheme or provide a
scheme with the --scheme flag

You can see all of the existing schemes for your native projects by
running npx uri-scheme list

Starting Metro Bundler

No scheme specified for development client

Check URI schemes by npx uri-scheme list

› iOS: Schemes for config: ./ios\DogSafeProject\Info.plist

› Android: Schemes for config:
./android\app\src\main\AndroidManifest.xml

Please help me!

答:
I was having the same issue and running this script in my terminal got the job done.</p>
```<code>npx uri-scheme add <app name>.
</code>```

Body:
I was having the same issue and running this script in my terminal got the job done.

npx uri-scheme add <app name>.