dart

Flutter fade animation between page views

微笑、不失礼 提交于 2021-01-28 19:52:11
问题 I'm trying to find how to fade between PageView pages. This is my pageView: PageView( controller: controller, children: [ Container( decoration: BoxDecoration( image: DecorationImage( image: AssetImage("assets/image4.jpg"), fit: BoxFit.cover), ), child: Center( child: Text( 'myText', style: TextStyle(color: Colors.white, fontSize: 40.0), )), ), Container( decoration: BoxDecoration( image: DecorationImage( image: AssetImage("assets/image2.jpg"), fit: BoxFit.cover), ), child: Center( child:

Can't use indexOf in List of Map in DART

断了今生、忘了曾经 提交于 2021-01-28 19:30:41
问题 I have a List of Map like this List<Map<String, String>> data = [ {"id":"1", "name":"Job"}, {"id":"2", "name":"Teh"}, {"id":"3", "name":"Maru"}, {"id":"4", "name":"Pam"}, ]; void main() { var index = data.indexOf({"id":"1", "name":"Job"}); print("Index: $index"); } Result run on DartPad was: Index: -1. How can I using indexOf for Map object in List? Thanks 回答1: It doesn't work because the two maps aren't the same Object, to solve that, you can either use const objects or use indexWhere With

flutter checkbox not working in StatelessWidget

橙三吉。 提交于 2021-01-28 19:10:30
问题 Here is my class class Home extends StatelessWidget { and the Checkbox goes here. @override Widget build(BuildContext context) { return Scaffold( body: Center( child: Column( crossAxisAlignment: CrossAxisAlignment.center, mainAxisAlignment: MainAxisAlignment.center, children: <Widget>[ Padding( padding: EdgeInsets.all(20.0), child: Column( children: <Widget>[ TextField( controller: ctrlMotherName, decoration: InputDecoration( labelText: "Name of Mother", border: OutlineInputBorder() ) ),

How to create a BlocListener that can listen to all pages in flutter with access to MaterialApp context?

荒凉一梦 提交于 2021-01-28 19:05:25
问题 I'm trying to create a BlocListener that has the ability to listen to all pages/routes throughout the app just like how you can access a Bloc or a Provider all throughout the app if they are defined at root-level like in the code below runApp( MultiProvider( providers: [ ChangeNotifierProvider<IdentityTokenProvider>( create: (_) => IdentityTokenProvider(), ), ], child: MultiBlocProvider( providers: [ BlocProvider<AuthBloc>( create: (_) => AuthBloc(), ), ], child: MaterialApp(

Flutter adding Draggable Scrollbar to a CustomScrollView? It keeps giving me 'The argument type CustomScrollView can't be assigned to BoxScrollView'

穿精又带淫゛_ 提交于 2021-01-28 19:00:36
问题 A Simple example would be: Scaffold( floatingActionButton: _fab(), floatingActionButtonLocation: _fabLocation(), body: Scrollbar( child: CustomScrollView( slivers: <Widget>[ SliverAppBar( automaticallyImplyLeading: false, leading: null, backgroundColor: Theme.of(context).colorScheme.secondary, title: AutoSizeText( _catalogSearchRatio, style: Theme.of(context).textTheme.title.copyWith( color: Theme.of(context).colorScheme.onSecondary), ), floating: true, pinned: false, ), SliverFixedExtentList

Get URL of a http get request in flutter app

可紊 提交于 2021-01-28 18:44:17
问题 I am trying to get the URL of the following get request; String url = ['url_here']; Future<Post> fetchPost() async { final response = await http.get(url); if (response.statusCode == 200) { return Post.fromJson(json.decode(response.body)); } else { throw Exception('Failed to load post'); } } I get a statuscode of 200. Any ideas? To clarify, When you enter the url in a browser it brings me to a page with a url that has a code in it. I am trying to extract that code. 回答1: followRedirects is true

how to sort list of songs from external storage alphabetically in flutter

筅森魡賤 提交于 2021-01-28 15:01:05
问题 As my Problem Says..i want to sort my listView items that are basically songs read by external storage..I want to sort them alphabetically..this is my code for listView final List<MaterialColor> _colors = Colors.primaries; @override Widget build(BuildContext context) { final rootIW = MPInheritedWidget.of(context); SongData songData = rootIW.songData; return new ListView.builder( itemCount: songData.songs.length, itemBuilder: (context, int index) { var s = songData.songs[index]; final

breaking out of a switch within a foreach loop closure

萝らか妹 提交于 2021-01-28 14:30:21
问题 I have the following code void onSelectionChangedFiredSources( Event event, var detail, SelectCheckboxMenuComponent target) { // getItemModels returns a list of objects getItemModels( target.selectedItems ) ..forEach( (item) { switch( item.label ) { case 'Ear': toggleDialog( 'paper-dialog-transition-center', $['ear-side-dialog']); break; case 'Eye': toggleDialog( 'paper-dialog-transition-center', $['eye-side-dialog']); break; case 'Nostril': toggleDialog( 'paper-dialog-transition-center', $[

How to use more than one ChangeNotifierProvider in Flutter?

牧云@^-^@ 提交于 2021-01-28 13:41:42
问题 I recently started using provider for my state management and I know how to use one at a time. class Home extends StatelessWidget { @override Widget build(BuildContext context) { return Scaffold( body: ChangeNotifierProvider<Reader>( create: (context) => new Reader(), child: _HomeBody(), ), ); } } But now I have two different classes and I want to add both of them and be able to access in my widget tree. How can I add more than one ChangeNotifierProvider in Flutter ? 回答1: One option (not

ShaderMask LinearGradient's stops strange behavior

冷暖自知 提交于 2021-01-28 12:35:14
问题 I want to fade both side (edges) of a content. I use a ShaderMask along with a LinearGradient , it works great except that I don't understand why my stops are not centered correctly, I use stops: [0.0, 0.05, 0.95, 1.0] so that it should be faded 0.05 on each side, but I get the following (I added a Container gradient with same configuration for comparison): With debug paint mode : I use exactly the same stops for the Container and for the ShaderMask but get different results. Of course I can